Android: java.net.SocketException: Permission denied - android

Some of my app users are seeing the "Permission denied" exception
Specially for the following device: Xiaomi MI MAX Android OS: 7.0
Other devices are able to access Internet.
I've added the required permissions before the application tag, like this,
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application>
...
</application>
Can anyone please help what is wrong here?

For Android 6.0 and above, there is a new way of requesting permission from the user, which is called runtime permission, which means permission is granted when the app is running, not when it is installed like earlier versions.
Check the official guide for complete explanation

Related

No prompt or toggle for Android permission

In my app on Android 7, targetSdkVersion 24, I am trying to request an Android permission WRITE_EXTERNAL_STORAGE. However, when I run the app, it never prompts me for this permission, and when on my device I go to Settings > Apps > MyApp > Permissions, I do not see a toggle for anything related to WRITE_EXTERNAL_STORAGE.
Have I missed a step somewhere?
AndroidManifest.xml (complete file on pastebin)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
MyActivity.java
int permission = activity.checkSelfPermission(perm);
if (permission != PackageManager.PERMISSION_GRANTED)
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
After spending some time to investigate, I have developed a theory on this issue.
My app has some dependencies that has this in their AndroidManifest.xml:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
What this does is auto deny WRITE_EXTERNAL_STORAGE permission if the SDK is higher than 18. That's consistent with the issues I am getting; Permission getting denied and not even prompt the user.
Then I test adding this to my App AndroidManifest.xml in attempt to override the lib dependency permission settings:
android:maxSdkVersion="25"
It then fails to build due to Merge conflict on masSdkVersion. This further confirms my suspicions on the issue; the android:maxSdkVersion propagated to the App module.
After digging through the docs, I can't find the solution, but I have a work around. READ_EXTERNAL_STORAGE is in the same group as the WRITE_EXTERNAL_STORAGE, and the doc says asking a permission for the same group would apply to the rest of permission for the whole group.
So I tested asking READ permission throughout my App and AndroidManifest.xml, it works, but I think it's stupid.
I will update when I find a proper way to resolved.

java.lang.RuntimeException: Unable to pause activity : java.lang.SecurityException: uid does not have android.permission.UPDATE_DEVICE_STATS

This exception is coming on my main activity:
java.lang.RuntimeException: Unable to pause activity:
java.lang.SecurityException: uid does not have android.permission.UPDATE_DEVICE_STATS
I have noticed that this is coming on Android 6.0.1 (Marshmallow) and device is Samsung Galaxy J7. When I researched about the permission UPDATE_DEVICE_STATS, I found out that this permission is needed by system apps.
Can anyone please guide me why this exception suddenly started to showing up as my app is running fine on other devices.
In 6.0 and above you have to get the permissions dynamically not at the application install time you must check this link.Permission are of two types dangerous and non dangerous.
For Marshmallow and above android version you have to check whether the requested permission is accepted by user or not dynamically using following code:
ActivityCompat.requestPermissions();
You have to check each and every permissions runtime.
and ensure that you have defined following permission in your manifest:
<uses-permission android:name="android.permission.GET_TASKS" >
</uses-permission>
not
<user-permission android:name="android.permission.GET_TASKS" >
</user-permission>
Another solution is to define targetSdkVersion bellow 23 in manifest file :
android:targetSdkVersion="21"

Permission denied, AndroidManifest.xml does not work

m developing launcher for 2.3.3 via specified STB. And I wrote permissions like
...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
in AndroidManifest.xml.
While debugging -uninstall/install-, sometimes meet "Permission denied" so i should uninstall/install again and again till got no errors with "Permission denied".
Does anyone get this strange bug? Of course, I did not edit AndroidManifest.xml at all.
If while debugging your Device is connected to a PC and
Enable copy files to/from your computer.
Then you will see this Permission denied message.
I have had recently this problem, when I upgraded the targetSdkVersion to 23. The "problem" was the new system of dynamic permissions in Android. See http://developer.android.com/training/permissions/requesting.html

How to fix HARDWARE_TEST permission error?

i'm developing an android app which uses some hardware parts like camera or Wi-Fi, and i'm using HARDWARE_TEST permission in the manifiest:
<uses-permission android:name="android.permission.HARDWARE_TEST">
I never have had any issue with that, but now suddenly when I eclipse and manifiest file, a new error is shown in this line:
"Permission is only granted to system apps"
The only way i've got to fix it is deleting this line.
Why is this error?? How can I fix it?
Thanks
Edited:
I have found the solution and answer my own question:
My problem was in android:targetSdkVersion value in manifiest which was 15 and proyect build target was checked API level 16 (Android 4.1.2)
<uses-sdk
android:minSdkVersion="2"
android:targetSdkVersion="15" />
So i have changed android:targetSdkVersion value to 16 and Proyect properties > Android > "Proyect Buid Target" checked 16 too.
There are several permission protection level for Android Permissions: Normal, Dangerous, System and signatureOrSystem.
signatureOrSystem Permission can only be granted to System applications. And For permissions in signature level:
A permission that the system grants only if the requesting application
is signed with the same certificate as the application that declared
the permission. If the certificates match, the system automatically
grants the permission without notifying the user or asking for the
user's explicit approval.
Here is the permission definition syntax.
Here is the definition of the HARDWARE_TEST permission:
<!-- Allows access to hardware peripherals. Intended only for hardware testing -->
<permission android:name="android.permission.HARDWARE_TEST"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="signature"
android:label="#string/permlab_hardware_test"
android:description="#string/permdesc_hardware_test" />
It is a signature permission in Android 4.2, so it can only be granted to app with the same signature(signed by vendor). So your application cannot request that permission.
If you want to directly manipulate hardware, you may need a rooted device.

Exception in android manifest file permission

I got exception in android manifest file.
I have added following permissions:
1. uses-permission android:name="android.permission.CALL_PRIVILEGED" />
2. uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
I got
"Permission is only granted to system apps" error. How to fix it. Before it was working fine.
you can't fix it. As mentioned:
"Permission is only granted to system apps"
This mean, no ordinary app can use the permissions. At least, not without rooting the device.

Categories

Resources