我是安卓新手。现在,我正在使用以下方法进行图像捕获功能:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
问题是我拍摄照片后,新拍摄的照片不会显示在图像显示页面上。
这里有谁知道哪里有代码可以帮助我刷新我的 android 或我需要执行的任何步骤,以便在我拍摄新照片后可以更新我的图像显示页面?
任何帮助将不胜感激,并首先感谢您。
更新的答案:我用这个,可能这可以帮助别人:
mScanner = new MediaScannerConnection(
Camera.this,
new MediaScannerConnection.MediaScannerConnectionClient() {
public void onMediaScannerConnected() {
mScanner.scanFile(outputFileUri.getPath(), null /* mimeType */);
}
public void onScanCompleted(String path, Uri uri) {
//we can use the uri, to get the newly added image, but it will return path to full sized image
//e.g. content://media/external/images/media/7
//we can also update this path by replacing media by thumbnail to get the thumbnail
//because thumbnail path would be like content://media/external/images/thumbnail/7
//But the thumbnail is created after some delay by Android OS
//So you may not get the thumbnail. This is why I started new UI thread
//and it'll only run after the current thread completed.
if (path.equals(outputFileUri.getPath())) {
mScanner.disconnect();
//we need to create new UI thread because, we can't update our mail thread from here
//Both the thread will run one by one, see documentation of android
Camera.this
.runOnUiThread(new Runnable() {
public void run() {
}
});
}
}
});
mScanner.connect();