安卓(Android) 怎么从相机结果(Camera Result)获取字符串uri

2019年10月27日20:56:45安卓(Android) 怎么从相机结果(Camera Result)获取字符串uri已关闭评论 397 902字阅读3分0秒

1.简介

安卓(Android) 怎么从相机结果(Camera Result)获取字符串uri?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.io.File;
import java.io.FileNotFoundException;
import android.app.Activity;

import android.net.Uri;
import android.os.Environment;

public class Main {
    private static String getStringUriFromCameraResult(Activity activity) {
        Uri uri = null;
        File file = getFileToStoreCameraResult();
        try {
            uri = Uri.parse(android.provider.MediaStore.Images.Media
                    .insertImage(activity.getContentResolver(),
                            file.getAbsolutePath(), null, null));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (uri != null) {
            return uri.toString();
        }
        return null;
    }

    public static File getFileToStoreCameraResult() {
        String directoryPath = Environment.getExternalStorageDirectory()
                + "/data/com.raulete.evoluzzion/tmp/";
        File directory = new File(directoryPath);
        if (!directory.exists())
            directory.mkdirs();
        String filePath = directoryPath + "camera_capture";
        File file = new File(filePath);
        return file;
    }
}

 
继续阅读
编程十万个怎么办