如何将图像传递给其他有意图的活动

时间:2018-05-20 14:49:03

标签: android android-intent imageview android-camera

我有一个底栏。它有一个相机图标。当我点击图标时。它向我展示了一个对话框。该对话框有3个按钮。这些是相机请求,图库请求和取消。我带着照相机请求拍照,这是我过去的意图。然后我按下提交按钮(在模拟器默认按钮中)。但它给了我一个例外。我的目的是:我想将拍摄的照片发送给其他活动。然后将其设置为我的图像视图。我怎么能这样做?

这是我的提交按钮: enter image description here

enter image description here

我的Logcat:

05-20 15:25:01.635 2653-2653/something.about.berkay.isim E/AndroidRuntime: FATAL EXCEPTION: main
    Process: something.about.berkay.isim, PID: 2653
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data (has extras) }} to activity {something.about.berkay.isim/something.about.berkay.isim.bottom_bar}: java.lang.NullPointerException
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3365)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408)
        at android.app.ActivityThread.access$1300(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
        at something.about.berkay.isim.bottom_bar.onActivityResult(bottom_bar.java:186)
        at android.app.Activity.dispatchActivityResult(Activity.java:5423)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408) 
        at android.app.ActivityThread.access$1300(ActivityThread.java:135) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
        at dalvik.system.NativeStart.main(Native Method) 

这是我的代码:

  private static final int CAMERA_REQUEST = 1888;
   private void openCamera() {

        Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(takePicture, CAMERA_REQUEST);


        try {
           /* camera.takePicture();*/
            dialog.dismiss();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


       switch (requestCode){
           case GALLERY_REQUEST : if(resultCode == RESULT_OK){   //gallery için 1
               Uri selectedImage = data.getData();
            //   deneme.setImageURI(selectedImage);
           }break;
           case CAMERA_REQUEST : if (resultCode == RESULT_OK){

              Uri selectedImage = data.getData();
           Intent i = new Intent(bottom_bar.this , fotograf_cekildikten_sonra_kaydet_iptal_yeri.class);
           i.putExtra("dene " ,selectedImage);
         startActivity(i);



           }

       }

我的其他活动:

 setContentView(R.layout.fotograf_cekildikten_sonra_kaydet_iptal_yeri);

    Bundle extras = getIntent().getExtras();
    Uri uri = extras.getParcelableExtra("dene");
    ımageView = (ImageView)findViewById(R.id.telefon_arama_ImageView);

    ımageView.setImageResource(uri);

1 个答案:

答案 0 :(得分:2)

意图不用于传递大数据。它是您的流程(应用程序)或IPC中的消息传递机制。如果您尝试传递大数据 你可能会得到一个TransactionTooLargeException。你可以做的是你可以将照片保存到本地文件系统,然后将该照片的uri传递给 通过Intent的其他活动。以下是如何执行此操作的官方指南: photobasics