How can I refresh the Gallery after I inserted an Image in android?

后端 未结 5 1547
旧时难觅i
旧时难觅i 2020-12-01 06:47

I\'ve added an inserted in Gallery using android API as following:

Images.Media.insertImage(ctx.getContentResolver(), \"scard/test.jpg\", \"Hello\"

5条回答
  •  囚心锁ツ
    2020-12-01 07:17

    static public boolean resetExternalStorageMedia(Context context) {
        if (Environment.isExternalStorageEmulated())
            return (false);
        Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory());
        Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED, uri);
    
        context.sendBroadcast(intent);
        return (true);
    }
    
    static public void notifyMediaScannerService(Context context, String path) {
        MediaScannerConnection.scanFile(context,
                new String[] { path }, null,
                new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);
            }
        });
    }
    

提交回复
热议问题