Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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:图像库共享到应用程序_Android_Image_Gallery_Share - Fatal编程技术网

Android:图像库共享到应用程序

Android:图像库共享到应用程序,android,image,gallery,share,Android,Image,Gallery,Share,我有一个应用程序可以从图像库(通过共享菜单)接收图像。我的应用程序启动,我执行以下操作: Bundle bundle = getIntent().getExtras(); Object obj = bundle.get("android.intent.extra.STREAM"); 调试时,Eclipse报告对象obj的类型为'Uri@StringUri“(?)在它里面的某个地方是字符串”content://media/external/images/media/992'. 有

我有一个应用程序可以从图像库(通过共享菜单)接收图像。我的应用程序启动,我执行以下操作:

    Bundle bundle = getIntent().getExtras();
    Object obj = bundle.get("android.intent.extra.STREAM");

调试时,Eclipse报告对象obj的类型为'Uri@StringUri“(?)在它里面的某个地方是字符串”content://media/external/images/media/992'. 有人知道obj是什么类型的对象,所以我可以对它进行打字吗?那绳子是关于什么的?即,如何获取图像数据?

它属于
Uri类型,是一个通用的资源标识符

content://media/external/images/media/992
是图像的URI。要将其转换为直接文件系统路径,请将URI传递给我在本网站其他地方找到的此方法:

// Convert the image URI to the direct file system path of the image file
 public String getRealPathFromURI(Uri contentUri) {

    String [] proj={MediaStore.Images.Media.DATA};
    Cursor cursor = managedQuery( contentUri,
            proj, // Which columns to return
            null,       // WHERE clause; which rows to return (all rows)
            null,       // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();

    return cursor.getString(column_index);
 }