简体   繁体   English

通过意图将画廊图像传递到另一个活动

[英]passing gallery image to another activity through intent

I need to send a image from gallery to another activity by using the path of that image but nothing happened... help me out...... here is the code.. 我需要通过使用该图像的路径将图像从画廊发送到另一个活动,但是什么也没有发生……帮帮我……这是代码。

        protected void onActivityResult(int requestCode, int resultCode, Intent data)
        {
             super.onActivityResult(requestCode, resultCode, data);
           if(requestCode==RESULT_LOADIMAGE&&resultCode==RESULT_OK&&null!=data)
       {
        Uri selectedImages=data.getData();
        String[] filePathColon={MediaStore.Images.Media.DATA};
        Cursor cursr=getContentResolver().query(selectedImages, filePathColon, null, null, null);
        cursr.moveToFirst();
        int columnindex=cursr.getColumnIndex(filePathColon[0]);
        String picturepath=cursr.getString(columnindex);
        cursr.close();

    Intent  intent= new Intent(MainActivity.this,SecondActivity.class);
      intent.putExtra("imagePath",filePathColon );
        startActivity(intent);

       }
   }

and second activity code is 第二个活动代码是

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    img=(ImageView)findViewById(R.id.imageView1);


       getData();

       }

      private void getData(){
    String ps=getIntent().getStringExtra("imagepath");

    img.setImageBitmap(BitmapFactory.decodeFile(ps));

}   
intent.putExtra("imagePath",filePathColon );

should be 应该

intent.putExtra("imagePath",picturepath);

because filepathcolon refers to column index and picturepath refers to the URI 因为filepathcolon指向列索引,而picturepath指向URI

and get it using 并使用它

String ps=getIntent().getStringExtra("imagePath"); //it should be same as you send it

please change like this 请这样改变

      Intent  intent= new Intent(MainActivity.this,SecondActivity.class);
  intent.putExtra("imagePath",picturepath);
    startActivity(intent);

   }

The two strings in your Intent do not match: You wrote imagePath with capital P in the first Activity, but not in your second one. Intent中的两个字符串不匹配:您在第一个Activity中用大写P编写了imagePath,但在第二个Activity中却写不了。

String ps=getIntent().getStringExtra("imagePath");

fixes it 修复它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将捕获的图像或从图库传递到另一个活动 - Passing of captured image or from gallery to another activity 通过意图将图像网址传递给另一个活动 - Pass Image url through intent to a another activity 我已经以相同的意图从图库中获取图像到图像视图中,然后在图像视图上单击我要通过意图向该图像发送另一个活动。 - I have taken image from gallery to image view in same intent.And on image view click I want to send that image another Activity through intent. 通过Intent将数据传递到另一个活动时获取Null值 - Getting Null values while Passing datas through Intent to another activity 通过 Intent 将数据传递给另一个 Activity 时获取 Null 值 - Getting a Null value while passing data through intent to another activity 通过 Intent 传递对原始视频文件的引用并在另一个活动中使用它 - Passing a reference to a Raw video file through Intent and using it in another activity 如何将图片库从片段传递到另一个活动? - How to passing Image Gallery from fragment into another activity? 如何单击图像视图并通过意图在另一个活动中发送该图像? - How to click image view and send that image in another activity through intent? 额外数据不通过画廊意图 - Extra data is not passing through gallery intent 将意图值传递给另一个活动 - passing intent value to another activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM