Search Unity

Application.OpenURL() alternative for Android API level > 23

Discussion in 'Android' started by ZeFirestarter, May 15, 2019.

  1. ZeFirestarter

    ZeFirestarter

    Joined:
    Oct 24, 2014
    Posts:
    17
    Hello fellow developers, I need your help.

    I used to be able to open PDFs through my Unity App with the command:

    Application.OpenURL(filepath/filename.pdf);
    But now I can't use it anymore and in the Unity documentation it says to use the FileProvider.

    For me it has been an unmitigated disaster. I am not able to get it to work.
    As soon as I try and modify the Android.manifest, the app crashes as soon as it opens.

    Code (CSharp):
    1. <provider
    2.     android:name="android.support.v4.content.FileProvider"
    3.     android:authorities="${applicationId}.fileprovider"
    4.     android:exported="false"
    5.     android:grantUriPermissions="true">
    6.     <meta-data
    7.         android:name="android.support.FILE_PROVIDER_PATHS"
    8.         android:resource="@xml/file_paths" />
    9. </provider>
    Just putting this inside the <application> </application> makes it crash.
    I also put in the 'file_paths.xml' in Assets/Plugins/Android/res/xml/ folder.
    Even without the meta-data, it just crashes.

    The worst part is, even if I was able to make it work so it doesn't crash, I don't know which command I could use in Unity to make it open the PDF.

    What should I use instead of Application.OpenURL()??
    Thank you for your time. Any help is very much appreciated.
     
  2. NickR2600

    NickR2600

    Joined:
    Aug 17, 2018
    Posts:
    20
    I'm trying to do the exact same thing. I'd love to hear if anyone has a solution.
     
  3. NickR2600

    NickR2600

    Joined:
    Aug 17, 2018
    Posts:
    20
    I think I've stopped the application from crashing on open. It's working on the Android emulator at least. The trick was to copy AppData\Local\Android\Sdk\extras\android\m2repository\com\android\support\support-v4\24.1.1\support-v4-24.1.1.aar to my Unity project's folder Assets/Plugins/Android. That's annoying. Shouldn't resources like this have been detected and bundled automatically? It's outline here on stackoverflow: https://stackoverflow.com/questions...e-content-fileprovider-classnotfoundexception
     
    Last edited: Oct 17, 2019
  4. NickR2600

    NickR2600

    Joined:
    Aug 17, 2018
    Posts:
    20