How to Open a PDF in an Android-Unity3D App?

前端 未结 2 1135
刺人心
刺人心 2021-01-28 18:40

I\'m developing an Android app in Unity3D to be used in classrooms, it has buttons to display some webs and videos related to the current lesso

2条回答
  •  不思量自难忘°
    2021-01-28 19:07

    If your app target level API 24 or more, you need to use FileProvide API, otherwise you get FileUriExposedException, as described here.

    To interact with FileProvider from С# code, you need to know how to interact with AndroidJavaClass and AndroidJavaObject to work with Java libraries (namely android.support.v4). Also you need to know how to declares a content provider component by adding the attribute to your AndroidManifest.xml in your project and some more points that are listed here.

    In the answer of this post you can find a solution to the problem, but stumble upon the following troubles:

    1) The android.support.v4 library is no longer available on the path "AndroidSDK/extras/android/support/v4/android-support-v4.jar", since now it is part of another library.

    2) You can find this library in some archives on the Internet, but when you download them you will find that the res folder in Plugins/Android is no longer supported and you need to create a .aar binary file in which you need to put AndroidManifest.xml and android.support.v4 library.

    3) When specifying the attribute in AndroidManifest.xml, you need to additionally specify in which to specify the path, where in your .aar archive the provider_paths.xml file is located, otherwise your application will crash at startup.

    You can try to go this long way yourself, or download my asset, which already has all the necessary code for working with the android.support.v4 library via AndroidJavaClass and AndroidJavaObject, and which is also able to rewrite package name in AndroidManifest.xml and providers_paths.xml when you will change it in the project settings. A demo is also included there.

    Link on github: https://github.com/Mihail5412/Unity-Android-Files-Opener

提交回复
热议问题