Android 6 revoked permissions checked as granted - android

Got a problem hat I'm not sure is a bug or not.
If the user grants a permission and then subsequently revokes it, it appears that checkSelfPermission returns GRANTED on the revoked permission.
e.g. it appears that after revoking permission.CAMERA:
true == ActivityCompat.checkSelfPermission(context, permission.CAMERA)
== PackageManager.PERMISSION_GRANTED
The only way i seem to find out that camera was revoked is by an exception:
10-20 14:25:54.330: E/AndroidRuntime(13954): java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Pictures/JPEG_20151020_142554_399504353.jpg} (has extras) } from ProcessRecord{adc5d77 13954:com.conx2share.conx2share.staging/u0a144} (pid=13954, uid=10144) with revoked permission android.permission.CAMERA
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.os.Parcel.readException(Parcel.java:1599)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.os.Parcel.readException(Parcel.java:1552)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.app.Activity.startActivityForResult(Activity.java:3917)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.app.Activity.startActivityForResult(Activity.java:3877)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:855)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:907)
10-20 14:25:54.330: E/AndroidRuntime(13954): at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:930)
Does anyone know if this is user error or a bug in the new permissions system?

I'm a little late to the party, but I just had this problem and think should be useful to someone else in the future.
According to Google link https://developers.google.com/android/guides/permissions#prerequisites
Along with new platform features, Android 6.0 Marshmallow has a new
permissions model that streamlines the app install and auto-update
process. Permissions are now requested at runtime instead of before
app installation.
So, if you are targeting your app to SDK level 23 or greater, permissions declared in AndroidManifest.xml are not enough (though necessary). Ensure that you are using the V4 support library and do the check as shown below:
#Override
public void onClick(View view) {
// Check permission for CAMERA
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// Check Permissions Now
// Callback onRequestPermissionsResult interceptado na Activity MainActivity
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.CAMERA},
MainActivity.REQUEST_CAMERA);
} else {
// permission has been granted, continue as usual
Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(captureIntent, 0);
}
In my case, i did the check on a Fragment, but could be done in an Activity, it depends on your needs.
The user can grant permission to the app by going to Settings > Apps > yourapp and then grant the permission. In that case, the logic goes by the else and the intent is called.
In the other hand, the life is not so easy and the user won't do that. Therefore we have to call ActivityCompat.requestPermissions:
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.CAMERA},
MainActivity.REQUEST_CAMERA);
In the first parameter I passed getActivity() because I am using a Fragment. If you are using Activity, pass this. The second parameter is the permission to be checked and the third is an app-defined int constant to be used as an identifier into the callback method that I will explain next.
public static final int REQUEST_CAMERA = 1;
ActivityCompat.requestPermissions will open a dialog asking the user to grant or deny the permission. That's why we have to use the method onRequestPermissionsResult:
#Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
Toast.makeText(getApplicationContext(), "Permission granted", Toast.LENGTH_SHORT).show();
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(getApplicationContext(), "Permission denied", Toast.LENGTH_SHORT).show();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
In case you are using Fragment, like me, this callback method have to be in the Activity that contains the Fragment.

This turns out to have been a programmer error in the logic.

Related

Automatically detect to show allow permission after user deny in the first time asking

