“新形象资源”?
图像资源是.apk应用程序包中/ res / drawable文件夹的一部分.您无法在运行时添加“新”图像资源.
你有没有其他一些用例?
海报解释后编辑:
您必须将媒体文件添加到Media Store才能被gallery小部件看到.使用MediaScanner.我在我的代码中使用这个方便的包装器:
public class MediaScannerWrapper implements
MediaScannerConnection.MediaScannerConnectionClient {
private MediaScannerConnection mConnection;
private String mPath;
private String mMimeType;
// filePath - where to scan;
// mime type of media to scan i.e. "image/jpeg".
// use "*/*" for any media
public MediaScannerWrapper(Context ctx,String filePath,String mime){
mPath = filePath;
mMimeType = mime;
mConnection = new MediaScannerConnection(ctx,this);
}
// do the scanning
public void scan() {
mConnection.connect();
}
// start the scan when scanner is ready
public void onMediaScannerConnected() {
mConnection.scanFile(mPath,mMimeType);
Log.w("MediaScannerWrapper","media file scanned: " + mPath);
}
public void onScanCompleted(String path,Uri uri) {
// when scan is completes,update media file tags
}
}
然后实例化MediaScannerWrapper并使用scan()启动它.你可以调整它来处理多个文件.提示:传递文件路径列表,然后循环mConnection.scanFile.