Haz todo lo posible por comprender el código correctamente antes de utilizarlo a tu proyecto si tdeseas aportar algo puedes comentarlo.
Solución:
Prueba esto,
private Context mContext=YourActivity.this;
private static final int REQUEST = 112;
if (Build.VERSION.SDK_INT >= 23)
String[] PERMISSIONS = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (!hasPermissions(mContext, PERMISSIONS))
ActivityCompat.requestPermissions((Activity) mContext, PERMISSIONS, REQUEST );
else
//do here
else
//do here
obtener el resultado de los permisos
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
case REQUEST:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
//do here
else
Toast.makeText(mContext, "The app was not allowed to write in your storage", Toast.LENGTH_LONG).show();
verificar permisos para malvavisco
private static boolean hasPermissions(Context context, String... permissions)
if (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;
Manifiesto
Si no desea verificar varios permisos a la vez, agregue el permiso en PERMISOS array me gusta:
String[] PERMISSIONS = android.Manifest.permission.WRITE_EXTERNAL_STORAGE,android.Manifest.permission.READ_EXTERNAL_STORAGE;
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)