I working with anroid app in Android M and need some permission that allow to access CAMERA, RECORD_AUDIO, WRITE_EXTERNAL_STORAGE, ... so I put my permission checking when user open the app in the first time. But if user deny it, how can I detect it automatically that user is using the feature that required permission then ask them again? Or I have to put my condition in every feature that need permission.
I know when we use some feature that required permission but not allowed already it will throw the exception, so do we have any class that handle this task?
I use this logic: Every Activity extends a BaseActivity, in which there is a method that check the permissions everytime the onCreate() is called.
The method that I use is:
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
So, everytime the user launch a new Activity, the application check the permissions and display which permissions are not granted yet.
To manage the result, use onRequestPermissionsResult()
BTW, this logic will ask the user the permission even if the activity's feature doesn't require any permission.
If you want to ask the user the permissions only where the feature that requires a permission, you must check it in every activity
onRequestPermissionsResult you can check particular Permission is granted or not you can call Permission dialog again from there if particular permission not granted for Example
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions,
#NonNull int[] grantResults) {
if (requestCode == REQUEST_CAMERA) {
// BEGIN_INCLUDE(permission_result)
// Received permission result for camera permission.
Log.i(TAG, "Received response for Camera permission request.");
// Check if the only required permission has been granted
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Camera permission has been granted, preview can be displayed
Log.i(TAG, "CAMERA permission has now been granted. Showing preview.");
Snackbar.make(mLayout, R.string.permision_available_camera,
Snackbar.LENGTH_SHORT).show();
} else {
Log.i(TAG, "CAMERA permission was NOT granted.");
// Ask again for permission
}
// END_INCLUDE(permission_result)
} else if (requestCode == REQUEST_CONTACTS) {
Log.i(TAG, "Received response for contact permissions request.");
// We have requested multiple permissions for contacts, so all of them need to be
// checked.
if (PermissionUtil.verifyPermissions(grantResults)) {
// All required permissions have been granted, display contacts fragment.
Snackbar.make(mLayout, R.string.permision_available_contacts,
Snackbar.LENGTH_SHORT)
.show();
} else {
Log.i(TAG, "Contacts permissions were NOT granted.");
// Ask again for permission
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

Intent call action doesn't work on Marshmallow

I'm trying to start a call intent action on a device who has Marshmallow as OS, Using the same steps as usual (This is working on versions below):
Add permission:
<uses-permission android:name="android.permission.CALL_PHONE" />
Open the intent:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + getString(R.string.connect_phone)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This is the log I'm getting:
FATAL EXCEPTION: main
Process: com.app.calling, PID: 4250
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.intent.action.CALL dat=tel:xxxxxxxxxxxxx flg=0x10000000
cmp=com.android.server.telecom/.components.UserCallActivity
VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} }
from ProcessRecord{1618b01 4250:com.app.calling/u0a234} (pid=4250,
uid=10234) with revoked permission android.permission.CALL_PHONE
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at
android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3130)
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1540)
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.app.Activity.startActivityForResult(Activity.java:4230)
at
android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:849)
at
android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:907)
at android.support.v4.app.Fragment.startActivity(Fragment.java:919)
at
com.app.calling.activity.fragment.ConnectFragment$2.onGroupClick(ConnectFragment.java:44)
at
android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:676)
at
android.widget.ExpandableListView.performItemClick(ExpandableListView.java:654)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3821)
at android.widget.AbsListView$3.run(AbsListView.java:5841)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Again, this process is working fine in the previous version (Lollipop and kitkat)unfortunately isn't on Marshmallow, does anybody know why or what I'm missing?
Method to make call
public void onCall() {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.CALL_PHONE},
"123");
} else {
startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:12345678901")));
}
}
Check permission
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
switch (requestCode) {
case 123:
if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
onCall();
} else {
Log.d("TAG", "Call Permission Not Granted");
}
break;
default:
break;
}
}
Beginning in android 6.0 (API 23), dangerous permissions must be declared in the manifest AND you must explicitly request that permission from the user. According to this list, CALL_PHONE is considered a dangerous permission.
Every time you perform an operation that requires a dangerous permission, you must check if that permission has been granted by the user. If it has not, you must request that it be granted. See Requesting Permissions at Run Time on Android Developers.
For Marshmallow version and above you need to ask the permission at runtime not only in the manifest file. Here is the documentation:
Requesting Permissions at Run Time
Hope it helps.

Requesting multiple Bluetooth permissions in Android Marshmallow

