【问题标题】:Android: Image gallery share to appAndroid:图片库共享到应用程序
【发布时间】:2010-10-30 23:49:21
【问题描述】:

我有一个应用程序可以接受图片库中的图片(通过共享菜单)。我的应用程序启动,我这样做:

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

在调试时,Eclipse 报告对象 obj 的类型为“Uri@StringUri”(???),其中某处是字符串“content://media/external/images/media/992”。有人知道 obj 是什么类型的对象,所以我可以对它进行类型转换吗?字符串是关于什么的? IE,如何获取图片数据?

【问题讨论】:

    标签: android image gallery share


    【解决方案1】:

    它的类型为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);
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      相关资源
      最近更新 更多