Android的 - 如何从节约手机上停止摄像的意图 [英] Android - How to stop camera intent from saving on the phone

查看:148
本文介绍了Android的 - 如何从节约手机上停止摄像的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我使用的是手机的摄像头和保存在SD卡上的图像。的问题是,图像也被保存在移动电话存储器中。有什么办法,我不能停止?

On my app I'm using the mobile phones camera and saving the image on the sd card. The issue is that the picture is also being saved on the mobile phones memory. Is there any way I cant stop this?

这是code键启动相机意图:

This is the code to start the camera intent:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(cameraIntent, CAMERA_REQUEST);

这是code保存图片到SD卡:

This is the code to save the image to the sd card:

String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/wardrobe_app");    
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-"+ n +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }
    file_path = myDir.toString();
    img_path = file_path + "/" + fname;
    Toast t = Toast.makeText(addClothing.this,
            img_path, Toast.LENGTH_LONG);
    t.show();

这是code设置为拍摄的照片的ImageView的:

And this is code to set an ImageView as the picture taken:

if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        photo = (Bitmap) data.getExtras().get("data");
        iv1.setImageBitmap(photo);
        SaveImage(photo);
    }

感谢您的帮助!

推荐答案

不幸的是,我认为这是不可能的没有根,至少意图。您code是不是问题;这是由于在相机应用如何工作 - 当用户拍照时,相机应用程序本身会保存图片的设备内存,并返回一个位图。因此,这是完全失控的,除非你有根,可以使用反射来修改相机应用到prevent省电。

Unfortunately, I believe this is impossible without root, at least with intents. Your code isn't the issue; it's due to how the camera app works - when the user takes a picture, the camera app itself will save that picture to the device memory and return a Bitmap. So this is entirely out of your control unless you have root and can use reflection to modify the camera app to prevent saving.

另一种选择是使用摄像头API直接在您的应用程序。

The other option is to use the Camera API in your app directly.

这篇关于Android的 - 如何从节约手机上停止摄像的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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