- Home /
Alternative to 'Application.OpenURL()' for newest Android API
Hello all, is there an easy alternative or tutorial for this command to use with the newest Android APIs?
In the Unity Documents it says to use FileProvider from Android, but that does not help at all. What command should we use in Unity to open a pdf for example, also how do we integrate the FileProvider in Unity. We not only have to modify the manifest, but also do other stuff.
Answer by matheus_unity942 · May 20, 2019 at 06:30 AM
Estou tendo problemas com algo similar, talvez isto possa te ajudar...
//Refernece of AndroidJavaClass class for intent
AndroidJavaClass intentClass = new AndroidJavaClass ( "android.content.Intent" );
//Refernece of AndroidJavaObject class for intent
AndroidJavaObject intentObject = new AndroidJavaObject ( "android.content.Intent" );
//call setAction method of the Intent object created
intentObject.Call<AndroidJavaObject> ( "setAction", intentClass.GetStatic<string> ( "ACTION_VIEW" ) );
//set the type of sharing that is happening
intentObject.Call<AndroidJavaObject> ( "setType", "html" );
//add data to be passed to the other activity i.e., the data to be sent
intentObject.Call<AndroidJavaObject> ( "setFData", new System.Uri( body ) );
//get the current activity
AndroidJavaClass unity = new AndroidJavaClass ( "com.unity3d.player.UnityPlayer" );
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ( "currentActivity" );
//start the activity by sending the intent data
currentActivity.Call ( "startActivity", intentObject );
A ideia seria usar uma para o navegador e acessar a URL passada como parâmetro, até o momento ganhou o erro...
JNI:OpenURL:android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Your answer
Follow this Question
Related Questions
Open Pdf File in Android 1 Answer
Open PDF in Android (API level >=26) 0 Answers
PDF Reader for android 1 Answer
How to open PDF on particular page on Android? 0 Answers
After installing the .apk , the App Icon appears twice 1 Answer