2012-04-30 7 views
0

ギャラリーから画像をAndroidアプリケーションに取り込む方法は?モバイルギャラリーから画像をAndroidアプリケーションに取り込む方法

私のギャラリーから画像をブラウズして、自分のアプリを選択する必要があります。できますか?

+0

このページの右側にある[関連する] Q&Aを見てください。あなたの質問に対処する方法がいくつかあります。 –

答えて

0

あなたはギャラリー(よく「ギャラリー」)の意図を使用する必要があります。

あなたがここでのコード例を見つけることができます

は(私はそれを行っていないが、それは動作しますように見えます): http://www.androidsnippets.com/get-file-path-of-gallery-image

0

使用このコード:

fromGalleryButton.setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 
          //takePhotoFromGallery = true;// edited 

          Intent intent = new Intent(); 
          intent.setType("image/*"); 
          intent.setAction(Intent.ACTION_GET_CONTENT);// 

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

         } 
        }); 

そして、これを追加します。

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
     super.onActivityResult(requestCode, resultCode, data);  
     if (requestCode == 10 && resultCode == Activity.RESULT_OK) {    
      Uri contentUri = data.getData();   
      String[] proj = { MediaStore.Images.Media.DATA };   
      Cursor cursor = managedQuery(contentUri, proj, null, null, null);   
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);   
      cursor.moveToFirst();   
      imagePath = cursor.getString(column_index);   

      tempBitmap = BitmapFactory.decodeFile(imagePath); // this is your image 

     } 
} 
関連する問題