Android Studio Permission Denial - java

I am not sure if this is the right place to ask this question but I can't find help anywhere. I'm trying to get this application to work but I've run into some errors.
Clicking "Open gallery" button immediately crashes whole app with this error:
FATAL EXCEPTION: main
Process: com.niel.galleryphotoapp, PID: 3691
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.niel.galleryphotoapp/com.niel.galleryphotoapp.HomeFragmentActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=3691, uid=10086 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=3691, uid=10086 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1684)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:532)
at android.content.ContentResolver.query(ContentResolver.java:474)
at com.niel.galleryphotoapp.DeviceImageManager.getPhoneAlbums(DeviceImageManager.java:34)
at com.niel.galleryphotoapp.HomeFragmentActivity.onCreate(HomeFragmentActivity.java:80)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
I don't know why it is happening, I checked the manifest and it seems the required permissions are there.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I'm using Android Studio 2.3.3 + Nexus 4 API 25 emulator.

Although you have included permissions in your manifest, you also need to request runtime permissions as well. Everything you need to know is here:
https://developer.android.com/training/permissions/requesting.html

As cjnash said, you need to ask for runtime permissions as well. If you need a quick way just to try it, you can go in your device settings and manually give your app the permissions it needs to run.

Related

App crash on Android 6.0 API 23 (but not on Android 9, API 28)

So i use two different emulators for testing my little app. Strangly the Android 6.0 API 23 version recently started to crash when trying to open an activity from the app. I don't remember what I did :(
Here's the error message i get from "RUN". My guess is that has to something with the GUI? The post page on Stackoverflow only let me post so much of the error so i cut out much of it. Maybe this part is important " Caused by: android.content.res.Resources$NotFoundException:" Anyone know what is happening here?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dex, PID: 24065
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dex/com.example.dex.Activity2}: android.view.InflateException: Binary XML file line #517: Binary XML file line #517: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #517: Binary XML file line #517: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070082
at android.content.res.Resources.getValue(Resources.java:1351)
at
Caused by: android.view.InflateException: Binary XML file line #517: Error inflating class ImageButton
as you expected, the source of your problem is in the last lines. When Android tries to inflate a layout which contains ImageButton, it does not find a resource. If this is on higher API-levels only, you might have a resource which is a subfolder like drawable-v24 only available for defined API-levels. The reason might also be that you are using a parameter or property that was added later.

java.lang.NoClassDefFoundError: org.jumpmind.symmetric.io.stage.StagingManager$1, even though the class exists in the jar file

I am trying to integrate Symmetric-Android 3.10.2 in my Android application. It is showing
java.lang.NoClassDefFoundError:
org.jumpmind.symmetric.io.stage.StagingManager$1
Even the class exists in jarfile
I have upgraded my API level from 22 to 26 after reading article from
https://sourceforge.net/p/symmetricds/discussion/1354726/thread/f965364c00/
but the issue remains
java.lang.NoClassDefFoundError:
org.jumpmind.symmetric.io.stage.StagingManager$1
at org.jumpmind.symmetric.io.stage.StagingManager.(StagingManager.java:288)
at org.jumpmind.symmetric.android.AndroidSymmetricEngine.createStagingManager(AndroidSymmetricEngine.java:108)
at org.jumpmind.symmetric.AbstractSymmetricEngine.init(AbstractSymmetricEngine.java:348)
at org.jumpmind.symmetric.android.AndroidSymmetricEngine.(AndroidSymmetricEngine.java:84)
at org.jumpmind.symmetric.android.SymmetricService.onStartCommand(SymmetricService.java:88)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3944)
at android.app.ActivityThread.access$2300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1833)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
It sounds like your issue may not be related to SymmetricDS, but instead how your classpath is configured in this Android project. There are several solutions in this thread that might help

Android app with AWS analytic integration failed to read awsconfiguration.json

I am following the tutorial here
I am just trying to get a feel for Android development and AWS integration. I setup the basic helloworld Android app following this guide. Then went on to add the AWS components in the first link.
When I get to the "Monitor Analytics" section, my project will build but throw an exception at runtime.
The exception is as follows:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxxx.wearables_data_receiver.app/com.xx.xxxx.wearables_data_receiver.feature.MainActivity}: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:99)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:83)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:68)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:45)
at com.amazonaws.mobile.client.AWSMobileClient.initialize(AWSMobileClient.java:155)
at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1351)
at android.content.res.Resources.openRawResource(Resources.java:1265)
at android.content.res.Resources.openRawResource(Resources.java:1241)
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:88)
The line:
at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)
Points to the "AWSMobileClient.getInstance().initialize" call from the tutorial in the first link:
AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
#Override
public void onComplete(AWSStartupResult awsStartupResult) {
System.out.println("AWSMobileClient is instantiated and you are connected to AWS!");
}
}).execute();
I'm not sure what's going on here, I have tried opening up the file permissions, and placing it in a few different directories but to no avail. Any help would be greatly appreciated.
The error is due to missing awsconfiguration.json file.
Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
Could you make sure that you have the awsconfiguration.json file placed in the res/raw directory and has valid json? If you did the set up using Amplify CLI it should always automatically update the awsconfiguration.json file with required information.

How to fix java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO error?

