åºæ¬ï¼ã¤ã³ãã³ãã§ã«ã¡ã©ãå¼ã³åºãæ¹æ³
以ä¸ã®ã¤ã³ãã³ãã使ãã¨æ¨æºã®ã«ã¡ã©ã¢ããªãå¼ã³åºããã¨ãã§ãã¾ãã
public void onBasicClick(View view) { Intent intent = new Intent(); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 1); }
ã¡ãªã¿ã«ãMediaStore.ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE" ã«å¯¾å¿ããã«ã¡ã©ã¢ããªï¼Camera 360ãªã©ï¼ãã¤ã³ã¹ãã¼ã«ããã¦ããã°é¸æãã¤ã¢ãã°ã表示ããã¾ãã
æ®å½±ãããç»åãã¼ã¿ã¯ä»¥ä¸ã®ããã«åãåãã¾ãã
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); }
ãã ããããã¦åå¾ã§ãã Bitmap ã¯ãµã¤ãºãé常ã«å°ããã®ã§ä½¿ãç©ã«ãªãã¾ããã
ããã«ãdata.getData() ã§åå¾ã§ããUriãªãã¸ã§ã¯ã㯠null ã§ãã
æ®å½±ããã解å度ã®ç»åãã¼ã¿ãåå¾ããæ¹æ³
以ä¸ã®ããã« MediaStore.EXTRA_OUTPUT ã« Uri ãªãã¸ã§ã¯ããæå®ãã¾ããUri ãªãã¸ã§ã¯ãã¯ã³ã³ãã³ããããã¤ãã«äºã insert ãã¦ç¢ºä¿ãã¦ããã¾ãã
private Uri mImageUri; // ã¤ã³ã¹ã¿ã³ã¹å¤æ° public void onExtraClick(View view) { String filename = System.currentTimeMillis() + ".jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, filename); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); mImageUri = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); startActivityForResult(intent, 2); }
æ®å½±å¾ã¯ãMediaStore.EXTRA_OUTPUT ã§æå®ãã mImageUri ã«ç»åãã¼ã¿ãæ¸ãè¾¼ã¾ãã¦ããã®ã§ãmImageUri ãåç §ããã ãã§ãããã ããæ®å½±ããã解å度ã®ã¾ã¾ã®ç»åãã¼ã¿ãªã®ã§ãæ®å½±ãµã¤ãºã«ãã£ã¦ã¯ç»åãµã¤ãºãé常ã«å¤§ããå ´åããããã¨ãæ³å®ããªããã°ããã¾ããã
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 2) { // ImageViewã«è¡¨ç¤ºãããªã ImageView imageView = (ImageView) findViewById(R.id.main_image); imageView.setImageURI(mImageUri); }
ã¡ãªã¿ã«ããã®æ¹æ³ã§ã data.getData() ã§åå¾ã§ããUriãªãã¸ã§ã¯ã㯠null ã§ãã
ãã¦ãããã¾ã§ã®èª¬æ㯠Android SDK開発のレシピ ã«æ¸ããã®ã§ããã®è¾ºã«ãã¦ãããããæ¬é¡ã
Xperia 2.1 ã®å ´å
åç½®ããé·ããªãã¾ããã Xperia 2.1 ã®å ´åã¯ãä¸è¨ã® MediaStore.EXTRA_OUTPUT ã§æå®ãã mImageUri ã«ç»åãã¼ã¿ãæ¸ãè¾¼ã¾ãã¾ããã
ãªã®ã§ãä¸è¨ã®ããã«ImageViewã«è¡¨ç¤ºãããã¨ãã¦ã表示ã§ãã¾ããã
ã§ã¯ãã©ããããï¼ Xperia 2.1 ã§ã¯ãdata.getData() ã§åå¾ã§ãã Uri ãªãã¸ã§ã¯ãã«æ®å½±ãããç»åãã¼ã¿ãæ¸ãè¾¼ã¾ãã¾ãã
ãã¾ã¾ã§ããã£ã¨nullã ã£ãã®ã«ï¼
ããããã®å¤ã¯ãããªæã
mImageUri: content://media/external/images/media/355 data.getData(): content://media/external/images/media/356
èªåçã«ã³ã³ãã³ããããã¤ãã« insert ãã¦ãããã¿ããã§ãããã¡ãããã¼ãåªãããã
ã¨ãããã¨ã§ãXperia 2.1 ã®å ´åã¯ãäºã insert ã¯ãããªãã¦ããã§ãããããã以ä¸ã®ããã«ã´ãã«ãªãã®ã§ insert ããªãæ¹ãããã§ãã
ããã¾ã§åå ã¨äºè±¡ãåããã°è²ã ãªå¯¾å¦ãã§ããã¨æãã¾ãããBuild.Model ã¨ï¼ã¢ãããã¼ããã¦ãªãXperiaã«ã対å¿ããããã«ï¼ Build.VERSION ãè¦ã¦ãXperia 2.1 ã ã£ãããäºã insert ããªã対å¦ãããããç§ã¯ã端æ«ä¾åãã³ã¼ãã«æã¡è¾¼ãã®ãå«ã ã£ãã®ã§data.getData() ã null ã§ã¯ãªãã¦ãmImageUri ã®ãã¼ã¿ã 0 ãã¤ãã ã£ãããã³ãã¼ããï¼æ¸ãè¾¼ãï¼ããã«ãã¾ãããåãäºè±¡ã®ç«¯æ«ã«ã対å¿ã§ãããã¨ã«æå¾ ãã¦ã
ãã¦ãéæ²³SãIS03ãªã©ä»å¾ã®Android端æ«ã¯ãã©ã¡ãã®æåããããã§ãããããä»ãã楽ãã¿ã§ããï¼ãï¼ï¼