2011-02-05 25 views
0

ASTROファイルマネージャなどの他のギャラリー様のアプリケーションではなく、Androidのネイティブギャラリーから選択する方法を教えてください。ユーザーが複数のアプリケーションのことを持っているならば、インテント経由でAndroidネイティブギャラリーにアクセスする

activity.startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CHOOSE_IMAGE); 

:私は、このような何かを行う場合は

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
List<ResolveInfo> infos = activity.getPackageManager().queryIntentActivities(intent, 0); 

次のコードでは、画像を選択することができる活動のリストを与えます(ASTROファイルマネージャなどの)ギャラリーのように動作することができますが、そのうちの1つを選択するように促され、「デフォルトとして設定」オプションはありません。

私はユーザーにその都度選択するように求められたくないので、ネイティブギャラリーを使用したいと思います。

以下のハックのコードサンプルは、既知のネイティブのギャラリー名をテストするためのホワイトリストを使用しています。

for (ResolveInfo info : infos) { 
     if ( 0==info.activityInfo.name.compareTo("com.cooliris.media.Gallery") 
      || 0==info.activityInfo.name.compareTo("com.htc.album.CollectionsActivity") 
     ) { 
      // found the native gallery 
      doSomethingWithNativeGallery(); 
     } 
    } 

はちょっと汚い感じています。より良い方法がありますか?私は私の意図で何かを逃していると思う。

答えて

0

コードの最後の部分を取得しませんでした。私が何をしたかネイティブgallryを開始するには

がある -

public void upload(){ 
      Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); 
      photoPickerIntent.setType("image/jpg"); 
      photoPickerIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/image.jpg")); 
      startActivityForResult(photoPickerIntent, 1); 

    } 

あなたはネイティブのギャラリーを開始したいアップロード()を呼び出します。あなたはこれが動作しない

+0

を行うには好きなものを、明確な答えを得られないだろう場合

 /** * Retrieves the returned image from the Intent, inserts it into the MediaStore, which * automatically saves a thumbnail. Then assigns the thumbnail to the ImageView. * @param requestCode is the sub-activity code * @param resultCode specifies whether the activity was cancelled or not * @param intent is the data packet passed back from the sub-activity */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_CANCELED) { return; } else if(resultCode == RESULT_OK) { Uri uri = intent.getData(); String path = getPath(uri); Log.i("PATH", path); data = path; return; } uplad(); } public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } 

- - それは、から選択しない、私はやったことの画像情報を取得する

複数のインストール可能なギャラリーのようなアプリ - ASTROもインストールしてみてください。さらに、最近sdcardを直接参照するべきではなく、代わりにEnvironment.getExternalStorageDirectory()を使用してください。 –

関連する問題