次のコードを使用してサムネイルを取得し、それらを gridView に入力します。そのような画像の情報はデータベースに保存され、画像のサムネイルは別のデータベースに保存されている
と思います。as BUCKET_DISPLAY_NAME,MediaStore.Images.Media.DATA and MediaStore.Images.Media._ID
画像を削除したい場合は、3 つの部分を削除する必要があります。1 つは物理ファイル、2 つはデータベース内の画像の情報の記録、3 つは別のデータベース内のサムネイルの記録ですよね?
次のコードは、2 つの部分のみを削除するためのものです。1 つは物理ファイルで、2 つはデータベース内の画像情報の記録です。サムネイルの記録を削除するにはどうすればよいですか? ありがとう!
ところで、コード
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
非同期なので、画像を削除した後、すぐに最新のサムネイルを取得する必要があります。
さらに、
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())))
画像の情報データベースとサムネイル データベースの両方を更新しますか?
private void FillImageAndThumb() {
this.count = curPublic.getCount();
this.thumbnails = new Bitmap[this.count];
this.arrPath = new String[this.count];
this.thumbnailsselection = new boolean[this.count];
this.myID=new int[this.count];
for (int i = 0; i < this.count; i++) {
curPublic.moveToPosition(i);
int id = curPublic.getInt(curPublic.getColumnIndex(MediaStore.Images.Media._ID));
int dataColumnIndex =curPublic.getColumnIndex(MediaStore.Images.Media.DATA);
myID[i]=id;
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(),
id,
MediaStore.Images.Thumbnails.MICRO_KIND,
null);
arrPath[i] = curPublic.getString(dataColumnIndex);
}
}
private void SetCurPublic(AdapterView<?> arg0,int index){
String[] projection = new String[]{
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATA
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
if (index==0){
curPublic = getContentResolver().query(
images,
projection,
"",
null,
""
);
}else{
String s=arg0.getSelectedItem().toString();
curPublic= getContentResolver().query(
images,
projection,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME+"=?",
new String[]{s},
"" // Ordering
);
}
}
public void DeleteSelected() {
for (int i = 0; i < thumbnailsselection.length; i++) {
if (thumbnailsselection[i]) {
File fdelete = new File(arrPath[i]);
if (fdelete.exists()) {
if (fdelete.delete()) {
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String mSelectionClause = MediaStore.Images.Media._ID
+ "=?";
String[] mSelectionArgs = { String.valueOf(myID[i]) };
getContentResolver().delete(
images,
mSelectionClause,
mSelectionArgs
);
}
}
}
}
}