dynamically add pictures to gallery widget

前端 未结 2 1966
萌比男神i
萌比男神i 2020-12-06 07:38

Is there a good way to add new image resources(from SD card) to a gallery widget at runtime?

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 07:53

    Send broadcast to MediaStore Content Provider when you add a file

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageAdded)));
    

    Working for devices before KitKat

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                  Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
    

    Also have a look at this

    Working in Lolipop and should also solve kitkat issues.

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.DATA,"file path");
    values.put(MediaStore.Images.Media.MIME_TYPE,"image/jpeg");
    mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
    

    Add Permission.

    
    

提交回复
热议问题