i need to ask multiple permission at one time , but no dialog show in marshmallow and higher.
here is my code:
public class MainActivity extends AppCompatActivity {
private void RequestMultiplePermission() {
// Creating String Array with Permissions.
ActivityCompat.requestPermissions(MainActivity.this, new String[]
{
READ_SMS,
RECEIVE_SMS,
READ_PHONE_STATE,
PROCESS_OUTGOING_CALLS,
INTERNET,
RECEIVE_BOOT_COMPLETED,
READ_EXTERNAL_STORAGE,
WRITE_EXTERNAL_STORAGE
}, RequestPermissionCode);
}
// Calling override method.
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case RequestPermissionCode:
if (grantResults.length > 0) {
boolean ReadSMS = grantResults[0] == PackageManager.PERMISSION_GRANTED;
boolean ReceiveSms = grantResults[1] == PackageManager.PERMISSION_GRANTED;
boolean phoneState = grantResults[2] == PackageManager.PERMISSION_GRANTED;
boolean outGoingCall = grantResults[3] == PackageManager.PERMISSION_GRANTED;
boolean internet = grantResults[4] == PackageManager.PERMISSION_GRANTED;
boolean bootComplete = grantResults[5] == PackageManager.PERMISSION_GRANTED;
boolean readExternalStorage = grantResults[6] == PackageManager.PERMISSION_GRANTED;
boolean WriteExternalStorage = grantResults[7] == PackageManager.PERMISSION_GRANTED;
if (ReadSMS && ReceiveSms && phoneState && outGoingCall && internet && bootComplete && readExternalStorage && WriteExternalStorage) {
Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
}
}
break;
}
}
public boolean CheckingPermissionIsEnabledOrNot() {
int FirstPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), READ_SMS);
int SecondPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), RECEIVE_SMS);
int ThirdPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), READ_PHONE_STATE);
int ForthPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), PROCESS_OUTGOING_CALLS);
int FivePermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), INTERNET);
int sixPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), RECEIVE_BOOT_COMPLETED);
int sevenPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), READ_EXTERNAL_STORAGE);
int eightPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(), WRITE_EXTERNAL_STORAGE);
return FirstPermissionResult == PackageManager.PERMISSION_GRANTED &&
SecondPermissionResult == PackageManager.PERMISSION_GRANTED &&
ThirdPermissionResult == PackageManager.PERMISSION_GRANTED &&
ForthPermissionResult == PackageManager.PERMISSION_GRANTED &&
FivePermissionResult == PackageManager.PERMISSION_GRANTED &&
sixPermissionResult == PackageManager.PERMISSION_GRANTED &&
sevenPermissionResult == PackageManager.PERMISSION_GRANTED &&
eightPermissionResult == PackageManager.PERMISSION_GRANTED;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 23) {
if (!CheckingPermissionIsEnabledOrNot()) {
RequestMultiplePermission();
// carry on the normal flow, as the case of permissions granted.
} else {
//other granted stuff
}
}
}
}
result
i get no error , but dialog wasn't show , my users must manually go to app and grant permissions.
Questions
can anybody tell where am i wrong?
why we need to declare permission in manifest and another in runtime?
thanks in advance