自定义相机拍摄的照片都没有显示在Windows资源管理器 [英] Custom camera photos are not showing in Windows Explorer

查看:175
本文介绍了自定义相机拍摄的照片都没有显示在Windows资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照如何创建一个自定义的摄像头应用程序在Android的网站上的说明,到目前为止,我做到了。我创建了一个拍照按钮的布局,它工作正常,图像保存在SD卡使用 Camera.PictureCallback

的事情是,当我有我的手机连接到PC用电缆,如果我浏览到我保存图像从应用程序的目录,它们没有显示,即使我刷新目录。如果我使用他们的东西的应用程序,它工作正常,这意味着它们被保存在目录和路径是正确的。我也可以看到他们使用文件浏览器的电话。

不过,如果我使用 Windows资源管理器,它们没有显示在所有的,直到一段时间通过。

这是正常的还是我失去了一些东西呢?

的电话(三星Galaxy S6)被连接到PC作为媒体设备(MTP),但我还试图将其连接为一个摄像机(PTP),它是相同的。

这是我用来保存图像样品code:

 私人Camera.PictureCallback mPicture =新Camera.PictureCallback(){

    字符串的timeStamp =新的SimpleDateFormat(年月日HHMMSS)格式(新的Date())。
    字符串映像文件名称=MyTestPhoto_+的timeStamp;

    @覆盖
    公共无效onPictureTaken(byte []的数据,摄像头摄像头){
        文件mediaStorageDir =新的文件(SAVE_IMAGE_PATH);

        如果(!mediaStorageDir.exists())
            mediaStorageDir.mkdir();

            文件PictureFile的=新的文件(mediaStorageDir +映像文件名称+.JPG);
            如果(PictureFile的== NULL){
                Log.d(PictureCallback,错误创建的媒体文件,检查存储的权限。);
                返回;
            }

            尝试{
                FileOutputStream中FOS =新的FileOutputStream(PictureFile的);
                fos.write(数据);
                fos.close();
            }赶上(FileNotFoundException异常E){
                Log.d(PictureCallback,找不到文件:+ e.getMessage());
            }赶上(IOException异常前){
                Log.d(PictureCallback,访问文件时出错:+ ex.getMessage());
            }

            photoButton.setClickable(真正的);
            camera.start preVIEW();
        }
 };
 

从我发现在互联网上,这可能帮助:

  sendBroadcast(新意图(Intent.ACTION_MEDIA_MOUNTED,
                    Uri.parse(mediaStorageDir +映像文件名称+.JPG)));
 

不过,这并不,而事实上现在的应用程序崩溃:

  

活动com.example.testApplicationCamera.CameraActivity已泄露   IntentReceiver com.example.testApplicationCamera.CameraActivity$1@28968130   最初这里注册。是否缺少调用   unregisterReceiver()?

看起来这是不支持在Android 4.4奇巧及以上。 我不认为我真的需要它,因为我并不想使它在画廊或任何可见的,它实际上工作得很好,只是出于好奇,为何它没有出现在Windows资源管理器?

解决方案
  

从我发现在互联网上,这可能帮助:

这是从来没有一个妥善的解决办法,并幸运的是现在已被封锁。

使用 MediaScannerConnection 和它的静态 SCANFILE()的方法来提醒 MediaStore 索引文件。

  

为何它没有出现在Windows资源管理器?

Windows正在通过媒体传输协议(MTP)连接到Android设备。安卓是什么在MTP连接提供了没有什么是文件系统,而是什么是 MediaStore 索引。

I've followed the instructions on android's website on how to create a custom camera application and so far i made it. I've created a layout with a take a picture button and it works fine, the images are saved on the sdcard using the Camera.PictureCallback.

The thing is that while I have my phone connected to the PC with a cable, if I browse to the directory where I save the images from the app, they are not showing, even if I refresh the directory. If I use them in the app for something, it works fine, which means that they are saved in the directory and the path is correct. I can also see them using a File Explorer on the phone.

However, if I use the Windows Explorer, they aren't showing at all until some time passes.

Is that normal or am I missing something here?

The phone (Samsung Galaxy S6) is connected to the PC as a Media Device (MTP) but I also tried connecting it as a Camera (PTP) and it is the same.

This is the sample code that I use to save the images:

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();
        }
 };

From what I found on the internet, this might help:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                    Uri.parse(mediaStorageDir + imageFileName + ".jpg")));

But it doesn't, and in fact the app crashes now:

Activity com.example.testApplicationCamera.CameraActivity has leaked IntentReceiver com.example.testApplicationCamera.CameraActivity$1@28968130 that was originally registered here. Are you missing a call to unregisterReceiver()?

It seems like this isn't supported on Android 4.4 KitKat and above. I don't think that I actually need it, because I am not trying to make it visible in a gallery or anything, it actually works fine, just out of curiosity, why doesn't it appear in the Windows Explorer?

解决方案

From what I found on the internet, this might help:

That was never a proper solution and fortunately has been blocked now.

Use MediaScannerConnection and its static scanFile() method to alert the MediaStore to index your files.

why doesn't it appear in the Windows Explorer?

Windows is connecting to the Android device via the Media Transfer Protocol (MTP). What Android serves up over the MTP connection is not what is in the filesystem, but rather what is indexed by MediaStore.

这篇关于自定义相机拍摄的照片都没有显示在Windows资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