#File provider examples

1 messages · Page 1 of 1 (latest)

stuck patrol
#

This is from my phone, so apologies if it has mistakes but

#

Here's what we use.
/Plugins/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.io.universaldeeplink" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferInternal" android:versionName="1.0" android:versionCode="1" android:sharedUserId="android.uid.system">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name">
    <provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
      <meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/provider_paths"/>
    </provider>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
</manifest>```

And then code example, this would load an image for example...

```cs
#if UNITY_ANDROID && !UNITY_EDITOR
        using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
        using (var intent = new AndroidJavaObject("android.content.Intent", "android.intent.action.VIEW"))
        using (var uriClass = new AndroidJavaClass("android.net.Uri"))
        {
            string uriString = "file://...(someimage).png";
            AndroidJavaObject uri = uriClass.CallStatic<AndroidJavaObject>("parse", uriString);
 intent.Call<AndroidJavaObject>("setDataAndType", uri, "image/*");
            intent.Call<AndroidJavaObject>("addFlags", 1); // FLAG_GRANT_READ_URI_PERMISSION = 1
 activity.Call("startActivity", intent);
        }
#endif
drifting wharf
#

thanks

stuck patrol
#

Np! Hope it helps