GithubHelp home page GithubHelp logo

unityandroidnativefileopener's Introduction

Unity Android Native File Opener

Open files from a Unity application natively on an Android device. Android recently added more security measures to restrict access to files from outside of an application. It used to be possible to open files with Unity's Application.OpenUrl() method on Android but now it requires a little more work to achive this. This plugin has been tested on Android Version 8, Unity Version 2018.2.17f1, and the "Internal" build system.

How to set it up:

How to use the example:

  • Add an AndroidManifest.xml file into the Assets/Plugins/Android folder
  • If you do not have an AndroidManifest.xml already, you can find the Unity generated Android Manifest file in your ProjectName/Temp/StagingArea after you build the project once.
  • Nest the below snippet inside of the AndroidManifest's <application></application>: tag.
<provider
  android:name="com.cartoontexas.andyr.unityplugin.UnitySSContentProvider"
  android:authorities="a_very_unique_name"
  android:exported="false"
  android:grantUriPermissions="true" />
  • The android:authorities attribute should be a unique name, make this your app bundleID to assure uniqueness.
  • Open example scene: "AndroidNativeFileOpenerExample"
  • Add the example scene to your build settings and build to your device.
  • When done, open app, tap the scene and a frog GIF should be downloaded locally and appear in your default Android GIF viewer.
  • Feel free to try the other examples in the example script which can be uncommented and used.

How to use the API:

  • Prepare the build using the steps above.
  • Create a reference to a file on your device.
  • Insert AndroidContentOpenerWrapper.OpenContent(pathToYourLocalFile); in your code.

Credits: Much of this plugin was adapted from yasirkula (thanks for the help!) UnityNativeShare

unityandroidnativefileopener's People

Contributors

andy-roger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unityandroidnativefileopener's Issues

Can't use in multiple apps. INSTALL_FAILED_CONFLICTING_PROVIDER . Can't install because provider name com.company.product.fileprovider

Do we need to recompile the java source and change an authority name or something for each app we want to use this in for them all to be simultaneously installed on a device? I am getting this when trying to install a second app on a device that already has an app installed using this asset.

INSTALL_FAILED_CONFLICTING_PROVIDER . Can't install because provider name com.company.product.fileprovider is already used in [first app]

Not sure where to change "com.company.product.fileprovider"

Can't open csv file in android devices

hi,
I am trying to open csv file in android devices. but it's cant open. hear is my code

void OpenCSV()
{
AndroidContentOpenerWrapper.OpenContent(Application.persistentDataPath + "/CSV file/" + FileName+ ".csv");
}

please help me to solve it.

thanks in advance.

AndroidJavaException: java.lang.ClassNotFoundException: com.cartoontexas.andyr.unityplugin.ContentOpener

AndroidJavaException: java.lang.ClassNotFoundException: com.cartoontexas.andyr.unityplugin.ContentOpener
01-15 14:08:15.502 22334 22456 E Unity : java.lang.ClassNotFoundException: com.cartoontexas.andyr.unityplugin.ContentOpener
01-15 14:08:15.502 22334 22456 E Unity : at java.lang.Class.classForName(Native Method)
01-15 14:08:15.502 22334 22456 E Unity : at java.lang.Class.forName(Class.java:453)
01-15 14:08:15.502 22334 22456 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
01-15 14:08:15.502 22334 22456 E Unity : at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
01-15 14:08:15.502 22334 22456 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
01-15 14:08:15.502 22334 22456 E Unity : at android.os.Handler.dispatchMessage(Handler.java:102)
01-15 14:08:15.502 22334 22456 E Unity : at android.os.Looper.loop(Looper.java:201)
01-15 14:08:15.502 22334 22456 E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
01-15 14:08:15.502 22334 22456 E Unity : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.cartoontexas.andyr.unityplugin.ContentOpener" on path: DexPathList[[zip file "/data/app/com.litifer.android.myhoggy-tNHDWzR8jwFfzWsx_qvF0g==/base.apk"],nativeLibraryDirectories=[/data/app/com.litifer.android.myhoggy-tNHDWzR8jwFfzWsx_qvF0g==/lib/arm, /data/app/com.litifer.android.myhoggy-tNHDWzR8jwFfzWsx_qvF0g==/ba

Doesn't work with PDF

I could do it with an image using this code:

 void LoadImage()
       {
           string filename = "vuzix.png";
           string path = Path.Combine(Application.persistentDataPath, filename);
           LoadContent(path);
       }
    void LoadContent(string path)
        {
            AndroidContentOpenerWrapper.OpenContent(path); //path must be path/to/file.filetype
        }

But whenever i try with a pdf, it says the file is corrupted and i can not open it in my android device

UPDATE:
I realized this only happens when i try to open a powerpoint converted to pdf file

I tried using a sample pdf file and it worked well

What could be the issue and possible solution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.