I have a flashlight that needs CAMERA and WRITE_SETTINGS permissions, I need to first handle these permissions which I already know how to do it, Then if it is granted, for example, start my main activity... (sorry, I am new in android)
Add this library from github in your gradle file
Than add this code
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {
//The user have conceded permission
Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();
}
@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
//close the app or do whatever you want
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
}
};
new TedPermission(this)
.setPermissionListener(permissionlistener)
.setDeniedMessage("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")
.setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)
.check();
Or if you prefer do it natively, check in the google docs
On your manifest file add permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
On your main activity java file inside "onCreate" add following code
String[] PERMISSIONS = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.CALL_PHONE};
if (
(ContextCompat.checkSelfPermission(MapsActivity.this, PERMISSIONS[0]) != PackageManager.PERMISSION_GRANTED) ||
(ContextCompat.checkSelfPermission(MapsActivity.this, PERMISSIONS[1]) != PackageManager.PERMISSION_GRANTED)
)
{
ActivityCompat.requestPermissions(MapsActivity.this, PERMISSIONS, REQUEST_INTERNET);
finish();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With