0

Im successful adding a desired json file to the internal storage of my app data/<packagename>/files/ . What I want to achieve is, to make a function in my android plugin (inside Unity app) which can read the same json from internal storage. Im doubtful, if this is even possible at runtime. I tried this in my plugin contentprovider class String file_name=context.getFilesDir() + "/"+"stickers.json"; but my app crashes on device.

Second alternative which I thought is to pass the whole json object to Android plugin by using UnitySendMessage (I have never used it before).

I want the plugin to read the internally stored json because I can dynamically modify the json at runtime from unity and perform my desired functions from the android plugin code.

UPDATE

--------- beginning of crash 2020-05-30 14:09:32.275 22270-22270/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.Addy.Trace, PID: 22270 java.lang.RuntimeException: Unable to get provider com.plugin.unityapp.StickerContentProvider: java.lang.RuntimeException: contents.json file has some issues: /data/user/0/com.Addy.Trace/files/stickers.json: open failed: ENOENT (No such file or directory) at android.app.ActivityThread.installProvider(ActivityThread.java:7416) at android.app.ActivityThread.installContentProviders(ActivityThread.java:6956) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6844) at android.app.ActivityThread.access$1300(ActivityThread.java:268) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:7814) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068) Caused by: java.lang.RuntimeException: contents.json file has some issues: /data/user/0/com.Addy.Trace/files/stickers.json: open failed: ENOENT (No such file or directory) at com.plugin.unityapp.StickerContentProvider.readContentFile(StickerContentProvider.java:164) at com.plugin.unityapp.StickerContentProvider.getStickerPackList(StickerContentProvider.java:182) at com.plugin.unityapp.StickerContentProvider.onCreate(StickerContentProvider.java:98) at android.content.ContentProvider.attachInfo(ContentProvider.java:2113) at android.content.ContentProvider.attachInfo(ContentProvider.java:2087) at android.app.ActivityThread.installProvider(ActivityThread.java:7411) at android.app.ActivityThread.installContentProviders(ActivityThread.java:6956)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6844)  at android.app.ActivityThread.access$1300(ActivityThread.java:268)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:237)  at android.app.ActivityThread.main(ActivityThread.java:7814)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)  Caused by: java.io.FileNotFoundException: /data/user/0/com.Addy.Trace/files/stickers.json: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:496) at java.io.FileInputStream.<init>(FileInputStream.java:159) at com.plugin.unityapp.StickerContentProvider.readContentFile(StickerContentProvider.java:156) at com.plugin.unityapp.StickerContentProvider.getStickerPackList(StickerContentProvider.java:182)  at com.plugin.unityapp.StickerContentProvider.onCreate(StickerContentProvider.java:98)  at android.content.ContentProvider.attachInfo(ContentProvider.java:2113)  at android.content.ContentProvider.attachInfo(ContentProvider.java:2087)  at android.app.ActivityThread.installProvider(ActivityThread.java:7411)  at android.app.ActivityThread.installContentProviders(ActivityThread.java:6956)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6844)  at android.app.ActivityThread.access$1300(ActivityThread.java:268)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:237)  at android.app.ActivityThread.main(ActivityThread.java:7814)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)  Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:167) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252) at libcore.io.ForwardingOs.open(ForwardingOs.java:167) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7691) at libcore.io.IoBridge.open(IoBridge.java:482) at java.io.FileInputStream.<init>(FileInputStream.java:159)  at com.plugin.unityapp.StickerContentProvider.readContentFile(StickerContentProvider.java:156)  at com.plugin.unityapp.StickerContentProvider.getStickerPackList(StickerContentProvider.java:182)  at com.plugin.unityapp.StickerContentProvider.onCreate(StickerContentProvider.java:98)  at android.content.ContentProvider.attachInfo(ContentProvider.java:2113)  at android.content.ContentProvider.attachInfo(ContentProvider.java:2087)  at android.app.ActivityThread.installProvider(ActivityThread.java:7411)  at android.app.ActivityThread.installContentProviders(ActivityThread.java:6956)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6844)  at android.app.ActivityThread.access$1300(ActivityThread.java:268)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:237)  at android.app.ActivityThread.main(ActivityThread.java:7814)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068) 

This is the crash log in LOGCAT of android studio. From unity in a script , im using the awake function and writing the json file to internal storage, but maybe during the startup of the app the plugin isnt detecting the json in internal storage using String file_name=context.getFilesDir() + "/"+"stickers.json";

JSON File content

{
  "android_play_store_link": "",
  "ios_app_store_link": "",
  "sticker_packs": [
    {
      "identifier": "1",
      "name": "Adi",
      "publisher": "Jane Doe",
      "tray_image_file": "Trayicon_Cat1.png",
      "image_data_version":"1",
      "avoid_cache":false,
      "publisher_email":"",
      "publisher_website": "",
      "privacy_policy_website": "",
      "license_agreement_website": "",
      "stickers": [
        {
          "image_file": "Formidable.webp",
          "emojis": ["☕",""]
        },
        {
          "image_file": "Awful.webp",
          "emojis": ["",""]
        },
        {
          "image_file": "Athletic.webp",
          "emojis": ["☕",""]
        }

      ]
    }
  ]
}
Aditya Patil
  • 123
  • 1
  • 1
  • 9
  • what error shows the ADB when it crashes? – Lotan May 29 '20 at 22:17
  • hey, json files are yours? or a user copied them on internal storage? – MohammadReza Arashiyan May 30 '20 at 04:37
  • @MohammadRezaArashiyan Json files are mine, I plan to write them to the internal storage when the app startsup the first time. So that I have the initial skeleton of json there, and i can update it through unity as and when i please. – Aditya Patil May 30 '20 at 08:23
  • it seems that your json file is invalid or the directory incorrect for reading, could you paste the copied Json file on your dataPath? Let's check if the problem is the Json or something else – Lotan May 30 '20 at 08:48
  • @Lotan Problem isnt in the Json, I have used the same json file elsewhere. Still i will update my post – Aditya Patil May 30 '20 at 08:50
  • @AdityaPatil I trust you, but the message is pretty clear about the problem: or Json is incorrect, or the path where you are searching for it is incorrect. Paste the json copied, not the "what is suppoused to be" in your persistent data folder please ^^ – Lotan May 30 '20 at 08:53
  • @Lotan I have posted it. Probably i need to make changes in the plugin manifest? To access the internal storage ? Im not sure how to do it – Aditya Patil May 30 '20 at 08:58
  • 1
    Hmmm... Try to use android.content.Context.getExternalFilesDir. instead of context.getFilesDir() and just to be sure, you've debugged and the file is already created, right? You can visualize the file on your device etc? – Lotan May 30 '20 at 09:01

0 Answers0