I'm trying to set a ringtone with my app. For that I need to write a sound in the external memory of the phone. But every time I try to do it I get this error :
FATAL EXCEPTION: main
Process: com.mtoy.tiboxinshape, PID: 26322
java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=26322, uid=10211 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1620)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1231)
at com.mtoy.tiboxinshape.SoundAdaptateur$2.onLongClick(SoundAdaptateur.java:142)
at android.view.View.performLongClick(View.java:5243)
at android.view.View$CheckForLongPress.run(View.java:21127)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
I don't understand why I still have this error as I have the following line in my manifest.xml :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Do you have an idea of what I can do to avoid having this error ?
Android changed permission accept in Latest 23 API level,In This Process Some permission that will be automatically granted at install time those are available for mention in Manifest ,Remaining Permission's Are Accept's in RunTime , Because So many bad guys trying to collect user's personal data through this security weakness So Android Change's to Runtime Permission
For More Information About Runtime Permission's And Process Of Runtime Permisson Accept
Fallow Below Link
Every Android Developer must know about new Android's Runtime Permission
Here is the solution I found :
https://developer.android.com/training/permissions/requesting.html
Related
i have a problem with samsungBadger library, https://github.com/shafty023/SamsungBadger
i get the following error on nougat:
Writing exception to parcel
java.lang.SecurityException: Permission Denial: writing com.sec.android.provider.badge.BadgeProvider uri content://com.sec.badge/apps from pid=15661, uid=10234 requires com.sec.android.provider.badge.permission.WRITE, or grantUriPermission()
at android.content.ContentProvider.enforceWritePermissionInner(ContentProvider.java:689)
at android.content.ContentProvider$Transport.enforceWritePermission(ContentProvider.java:501)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:163)
at android.os.Binder.execTransact(Binder.java:573)
I tested this library with android 6.0 and work properly.
Can someone help me to fix this problem?
It'is very strange that android does not provide any native method to add badge on icon.
Thanks,
Sebastiano lazzaro
I made a music player app. It runs properly in some devices but it crashes in some others. I am not able to understand the error. How do I fix it? All I understand is the first error and that is I have to take separate permission for read phone state permission.
Error 1:
java.lang.RuntimeException: Unable to create service beatbox.neelay.beatbox.MediaService: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2804)
at android.app.ActivityThread.access$1900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1404)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenForSubscriber(ITelephonyRegistry.java:544)
at android.telephony.TelephonyManager.listen(TelephonyManager.java:2514)
at beatbox.neelay.beatbox.MediaService.callStateListener(MediaService.java:612)
at beatbox.neelay.beatbox.MediaService.onCreate(MediaService.java:126)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2794)
... 9 more
This is the error that is submitted by the user.
Error 2:
Writing exception to parcel
java.lang.SecurityException:
External path: /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1481126994678: Neither user 10199 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.
at android.app.ContextImpl.enforce(ContextImpl.java:1443)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1475)
at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:675)
at com.android.providers.media.MediaProvider.enforceCallingOrSelfPermissionAndAppOps(MediaProvider.java:6793)
at com.android.providers.media.MediaProvider.checkAccess(MediaProvider.java:5570)
at com.android.providers.media.MediaProvider.ensureFileExists(MediaProvider.java:4381)
at com.android.providers.media.MediaProvider.getAlbumArtOutputUri(MediaProvider.java:5834)
at com.android.providers.media.MediaProvider.makeThumbInternal(MediaProvider.java:5976)
at com.android.providers.media.MediaProvider.getThumb(MediaProvider.java:5897)
at com.android.providers.media.MediaProvider.openFile(MediaProvider.java:5466)
at android.content.ContentProvider.openAssetFile(ContentProvider.java:1427)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1607)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1673)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:430)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:458)
I have take permission for Android m both in manifest and in Java, and I'm not using any function of write external storage but then also it is showing this error.
On Android >=6.0, We have to request permission runtime.
Step1: add in AndroidManifest.xml file
Step2: Request permission.
Step3: Handle callback when you request permission.
Check this one: Permission at Run Time
Edit: I think you have similar Issue:
you must add this permissions
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to AndroidManifest.xml file
It might be because some of the devices are running Android 6.0 or higher and others are not.
See https://developer.android.com/training/permissions/requesting.html
If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
FATAL EXCEPTION: IntentService[]
Process: com.frenzin.alert, PID: 5892
java.lang.SecurityException: getDeviceId: Neither user 10240 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4207)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
at com.frenzin.alert.RegistrationIntentService.onHandleIntent(RegistrationIntentService.java:44)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
To request permission in runtime, go to https://developer.android.com/training/permissions/requesting.html
Add runtime permission for access
Add library:
compile 'pub.devrel:easypermissions:0.2.1'
private String[] phonePermissions = {Manifest.permission.READ_PHONE_STATE};
if (EasyPermissions.hasPermissions(this, phonePermissions)) {
//success
} else {
EasyPermissions.requestPermissions(this, "Access for Read Phone",
101, phonePermissions);
}
This question already has answers here:
Android 6.0 Permission Error
(5 answers)
Closed 7 years ago.
Yesterday I set upped target and compile sdk to 23 API level. When I launched the app on Nexus 9 with Preview Android M (MPA441) the app crashes with following SecurityException:
FATAL EXCEPTION: main
Process: com.grouplogic.mobilecho, PID: 22554
java.lang.RuntimeException: Unable to create application com.mypackage.MyApplication: java.lang.SecurityException: getDeviceId: Neither user 10098 nor current process has android.permission.READ_PHONE_STATE.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
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.SecurityException: getDeviceId: Neither user 10098 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4175)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
at com.mypackage.utils.DeviceUtils.isRunOnEmulator(DeviceUtils.java:63)
at com.mypackage.utils.DeviceUtils.getDeviceID(DeviceUtils.java:49)
at com.mypackage.domain.service.SettingService.setupPreferences(SettingService.java:79)
at com.mypackage.app.BaseApplication.createSingletons(BaseApplication.java:84)
at com.mypackage.app.BaseApplication.onCreate(BaseApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
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)
Does somebody know why the permission is disabled by default for new installed app when I install app through Android Studio? What is the correct way to avoid this crash, maybe there is way to check enable or not target permission and only if it is enabled the app should use some specific device API (read phone state, contacts and other permissions)? In the Internet I've just found this mention related to this problem1, but there I didn't find any clear explanation: is it bug in Android M or developer cannot understand how to use permission in a safe manner!? Also I've read this post but approach when user should go to settings and enable permission for app looks strange and not user friendly. I guess if user installs app from the Google Play everything will be fine because he explicitly to apply requested permission, but I need to confirm it.
Here you can find how-to request permissions at runtime.
https://developer.android.com/training/permissions/requesting.html
I received this log via Crashlytics:
java.lang.SecurityException: ConnectivityService: Neither user 10099 nor current process has android.permission.ACCESS_NETWORK_STATE.
at android.os.Parcel.readException(Parcel.java:1428)
at android.os.Parcel.readException(Parcel.java:1382)
at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:737)
at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:566)
at android.webkit.TextSelectWindow.isNetworkAvailable(TextSelectWindow.java:903)
at android.webkit.TextSelectWindow.dictSelection(TextSelectWindow.java:475)
at android.webkit.TextSelectWindow.onClick(TextSelectWindow.java:365)
at android.view.View.performClick(View.java:4220)
at android.view.View$PerformClick.run(View.java:17510)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
at dalvik.system.NativeStart.main(NativeStart.java)
Apparently, something requires the ACCESS_NETWORK_STATE permission. The only permission the app currently has is INTERNET, which I only need to receive crash logs via Crashlytics. The app itself never needs any Internet connection and works perfectly without having any permissions whatsoever. Now does that mean Crashlytics requires ACCESS_NETWORK_STATE to work correctly? The strange thing is that this is the first and single crash after a whole crash-free month and Crashlytics always worked without the permission.
The app targets SDK 21 and uses crashlytics:1.1.13 and crashlytics-gradle:1.14.7.
Crashlytics only needs INTERNET permissions. The ConnectivityManager needs the ACCESS_NETWORK_STATE permission