外部アプリから画像を選択し、自分のアプリで利用する方法
対象アプリの起動。
Intent.setActionにACTION_GET_CONTENTを渡す。setTypeで画像をリクエスト。
public void onClick(View view){ if(view.getId() == R.id.selecter){ Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, 1); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == Activity.RESULT_OK && requestCode == 1){ Uri uri = (Uri)data.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri); ImageView layout = (ImageView)findViewById(R.id.drawabletest_imagebox); layout.setImageBitmap(bitmap); } catch (IOException e) { //TODO 例外処理 } } }