I'm getting the following error while running my application in Android. I don't have any background task going on.
FATAL EXCEPTION: AsyncTask #1
Process: com.inclov.inclovapp, PID: 32532
java.lang.RuntimeException: An error occured while executing
doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:304) at
java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.SecurityException: Permission Denial: opening
provider com.android.providers.contacts.ContactsProvider2 from
ProcessRecord{2363bbc5 32532:com.inclov.inclovapp/u0a161} (pid=32532,
uid=10161) requires android.permission.READ_CONTACTS or
android.permission.WRITE_CONTACTS at
android.os.Parcel.readException(Parcel.java:1546) at
android.os.Parcel.readException(Parcel.java:1499) at
android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3503)
at
android.app.ActivityThread.acquireProvider(ActivityThread.java:5062)
at
android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2737)
at
android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1446)
at android.content.ContentResolver.query(ContentResolver.java:466) at
android.content.CursorLoader.loadInBackground(CursorLoader.java:64) at
android.content.CursorLoader.loadInBackground(CursorLoader.java:42) at
android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
at
android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
at
android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
at android.os.AsyncTask$2.call(AsyncTask.java:292) at
java.util.concurrent.FutureTask.run(FutureTask.java:237) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
add these to you manifest:
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Read this for more info - https://developer.android.com/training/contacts-provider/retrieve-names.html#Permissions
As stated in the error , you need these permissions :
android.permission.READ_CONTACTS
or
android.permission.WRITE_CONTACTS
For lollipop and prior, you need to add this to your manifest :
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
If you are targeting Marshmallow, you need to add a request Permissions logic inside the activity using this. Follow this official Link on how to do it.
Related
I am trying to run a custom Tflie model for segmentation in Android. It runs fine on CPU but while using GPU delegate, it crashes with following error:-
E/AndroidRuntime(30867): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(30867): Process: com.apptec.scansdk, PID: 30867
E/AndroidRuntime(30867): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(30867): at android.os.AsyncTask$3.done(AsyncTask.java:309)
E/AndroidRuntime(30867): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
E/AndroidRuntime(30867): at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
E/AndroidRuntime(30867): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(30867): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
E/AndroidRuntime(30867): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/AndroidRuntime(30867): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/AndroidRuntime(30867): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(30867): Caused by: java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: TensorDescriptor don't have selector with name - Slice
E/AndroidRuntime(30867): Falling back to OpenGL
E/AndroidRuntime(30867): TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread where it was initialized.
E/AndroidRuntime(30867): Node number 105 (TfLiteGpuDelegateV2) failed to invoke.
E/AndroidRuntime(30867):
E/AndroidRuntime(30867): at org.tensorflow.lite.NativeInterpreterWrapper.run(Native Method)
E/AndroidRuntime(30867): at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:158)
E/AndroidRuntime(30867): at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:343)
E/AndroidRuntime(30867): at org.tensorflow.lite.Interpreter.run(Interpreter.java:304)
E/AndroidRuntime(30867): at com.apptec.scansdk.MainActivity$RunSegmentationOnBinary.runTflite(MainActivity.java:237)
E/AndroidRuntime(30867): at com.apptec.scansdk.MainActivity$TfliteTask.doInBackground(MainActivity.java:310)
E/AndroidRuntime(30867): at com.apptec.scansdk.MainActivity$TfliteTask.doInBackground(MainActivity.java:284)
E/AndroidRuntime(30867): at android.os.AsyncTask$2.call(AsyncTask.java:295)
E/AndroidRuntime(30867): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime(30867): ... 4 more
Here is my code to load model
MappedByteBuffer buffer = null;
buffer = FileUtil.loadMappedFile(context, "docScan.tflite");
int numThreads = 4;
boolean useGpuDelegate = true;
final Interpreter.Options tfliteOptions = new Interpreter.Options();
tfliteOptions.setNumThreads(numThreads);
if (useGpuDelegate){
GpuDelegate delegate = new GpuDelegate();
tfliteOptions.addDelegate(delegate);
}
tfLite = new Interpreter(buffer, tfliteOptions);
Strangely, it works on phones like MI/Redmi/OPPO and only crashes on Samsung. Please help!
Add the following lines to AndroidManifest.xml:
Link for AndroidManifestGpu.xml:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/java/AndroidManifestGpu.xml
<application
<uses-native-library
android:name="libOpenCL.so"
android:required="false" />
<uses-native-library
android:name="libOpenCL-car.so"
android:required="false" />
<uses-native-library
android:name="libOpenCL-pixel.so"
android:required="false" />
</application>
Add these dependencies to your build.gradle:
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0-rc2'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.8.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-task-vision:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-task-text:0.1.0'
I am getting the crash below at this code line:
pkgMrg_global = getActivity().getPackageManager();
apps = pkgMrg_global.getInstalledApplications(0);
//GETTING CRASH AT LINE BELOW
Collections.sort(apps,
new ApplicationInfo.DisplayNameComparator(
pkgMrg_global));
What I dont understand is how Collections.sort leads to this Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE?
Stacktrace:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getSubscriberId(IPhoneSubInfo.java:231)
at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:1352)
at android.app.ApplicationPackageManager.getSimOperatorNameForStk(ApplicationPackageManager.java:1548)
at android.app.ApplicationPackageManager.getText(ApplicationPackageManager.java:1109)
at android.content.pm.PackageItemInfo.loadLabel(PackageItemInfo.java:115)
at android.app.ApplicationPackageManager.getApplicationLabel(ApplicationPackageManager.java:1186)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:561)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:554)
at java.util.TimSort.binarySort(TimSort.java:261)
at java.util.TimSort.sort(TimSort.java:204)
at java.util.TimSort.sort(TimSort.java:169)
at java.util.Arrays.sort(Arrays.java:2010)
at java.util.Collections.sort(Collections.java:1883)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1830)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1802)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
As per google docs here
The note says
Note: If both your minSdkVersion and targetSdkVersion values are set to 3 or lower, the system implicitly grants your app this permission. If you don't need this permission, be sure your targetSdkVersion is 4 or higher.
Protection level: dangerous
if so you need to add the permission
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Constant Value: "android.permission.READ_PHONE_STATE"
add this permission to your android manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
My Logcat:
08-23 01:32:12.806 1299-1299/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.haftasia.easycode, PID: 1299
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxx cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43f9a738 1299:com.haftasia.easycode/u0a181} (pid=1299, uid=10181) requires android.permission.CALL_PHONE
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2109)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
at android.app.Activity.startActivityForResult(Activity.java:3442)
at android.app.Activity.startActivityForResult(Activity.java:3403)
at android.app.Activity.startActivity(Activity.java:3645)
at android.app.Activity.startActivity(Activity.java:3613)
at com.haftasia.easycode.Day_3G_Mci$1$1.onClick(Day_3G_Mci.java:52)
at android.view.View.performClick(View.java:4448)
at android.view.View$PerformClick.run(View.java:18461)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
You must add this permission in your AppManifest.xml:
<uses-permission android:name="android.permission.CALL_PHONE" />
Your error occurred because you didn't add it.
Since the logcat is saying everything what you looking for why dont you try to add permission ?
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
You seem to have an intent which makes an call but however for any app to make a call it requires the permission.
To add it in the Manifest before the application tag add the following
<uses-permission android:name = "android.permission.CALL_PHONE"/>
I am building an Android Library. I kept the code as normal android project while I was developing it and now I converted it into library project (even made a new library project and copied all the code in there just to be sure). The library basically allows user to enter data into database using contentprovider and the library returns that data queried from the database. So whatever app uses the library does not need to use the contentprovider to access data since the library does it all.
I made a very basic app that uses the library, the moment that I make a call to the library the app crashes giving the error code:
FATAL EXCEPTION: AsyncTask #3
Process: com.example.testing, PID: 18991
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Permission Denial: opening provider thesis.thesis.contentprovider.UsersDataContentProvider from ProcessRecord{42a51b18 18991:com.example.testing/u0a272} (pid=18991, uid=10272) that is not exported from uid 10266
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2917)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4489)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2330)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1441)
at android.content.ContentResolver.query(ContentResolver.java:448)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:65)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:43)
at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 3 more
I added permissions to testapp, but didnt change the error
<uses-permission android:name="thesis.thesis.contentprovider.READ_DATABASE" />
<uses-permission android:name="thesis.thesis.contentprovider.WRITE_DATABASE" />
The provider declared in library manifest:
<provider
android:name="thesis.thesis.contentprovider.UsersDataContentProvider"
android:authorities="thesis.thesis.contentprovider"
android:exported="true"
android:readPermission="thesis.thesis.contentprovider.READ_DATABASE"
android:writePermission="thesis.thesis.contentprovider.WRITE_DATABASE" />
At the moment I have exported="true" to see if that was the problem but no. Later I want it to be set false, since the data is sensitive.
Can anyone please direct me to where the problem might be. Also ask if additional information is needed.
I'm working with android studio and when I launch the app it doesn't work and on android studio show this problem:
09-13 23:41:37.579 2228-2380/? A/SdkSpecific17﹕ null
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.google.android.location.os.real.SdkSpecific17.d(SourceFile:266)
at ees.run(SourceFile:797)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=2228, uid=10011 requires android.permission.INTERACT_ACROSS_USERS
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.getCurrentUser(ActivityManagerNative.java:3871)
at android.app.ActivityManager.getCurrentUser(ActivityManager.java:1948)
... 5 more
09-13 23:41:37.719 2228-2380/? A/SdkSpecific17﹕ null
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.google.android.location.os.real.SdkSpecific17.d(SourceFile:266)
at efb.D(SourceFile:933)
at dno.c(SourceFile:126)
at dno.x_(SourceFile:149)
at dnk.b(SourceFile:952)
at dmr.b(SourceFile:331)
at ees.run(SourceFile:798)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=2228, uid=10011 requires android.permission.INTERACT_ACROSS_USERS
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.getCurrentUser(ActivityManagerNative.java:3871)
at android.app.ActivityManager.getCurrentUser(ActivityManager.java:1948)
... 10 more
can you help me? Thanks
The clue is
Caused by: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=2228, uid=10011 requires android.permission.INTERACT_ACROSS_USERS
You need to add to your manifest.xml
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
That being said, I've not seen this permission before... I believe it's used when you require root access. So you also might need a phone that is rooted.