I'm developing an app with connectivity which connects to a Bluetooth device with SDK 23 as compile with. I'm having problems with requesting multiple permissions for Bluetooth. This is what I have done so far:
#Override
public void onStart() {
super.onStart();
if (D)
Log.e(TAG, "++ ON START ++");
if (ContextCompat.checkSelfPermission(MyBlueToothClientActivity.this,
Manifest.permission.BLUETOOTH)
!= PackageManager.PERMISSION_GRANTED) {
} else {
ActivityCompat.requestPermissions(MyBlueToothClientActivity.this,
new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN},
REQUEST_ENABLE_BT);
}
if (ContextCompat.checkSelfPermission(MyBlueToothClientActivity.this,
Manifest.permission.BLUETOOTH)
!= PackageManager.PERMISSION_GRANTED) {
} else {
ActivityCompat.requestPermissions(MyBlueToothClientActivity.this,
new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN},
REQUEST_CONNECT_DEVICE_INSECURE);
}
}
#Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_ENABLE_BT: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
if (CommonData.mChatService == null)
setupChat();
Toast.makeText(MyBlueToothClientActivity.this, "Permission denied for bluetooth", Toast.LENGTH_SHORT).show();
}
return;
}
case REQUEST_CONNECT_DEVICE_INSECURE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_CONNECT_DEVICE_INSECURE);
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
if (CommonData.mChatService == null)
setupChat();
Toast.makeText(MyBlueToothClientActivity.this, "Permission denied for bluetooth", Toast.LENGTH_SHORT).show();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
Although I'm able to get the dialogue box for requesting enabling the Bluetooth, I don't get the second permission, i.e. to connect to a device. In the logcat, I get:
01-01 06:41:24.334 25473-25473 E/BluetoothChat: ++ ON START ++
01-01 06:41:24.344 25473-25473 W/Activity: Can reqeust only one set of permissions at a time
And since I'm not able to connect to the device, I just get stuck here. And this code works fine on Android version up to Lollipop, just causes problem on the Marshmallow version.
BLUETOOTH and BLUETOOTH_ADMIN are normal permissions and are therefore they are automatically granted. Only permissions in the table of dangerous permissions need to requested at runtime.
However, as mentioned in the Android 6.0 changes: Access to Hardware Identifier:
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions:
WifiManager.getScanResults()
BluetoothDevice.ACTION_FOUND
BluetoothLeScanner.startScan()
If you're using any of those methods, you'll need to request at least ACCESS_COARSE_LOCATION at runtime (as it is a dangerous permission).

Revoked permission android.permission.CALL_PHONE

