Windows 资源管理器中未显示自定义相机照片
Custom camera photos are not showing in Windows Explorer
我已经按照 android 网站上关于如何创建自定义相机应用程序的说明进行操作,到目前为止我已经成功了。我创建了一个带有拍照按钮的布局,它工作正常,图像使用 Camera.PictureCallback
保存在 sdcard 上。
问题是,虽然我的 phone 通过电缆连接到 PC,但如果我浏览到我从应用程序保存图像的目录,它们不会显示,即使我刷新目录。如果我在应用程序中使用它们来做某事,它工作正常,这意味着它们保存在目录中并且路径是正确的。我还可以在 phone.
上使用 File Explorer
看到它们
但是,如果我使用 Windows Explorer
,它们将在一段时间后才会显示。
这是正常现象还是我遗漏了什么?
phone (Samsung Galaxy S6) 作为媒体设备 (MTP) 连接到 PC,但我也尝试将其作为相机 (PTP) 连接,结果是一样的。
这是我用来保存图片的示例代码:
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
String timeStamp = new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date());
String imageFileName = "MyTestPhoto_" + timeStamp;
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File mediaStorageDir = new File(SAVE_IMAGE_PATH);
if (!mediaStorageDir.exists())
mediaStorageDir.mkdir();
File pictureFile = new File(mediaStorageDir + imageFileName + ".jpg");
if (pictureFile == null){
Log.d("PictureCallback", "Error creating media file, check storage permissions.");
return;
}
try{
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
}catch (FileNotFoundException e){
Log.d("PictureCallback ", "File not found: " + e.getMessage());
}catch (IOException ex){
Log.d("PictureCallback ", "Error accessing file: " + ex.getMessage());
}
photoButton.setClickable(true);
camera.startPreview();
}
};
根据我在互联网上找到的内容,这可能会有所帮助:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse(mediaStorageDir + imageFileName + ".jpg")));
但事实并非如此,事实上应用程序现在崩溃了:
Activity com.example.testApplicationCamera.CameraActivity has leaked
IntentReceiver com.example.testApplicationCamera.CameraActivity@28968130
that was originally registered here. Are you missing a call to
unregisterReceiver()?
Android 4.4 KitKat 及更高版本似乎不支持此功能。
我不认为我真的需要它,因为我不想让它在画廊或任何东西中可见,它实际上工作正常,只是出于好奇,为什么它没有出现在 Windows 资源管理器中?
From what I found on the internet, this might help:
这从来都不是一个合适的解决方案,幸运的是现在已经被阻止了。
使用 MediaScannerConnection
及其静态 scanFile()
方法提醒 MediaStore
为您的文件编制索引。
why doesn't it appear in the Windows Explorer?
Windows 正在通过媒体传输协议 (MTP) 连接到 Android 设备。 Android 通过 MTP 连接提供的不是文件系统中的内容,而是 MediaStore
.
索引的内容
我已经按照 android 网站上关于如何创建自定义相机应用程序的说明进行操作,到目前为止我已经成功了。我创建了一个带有拍照按钮的布局,它工作正常,图像使用 Camera.PictureCallback
保存在 sdcard 上。
问题是,虽然我的 phone 通过电缆连接到 PC,但如果我浏览到我从应用程序保存图像的目录,它们不会显示,即使我刷新目录。如果我在应用程序中使用它们来做某事,它工作正常,这意味着它们保存在目录中并且路径是正确的。我还可以在 phone.
上使用File Explorer
看到它们
但是,如果我使用 Windows Explorer
,它们将在一段时间后才会显示。
这是正常现象还是我遗漏了什么?
phone (Samsung Galaxy S6) 作为媒体设备 (MTP) 连接到 PC,但我也尝试将其作为相机 (PTP) 连接,结果是一样的。
这是我用来保存图片的示例代码:
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
String timeStamp = new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date());
String imageFileName = "MyTestPhoto_" + timeStamp;
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File mediaStorageDir = new File(SAVE_IMAGE_PATH);
if (!mediaStorageDir.exists())
mediaStorageDir.mkdir();
File pictureFile = new File(mediaStorageDir + imageFileName + ".jpg");
if (pictureFile == null){
Log.d("PictureCallback", "Error creating media file, check storage permissions.");
return;
}
try{
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
}catch (FileNotFoundException e){
Log.d("PictureCallback ", "File not found: " + e.getMessage());
}catch (IOException ex){
Log.d("PictureCallback ", "Error accessing file: " + ex.getMessage());
}
photoButton.setClickable(true);
camera.startPreview();
}
};
根据我在互联网上找到的内容,这可能会有所帮助:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse(mediaStorageDir + imageFileName + ".jpg")));
但事实并非如此,事实上应用程序现在崩溃了:
Activity com.example.testApplicationCamera.CameraActivity has leaked IntentReceiver com.example.testApplicationCamera.CameraActivity@28968130 that was originally registered here. Are you missing a call to unregisterReceiver()?
Android 4.4 KitKat 及更高版本似乎不支持此功能。 我不认为我真的需要它,因为我不想让它在画廊或任何东西中可见,它实际上工作正常,只是出于好奇,为什么它没有出现在 Windows 资源管理器中?
From what I found on the internet, this might help:
这从来都不是一个合适的解决方案,幸运的是现在已经被阻止了。
使用 MediaScannerConnection
及其静态 scanFile()
方法提醒 MediaStore
为您的文件编制索引。
why doesn't it appear in the Windows Explorer?
Windows 正在通过媒体传输协议 (MTP) 连接到 Android 设备。 Android 通过 MTP 连接提供的不是文件系统中的内容,而是 MediaStore
.