2

(共有メニューを介して)画像ギャラリーから画像を受け入れるアプリがあります。私のアプリが起動し、これを行います:

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

デバッグ中、Eclipseはオブジェクトobjがタイプ'Uri @ StringUri'(???)であり、その中のどこかに文字列' content:// media / external / images / media/992'があることを報告しています。誰もがオブジェクトobjのタイプを知っているので、それを型キャストできますか?そして、文字列は何についてですか?IE、画像データを取得するにはどうすればよいですか?

4

1 に答える 1

2

これは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);
 }
于 2010-10-31T02:31:42.303 に答える