0

I am using Eclipse Moquette in my application (MQTT Broker) to connect with IoT devices. I already declared all the permission in the manifest for Reading/Write storage here is the permissions declared in my manifest file.

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

All the permissions are prompt and granted during Runtime. Successfully. App UI is built on React-native while MQTT Broker starts as a service from java module.

Still, I am getting this error when I start the server.

Logcat error

Screenshot of logcat when MQTT server attempt to start the service. All permission are granted during runtime.

2020-11-04 14:58:37.515 21844-21952/com.botapp E/Moquette: null
    java.io.IOException: Permission denied
        at java.io.UnixFileSystem.createFileExclusively0(Native Method)
        at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
        at java.io.File.createNewFile(File.java:1008)
        at org.eclipse.moquette.spi.persistence.MapDBPersistentStore.initStore(MapDBPersistentStore.java:69)
        at org.eclipse.moquette.spi.impl.SimpleMessaging.processInit(SimpleMessaging.java:166)
        at org.eclipse.moquette.spi.impl.SimpleMessaging.init(SimpleMessaging.java:95)
        at org.eclipse.moquette.server.Server.startServer(Server.java:90)
        at org.eclipse.moquette.server.Server.startServer(Server.java:76)
        at com.botapp.mqtt.StartServer.serverStart(StartServer.java:31)
        at com.botapp.mqtt.StartServer.run(StartServer.java:24)
        at java.lang.Thread.run(Thread.java:919)
2020-11-04 14:58:37.515 21844-21952/com.botapp W/System.err: org.eclipse.moquette.proto.MQTTException: Can't create temp file for subscriptions storage [/storage/emulated/0/moquette_store.mapdb]
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.spi.persistence.MapDBPersistentStore.initStore(MapDBPersistentStore.java:72)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.spi.impl.SimpleMessaging.processInit(SimpleMessaging.java:166)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.spi.impl.SimpleMessaging.init(SimpleMessaging.java:95)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.server.Server.startServer(Server.java:90)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.server.Server.startServer(Server.java:76)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at com.botapp.mqtt.StartServer.serverStart(StartServer.java:31)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at com.botapp.mqtt.StartServer.run(StartServer.java:24)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at java.lang.Thread.run(Thread.java:919)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err: Caused by: java.io.IOException: Permission denied
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at java.io.UnixFileSystem.createFileExclusively0(Native Method)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at java.io.File.createNewFile(File.java:1008)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     at org.eclipse.moquette.spi.persistence.MapDBPersistentStore.initStore(MapDBPersistentStore.java:69)
2020-11-04 14:58:37.516 21844-21952/com.botapp W/System.err:     ... 7 more
hardillb
  • 54,545
  • 11
  • 67
  • 105
Hey.Its_RJ
  • 115
  • 1
  • 9
  • If your device is above android marshmallow you'll need to declare runtime permission & manifest permission as well – Mochamad Taufik Hidayat Nov 04 '20 at 07:03
  • Already done that... storage permission is checked and prompted during runtime. When I check app settings> permissions (for this app) it displays me granted. – Hey.Its_RJ Nov 04 '20 at 07:31
  • Please do not post images of error message text. It's really hard to read and impossible for people using screen readers. Post the actual text and format it with the toolbar. – hardillb Nov 04 '20 at 08:39
  • `org.eclipse.moquette.proto.MQTTException: Can't create temp file for subscriptions storage [/storage/emulated/0/moquette_store.mapdb]` So you cannot create a file on external storage. Thats all. – blackapps Nov 04 '20 at 10:58
  • And you use an Android 10 device. – blackapps Nov 04 '20 at 10:59
  • Any suggestion on how to resolve this error? @blackapps – Hey.Its_RJ Nov 04 '20 at 12:29
  • It seems that you did not read all comments. We will wait for that. – blackapps Nov 04 '20 at 12:46
  • I really need help with this thing. Already declared runtime permission and manifest permission as suggested above. "Can't create temp file for subscriptions storage". I tried changing the directory. – Hey.Its_RJ Nov 04 '20 at 13:03
  • There are some change on storage permission on android 10, maybe this anwser https://stackoverflow.com/a/57804657/4168314 will help – Mochamad Taufik Hidayat Nov 06 '20 at 09:29

1 Answers1

0

I know this problem was been posted a long time. But, I don't see a solution here, then I decided to collaborate, because other devs may have the same problem.

I had the same problem. I solved this error adding the code in manifest: android:requestLegacyExternalStorage="true"

This problem appears to occur in the latest versions of Android. In fact, it is not a problem, we should only implement the permission needs. I hope helped you.

damak
  • 16
  • 1