This code worked my phone.But it didnt worked from my friend phone. I have permission too . I get This error ;
Neither user 10109 nor current process has android.permission.READ_PHONE_STATE.
Permission ;
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
This is my Code ;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
IMEI= telephonyManager.getDeviceId();
This is probably due to your friend running on Android 6.0 (API level 23). You need to add permissions at Runtime as well as the ones in the Manifest.
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.
Refer here for more information. Maybe take a look at this question to see how to implement runtime permissions, although it's explained in the first link as well.
As per new marshmallow os you need to configure runtime permission for "READ_SMS"
like this :
String permission = Manifest.permission.READ_SMS;
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){
permissionList.add(permission);
if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
requestPermissions(new String[]{permission}), SMS_PERMISSION);
}
}
Related
My question is similar to Android 10 request permission for ACTIVITY_RECOGNITION in a way that I also do not have a permission dialog showing on a device, but conditions are different.
My app is targeting API 29.
In manifest I have
<uses-permission android:name="android.permission.BODY_SENSORS"/> <- for test purposes
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
Requesting permission Manifest.permission.ACTIVITY_RECOGNITION as usual:
fragment.requestPermissions(permissions, GOOGLE_FIT_ANDROID_PERMISSIONS_REQUEST_CODE)
On a device with Android 9 (API28) I do not receive a permission dialog for ACTIVITY_RECOGNITION and when I check a permission status, it is always denied.
I know that permission logic is working, as when I've added BODY_SENSORS permission, I do get a permission dialog for BODY_SENSORS, but not for ACTIVITY_RECOGNITION. As a result, a permission for BODY_SENSORS is granted, but for ACTIVITY_RECOGNITION - not:
permissions array:
android.permission.BODY_SENSORS;android.permission.ACTIVITY_RECOGNITION
grantResults array:
0;-1
Answering my own question. Please don't treat it as a source of truth, it is based on my own tests. Maybe someone from GoogleFit team can comment on this.
Preconditions: your app is targeting API29 or above.
Regardless of Android version, installed on a device, you should add permissions to Manifest file according to documentation. Side note: I was able to query GoogleFit HistoryApi even without those permissions on device with Android 9, but Android 10 will not work.
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
For devices with Android 10 or above: all is simple, you should request runtime permissions, same which you've added to Manifest.
For devices with Android version 9 or below: you don't have to request runtime permissions. This is the part which was not clear from the documentation.
You may, of course, request those permissions, but for android.permission. ACTIVITY_RECOGNITION you will not receive a permission dialog and as a result permission will not be granted.
I'm working on a Cordova app that needs the permissions INTERNET, WRITE_EXTERNAL_STORAGE, ACCESS_WIFI_STATE, and CHANGE_WIFI_MULTICAST_STATE. I have requested these permissions in the manifest like so
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
INTERNET, ACCESS_WIFI_STATE, and CHANGE_WIFI_MULTICAST_STATE are considered normal permissions and according to the docs they will be automatically accepted by Android at install time and the user can't revoke them.
Now in the MainActivity created by Cordova I added this code within an if block that checks to make sure we are on 6.0 or above:
if (checkSelfPermission(Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "has permission");
}
else {
Log.d(TAG, "no permission");
requestPermissions(new String[] { Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
The problem is that on an Android device running 5.1.1 this works and I see all 4 permissions when I go to the permission settings of the app. However on a device running 7.0 and 7.1.1 I get a dialog asking to approve the WRITE_EXTERNAL_STORAGE and all other permissions, since they are normal, do not get asked for approval. They are automatically approved. The issue is that even though I have permission, on the newer devices I can't do things related to these permissions and if I go to the app settings for permissions all I see is permission Storage granted. Nothing for INTERNET, ACCESS_WIFI_STATE, or CHANGE_WIFI_MULTICAST_STATE. I have not tested specifically on a 6.0 device but I think I would have the same issue.
Why are the permissions not showing in the permission settings, and why cant I perform operations that need these permissions, even though Android says I have permission?
The documentation you linked to contains the following statement:
"The system doesn't prompt the user to grant normal permissions, and users cannot revoke these permissions. "
So all permissions except for WRITE_EXTERNAL_STORAGE will always be granted. The only permission you have to ask for is the one which can be revoked.
Why are the permissions not showing in the permission settings
Well, depending on the android version they may be a little hard to find. For example on my emulator running android 7.0, I found a list of all the permissions under Apps -> MyApp -> Permissions, and then clicking "All permissions" in the overflow menu.
I have an Android Cordova app and I'm using GPS, check the network state, read/write on the Documents folder and taking camera pictures. Here my permissions on the manifest XML file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The manifest file is auto generated by the Cordova framework. For some reason I don't see camera permissions. Permissions are not asked at installation time anymore (that's since Android 6) but instead they should be asked before usage.
I correctly get the GPS access permission popup but not the read/write Documents folder permission. I also never get the camera permission albeit I'm able to use it without ever being asked for permission. Same story for the Network status permissions (never being asked).
I find Android permissions scheme extremely confusing, under application manager my app has got Location and Storage as expected, Camera and Network status are missing though.
To recap, inside the app, on the actual code, I'm using at least once those devices
GPS fine grained
GPS coarse (probably the Wifi SSID triangulation trick)
Write on Documents
Read on Documents
Read network status (Offline / Wifi / 3G etc..)
Take picture from the camera
Cordova framework wrote this manifest file:
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.hardware.location.gps (why is it not a .permission?)
android.permission.ACCESS_NETWORK_STATE
android.permission.WRITE_EXTERNAL_STORAGE
On application manager I get those options:
Location
Storage
So basically I get three different sets of permissions :-(
I found this in the this cordova plugin that you mentioned in comments.
So somehow this <uses-permission android:name="android.permission.CAMERA/> have to be in your code so as this plugin can use it.
Maybe you didn't check the right program to see its permissions, or if the camera permission is not shown in application permissions on device, you can't be able to use camera in this application. Please do a check again because I really want to know what is the situation.
I have an application that requires the internet permission but it doesn't seem to be working for me.
I added:
<uses-permission android:name="android.permission.INTERNET"/>
To the manifest (above the application tag) and when I install the app my phone says: "No permissions requested" and the permission dialog doesn't show up.
However when I replace INTERNET with CAMERA like so:
<uses-permission android:name="android.permission.CAMERA"/>
It works fine and shows up under the permissions tab in settings.
Any ideas?
Thanks
If the device is running Android 6.0 (API level 23) and the app's targetSdkVersion is 23 or higher if an app declares in its manifest that it needs a normal permission, the system automatically grants the app that permission at install time.
The system does not prompt the user to grant normal permissions, and users cannot revoke these permissions.
As you can check in the official doc the INTERNET permission is normal.
Instead the CAMERA permission is dangerous.
You're running your app in Android SDK>=23.
Internet permission is under Normal permission so it not show any permission prompt but Camera permission is under Dangerous Permission so it show permission prompt.
If an app declares that it needs a normal permission, the system automatically grants the permission to the app.
https://developer.android.com/guide/topics/permissions/requesting.html
Android only puts the dangerous permissions there. And since Camera is a dangerous permissions you see it in the list, and since Internet is not, you don't see it in the list.
Android differentiates between normal permissions (e.g. INTERNET) and dangerous permissions (e.g. CAMERA). The User is only asked in case of dangerous permissions. So the behavior you see is perfectly normal.
https://developer.android.com/guide/topics/permissions/normal-permissions.html
Only Selected permissions can be asked for user
check here which permissions can be asked by Permission manager
This usually does the trick for me:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_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.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I have an Android application which need the permissions: READ_PHONE_STATE & CALL_PHONE. I've declared these permissions in the Manifest and it works fine for SDK < 23.
Now in Android 6 (SDK 23) I'm asking the user to grant this permission in runtime.
In the documentation, they say the if the user has granted one of the above permission, he actually granted all the permissions that are found in the same group permissions, in this case all the permission that are related to the phone group permissions.
But I'm facing with a problem, when I'm using telephony manager to get the deviceid, I'm getting a security exceptions that says that I don't have any access, even though the user has granted the "call phone" permission, why is that?
Update:
I'm requesting multiple permissions
In Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE">
<uses-permission android:name="android.permission.READ_PHONE_STATE">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">
In Activity:
ActivityCompat.requestPermissions(this,new String[]
{
Manifest.permission.CALL_PHONE,
Manifest.permission.READ_EXTERNAL_STORAGE
},
permissionRequestcode);