I am trying to get an Android Things project to build and run on a Raspberry Pi 3. The files are found here. I am connected to my Raspberry Pi 3 via Ethernet. I plugged the ethernet cable directly from my laptop to the rPi and used Internet Sharing. I then used adb connect to connect to the device and it successfully connects.
I am running:
Android Studio 3.1.2
Build #AI-173.4720617, built on April 13, 2018
JRE: 1.8.0_152-release-1024-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6
Changes were made to Android Studio so I had to change some code around. I downloaded the files and updated the PeripheralManagerService to PeripheralManager instead.
PeripheralManager pioService = PeripheralManager.getInstance();
When I click the Run button, I get the following error (please keep in mind that I already added the following permission to Android Manifest file above the application section):
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
Please help me with figure out what I am still missing. Thanks!
06-08 01:43:28.746 3598-3598/? I/zygote: Late-enabling -Xcheck:jni 06-08 01:43:28.993 3598-3598/apps.hackstermia.buttonthings I/MainActivity: Starting ButtonActivity
06-08 01:43:29.013 3598-3598/apps.hackstermia.buttonthings I/MainActivity: Configuring GPIO pins
06-08 01:43:29.017 3598-3598/apps.hackstermia.buttonthings D/AndroidRuntime: Shutting down VM
06-08 01:43:29.028 3598-3598/apps.hackstermia.buttonthings E/AndroidRuntime: FATAL EXCEPTION: main
Process: apps.hackstermia.buttonthings, PID: 3598
java.lang.RuntimeException: Unable to start activity ComponentInfo{apps.hackstermia.buttonthings/apps.hackstermia.buttonthings.MainActivity}: java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO
at android.os.Parcel.readException(Parcel.java:2005)
at android.os.Parcel.readException(Parcel.java:1951)
at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.GetGpioClient(IPeripheralManagerClient.java:759)
at com.google.android.things.pio.GpioImpl.<init>(GpioImpl.java:50)
at com.google.android.things.pio.PeripheralManager.openGpio(PeripheralManager.java:197)
at apps.hackstermia.buttonthings.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:7010)
at android.app.Activity.performCreate(Activity.java:7001)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
06-08 01:43:29.047 3598-3598/apps.hackstermia.buttonthings I/Process: Sending signal. PID: 3598 SIG: 9
At first, following lines should be included by AndroidManifest just before application tag
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />
Then, if you install application via adb, you should install <APK> with -g option as follow as recomended by #Devunwired here
adb install -g <APK>
friends~!
I had the same problem with my Android Studio 3.1.3 and RaspberryPi 3 and AndroidThings. This platform was killing my "blink" app, because I had a lacks permission of "[..] USE_PERIPHERAL_IO".
For my problem, the solution was adding this sentence:
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />
to my Android Manifest file.
Thanks, anyone for help :))
Thanks for your input everyone.
I found out that the permission in the manifest file needs to be a direct child, or outside of the application
I had the same issue. Tried different approaches as mentioned above. What really works for me
1. update your android studio to the latest version. Mine was 3.0.1. After upgrade, it is 3.1.3
2. update the os version of android things to the latest. It was 0.6. After upgrade, it is 1.0.1.
3. Set those permission in android manifest
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />
hope those steps will make your android things working
Depending on the version of Android Studio, the prisons are applied and granted on upgrades and installs or only on installs (on older versions)
Rebooting the device should fix it, uninstalling and reinstalling the app should also fix it.

Adding PubSub as a dependency causes errors with Firestore

I am fairly new to Android and the Google cloud. I have written a test app which successfully writes to a firestore database.
I wanted to extend my application by adding a feature to publish to a pubsub topic.
I added the following dependency line to build.gradle:
implementation 'com.google.cloud:google-cloud-pubsub:0.33.0-beta'
Before I even added any new pubsub code, my app builds, runs, and immediately crashes with the following stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tliv.mytestapp, PID: 27506
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.android.gms.internal.zzeux.run(Unknown Source:23)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.util.ServiceConfigurationError: Provider io.grpc.netty.NettyChannelProvider could not be instantiated: java.lang.ClassCastException: class io.grpc.netty.NettyChannelProvider cannot be cast to com.google.android.gms.internal.zzfmw
at com.google.android.gms.internal.zzfmw.zzq(Unknown Source:84)
at com.google.android.gms.internal.zzfmw.zzdcr(Unknown Source:26)
at com.google.android.gms.internal.zzfmw.<clinit>(Unknown Source:12)
at com.google.android.gms.internal.zzfmw.zzdcs(Unknown Source:0)
at com.google.android.gms.internal.zzfmv.zzud(Unknown Source:0)
at com.google.android.gms.internal.zzeti.<init>(Unknown Source:22)
at com.google.android.gms.internal.zzenf.zza(Unknown Source:74)
at com.google.android.gms.internal.zzenh.run(Unknown Source:8)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.internal.zzeuu$zza.run(Unknown Source:7)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassCastException: class io.grpc.netty.NettyChannelProvider cannot be cast to com.google.android.gms.internal.zzfmw
at java.lang.Class.asSubclass(Class.java:2469)
at com.google.android.gms.internal.zzfmw.zzq(Unknown Source:2)
at com.google.android.gms.internal.zzfmw.zzdcr(Unknown Source:26) 
at com.google.android.gms.internal.zzfmw.<clinit>(Unknown Source:12) 
at com.google.android.gms.internal.zzfmw.zzdcs(Unknown Source:0) 
at com.google.android.gms.internal.zzfmv.zzud(Unknown Source:0) 
at com.google.android.gms.internal.zzeti.<init>(Unknown Source:22) 
at com.google.android.gms.internal.zzenf.zza(Unknown Source:74) 
at com.google.android.gms.internal.zzenh.run(Unknown Source:8) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
at com.google.android.gms.internal.zzeuu$zza.run(Unknown Source:7) 
at java.lang.Thread.run(Thread.java:764) 
I'm not sure where to begin troubleshooting this. As soon as I remove the pubsub dependency, my code builds and runs fine again.
As per the doc, "Google Cloud Java client libraries do not currently support Android".
You may want to use the Google Cloud Pub/Sub API Client Library instead for your project.

Categories

Resources