我们有一个应用程序,有时需要在其中保存图片。 我们实施了方法来寻求许可。
在我的设备(Galaxy S9,新闻更新)上,一切正常。它请求许可并保存图片。还有我gf的设备(Galaxy A7)。
在其他设备上,它不会征求许可,因此不会保存图片。我已经多次删除了该应用程序,以确保我们尚未在手机上授予我们这些权限。
addPicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (ContextCompat.checkSelfPermission(adding.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
picintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
picintent.putExtra(MediaStore.EXTRA_OUTPUT, picuri);
startActivityForResult(picintent, cameracode);
} else {
requestStoragePermission();
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
picintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
picintent.putExtra(MediaStore.EXTRA_OUTPUT, picuri);
startActivityForResult(picintent, cameracode);
}} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt", Toast.LENGTH_SHORT).show();
}
}
});
private void requestStoragePermission(){
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)){
new AlertDialog.Builder(this)
.setTitle("Berechtigung benötigt")
.setMessage("Diese Bereichtigunjg wird zum speichern des Bildes benötigt")
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(adding.this,new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create().show();
}else {
ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == STORAGE_PERMISSION_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
Toast.makeText(this, "Berechtigung erteilt", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Berechtigung nicht erteilt", Toast.LENGTH_SHORT).show();
}
}
};