不幸的是,android 11改变了它对存储权限的管理方式。。。我想执行删除和重命名功能,我将代码修改为:
private void deleteFile(int p, View view){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Supprimer ?").setMessage(videoFolder.get(p).getTitle()).setNegativeButton("Annuler", (dialog, which) -> {
}).setPositiveButton("Oui", (dialog, which) -> {
ArrayList<Uri> fichiers = new ArrayList<>();
Uri contentUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, Long.parseLong(videoFolder.get(p).getId()));
File file = new File(videoFolder.get(p).getPath());
fichiers.add(contentUri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
PendingIntent demande = MediaStore.createDeleteRequest(context.getContentResolver(), fichiers);
try {
((Activity) context).startIntentSenderForResult(demande.getIntentSender(),1,new Intent(), 0,0,0);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}else {
boolean deleted = file.delete();
if (deleted){
context.getApplicationContext().getContentResolver().delete(contentUri, null, null);
videoFolder.remove(p);
notifyItemRemoved(p);
notifyItemRangeChanged(p,videoFolder.size());
Snackbar.make(view, "Fichier supprimé avec succès", Snackbar.LENGTH_SHORT).show();
}else{
Snackbar.make(view, "Erreur, le fichier n'a pas été supprimé", Snackbar.LENGTH_SHORT).show();
}
}
}).show();
}
但我不知道如何获取“活动结果”,以便生成file.delete()所做的操作。
有人能帮我吗?谢谢
暂无答案!
目前还没有任何答案,快来回答吧!