I am checking permission if my android application have permissions on WRITE_EXTERNAL_STORAGE. I have already added in application manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I am using Code :
try{
boolean hasPermission =this.checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if ( hasPermission) {
Log.v("AppPerm", "Permission is granted");
Toast.makeText(getBaseContext(), "Permission is granted", Toast.LENGTH_LONG)
.show();
}
else {
msgbox("Error:Storage Permission Not Granted");
Toast.makeText(getBaseContext(), "Error:Storage Permission Not Granted", Toast.LENGTH_LONG)
.show();
}
}catch (Exception e){
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
.show();
}
When this code is executed (in android version 5.1) the Application Crashes with error :
unfortunately, the application has stopped.
I don't want the application to crash, It is not Catching the error?