Reputation: 381
I am facing problem in implementing runtime permissions. I went through below link for implementing runtime permissions:
https://developer.android.com/training/permissions/requesting.html
I facing problem for android.permission.MODIFY_PHONE_STATE" only. I have tested the below code for CAMERA permission and code working fine for camera permission.
Problem I am facing:
Grade Details: compileSdkVersion 23, buildToolsVersion "23.0.3", targetSdkVersion 23
Manifest Details: I have added the following permission
uses-permission android:name="android.permission.MODIFY_PHONE_STATE"
private static final int PERMISSIONS_REQUEST_CODE = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int granted = PackageManager.PERMISSION_GRANTED;
int result = ContextCompat.checkSelfPermission(ActivityMain.this,Manifest.permission.MODIFY_PHONE_STATE);
if (result == granted) {
Toast.makeText(ActivityMain.this,"permissions granted",Toast.LENGTH_LONG).show();
}
if (result != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(ActivityMain.this, "permissions denied", Toast.LENGTH_LONG).show();
boolean res = ActivityCompat.shouldShowRequestPermissionRationale(ActivityMain.this,Manifest.permission.MODIFY_PHONE_STATE);
// returning false
if (res) {
new AlertDialog.Builder(ActivityMain.this)
.setMessage("Allow")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(ActivityMain.this,
new String[]{Manifest.permission.MODIFY_PHONE_STATE},
PERMISSIONS_REQUEST_CODE);
}
}).setNegativeButton(android.R.string.cancel, null).show();
} else {
ActivityCompat.requestPermissions(ActivityMain.this,
new String[]{Manifest.permission.MODIFY_PHONE_STATE},
PERMISSIONS_REQUEST_CODE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(ActivityMain.this,"permissions granted",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ActivityMain.this,"permissions not granted",Toast.LENGTH_LONG).show();
}
return;
}
}
}
Upvotes: 3
Views: 2331
Reputation: 1023
MODIFY_PHONE_STATE is a system-only permission, so you can not access or use this permission in your app.
There are 2 types of Android apps: system & user
System apps are basically the apps that come pre-installed with your ROM. In a standard Android user environment, the user doesn’t have write access to the /system partition and thus, installing or uninstalling system apps directly isn’t possible.
User apps are just all your normal app installations through the Google Play Store. These go into the data partition of your Android phone, which is the part of the internal memory made available for user data and apps.
In order to install an app as a system app on your Android device, your device must either be rooted or have a custom recovery installed (or both).
Upvotes: 4