Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从库中接收操作\u发送意图_Android - Fatal编程技术网

Android 从库中接收操作\u发送意图

Android 从库中接收操作\u发送意图,android,Android,我试图通过一个动作发送意图从Android Gallery接收图像。我已经设置了正确的意向过滤器,画廊将打开我的应用程序。现在我想知道如何获取图像数据。我在互联网上找不到任何这样做的例子。我想路径在intent.getData()中的某个位置,但如何从库中提取该图像?不确定发送意图,但在处理从PICK intent返回到MediaStore的照片时,它会出现如下情况: Uri selectedImage = intent.getData(); AssetFileDescripto

我试图通过一个动作发送意图从Android Gallery接收图像。我已经设置了正确的意向过滤器,画廊将打开我的应用程序。现在我想知道如何获取图像数据。我在互联网上找不到任何这样做的例子。我想路径在intent.getData()中的某个位置,但如何从库中提取该图像?

不确定发送意图,但在处理从PICK intent返回到MediaStore的照片时,它会出现如下情况:

    Uri selectedImage = intent.getData();
    AssetFileDescriptor fd = getContentResolver()
            .openAssetFileDescriptor(selectedImage, "r");
    FileInputStream s = fd.createInputStream();
    // your image data processing code here

不过要小心-您可以处理500多万像素的文件,这些文件可能相当大(特别是如果您要将它们解压缩为位图进行处理),并且您的内存非常有限。

在Picasa源代码中找到了这一点。它给出了图像的正确路径

    Intent intent = getIntent();
    if (Intent.ACTION_SEND.equals(intent.getAction())) {
        Bundle extras = intent.getExtras();
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            String scheme = uri.getScheme();
            if (scheme.equals("content")) {
                String mimeType = intent.getType();
                ContentResolver contentResolver = getContentResolver();
                Cursor cursor = contentResolver.query(uri, null, null, null, null);
                cursor.moveToFirst();
                String filePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA));

要将其放置在哪个文件中以及该文件中的什么位置。