I'm trying to programmatically call to a number with following code:
String number = ("tel:" + numTxt.getText());
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(number));
startActivity(intent);
I've set the permission in the Manifest:
<uses-permission android:name="android.permission.CALL_PHONE"/>
I'm working with real device for testing and debugging, it is Nexus 5 with Android M, my compileSdkVersion is 23. I'm getting the following Security Exception:
error: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{cbbd7c1 5228:com.dialerTest.DialerApp/u0a96} (pid=5228, uid=10096) with revoked permission android.permission.CALL_PHONE
I've searched the web and this community for similar Q/A and couldn't find the answer. Any help will be appreciated.
Permission CALL_PHONE belong to dangerous permission group.
So if your apps target SDK is 23 or higher and your device is running on Android 6.0 or higher, you must request for CALL_PHONE permission while the app is running.
Example :
String number = ("tel:" + numTxt.getText());
mIntent = new Intent(Intent.ACTION_CALL);
mIntent.setData(Uri.parse(number));
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_CALL_PHONE);
// MY_PERMISSIONS_REQUEST_CALL_PHONE is an
// app-defined int constant. The callback method gets the
// result of the request.
} else {
//You already have permission
try {
startActivity(mIntent);
} catch(SecurityException e) {
e.printStackTrace();
}
}
When your app requests permissions, the system presents a dialog box to the user. When the user responds, the system invokes your app's onRequestPermissionsResult() method, passing it the user response.
#Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_CALL_PHONE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the phone call
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
In android 6.0 (Api lvl 23) we have something called "Runtime Permissions". You have to read about it.
You can find documentation here.
You code could works only if you make an ACTION_DIAL, not an ACTION_CALL where you need to request a permission, so if you want to make a call, please follow this example:
MANIFEST:
<uses-permission android:name="android.permission.CALL_PHONE" />
Code:
import static android.Manifest.permission.CALL_PHONE;
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:0612312312"));
/*
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData(Uri.parse("tel:0612312312"));
if (i.resolveActivity(getPackageManager()) != null) {
startActivity(i);
}*/
if (ContextCompat.checkSelfPermission(getApplicationContext(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
startActivity(i);
} else {
requestPermissions(new String[]{CALL_PHONE}, 1);
}
in fragment class
Step 1:
import static android.Manifest.permission.CALL_PHONE;
step 2:Where your onclick button:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" +driver_no ));
if (ContextCompat.checkSelfPermission(getActivity(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
startActivity(callIntent);
} else {
requestPermissions(new String[]{CALL_PHONE}, 1);
}
[Or] you are using in activity class means change the getActivity to getApplicationContext()
FYI: If you're targeting Android 11, you need to add an Intent Query element for Intent.ACTION_DIAL in your manifest.
https://developer.android.com/training/basics/intents/package-visibility#intent-signature

SecurityException thrown when calling WifiManager startScan

I'm using a PendingIntent launched by AlarmManager (with setRepeating) to start wifi scans (using IntentService) every few minutes.
On most devices and in most cases, there is no problem with that.
However, on several devices I get the following error (Couldn't reproduce the error on any test device. This is a crash log from a user's device):
java.lang.RuntimeException: Unable to start service com.myapp.android.service.MyService#44a9701 with Intent { act=com.myapp.android.ACTION_PERFORM_WIFI_SCAN flg=0x4 cmp=com.myapp/com.mayapp.android.service.MyService (has extras) }: java.lang.SecurityException: Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3021)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5415)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
Caused by: java.lang.SecurityException: Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.net.wifi.IWifiManager$Stub$Proxy.startScan(IWifiManager.java:1045)
at android.net.wifi.WifiManager.startScan(WifiManager.java:1088)
...
I'm creating the PendingIntent from my app so I see no reason for the SecurityException thrown from WifiManager (Especially since this happens rarely).
The IntentService launched from the PendingIntent code is as follows:
mContext.registerReceiver(mWifiScanReceiver, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
boolean ok = mWifiManager.startScan();
Any ideas on what might be causing this?
This is happening because of the new app permissions for android m.
See the comment above the source code of wifimanager's getScanResults() for api 23-
/**
* Return the results of the latest access point scan.
* #return the list of access points found in the most recent scan. An app must hold
* {#link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
* {#link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission
* in order to get valid results.
*/
public List<ScanResult> getScanResults() {
try {
return mService.getScanResults(mContext.getOpPackageName());
} catch (RemoteException e) {
return null;
}
}
Hence, you will have to ask the user for permissions on runtime. Put these permissions in your manifest-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
From api 23 onwards you require a permission to access user location to use it. I suggest you use a permissions check based on the api level and start intent only if the permissions have been granted.
Something like this-
if (Build.VERSION.SDK_INT >= 23) {
int hasReadLocationPermission = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
if (hasReadLocationPermission != PackageManager.PERMISSION_GRANTED) {
if (!ActivityCompat.shouldShowRequestPermissionRationale(HomeActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) {
showMessageOKCancel("You need to allow access to GPS",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(HomeActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GPS_ENABLE_REQUEST);
}
});
return;
}
ActivityCompat.requestPermissions(HomeActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GPS_ENABLE_REQUEST);
return;
}
if (locationManager != null && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
gotoGPSEnableScreen();
} else {
//Permissions granted and gps is on
launchService(true);
}
}
Further to check results-
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case GPS_ENABLE_REQUEST:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
gotoGPSEnableScreen();
}
} else {
launchService(false);
}
default:
return;
}
}
UPDATE:
android.permission.INTERACT_ACROSS_USERS_FULL is a signature level permission.
Just add this android:protectionLevel="signature" in your manifest .
For more details you can check this
http://developer.android.com/guide/topics/manifest/permission-element.html
<permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>
If you're going to override
onCreate()
in your
IntentService,
then make sure you call
super.onCreate()
in it. That seems to quite likely be your problem.
Your issue is you are calling from different user and asking to run on different user and that requires android.permission.INTERACT_ACROSS_USERS_FULL and that is signature level permission. Just add this android:protectionLevel="signature" in your manifest .
For more details you can check this
http://developer.android.com/guide/topics/manifest/permission-element.html
<permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>

Categories

Resources