Android:Problem in passing image and its URI between two activities

折月煮酒 提交于 2019-12-06 05:54:03

问题


Can we pass image and an image URI to other activity in same application using bundle?suggest me some way to do that?

USAGE :actually i have made an activity that crop an image taken from camera or from image stored in SD card depends upon the user. and another app that uses a background image and a border image both are overlay so as to see PHOTOFRAME.

So now I want to combine both app so that the cropped image come from first app should become the background image for the second app.ie comes in photoframe.How can i do that?


回答1:


Once you save your image in SD card

use this to cal the other activity.

final Intent intent = new Intent(MyClass.this, TargetClass.class);
final String root = Environment.getExternalStorageDirectory().getAbsolutePath();
intent.setData(Uri.parse(root + "/my/image/path/image.png"));
startActivity(intent);

if you are the reciever then you can get the path by calling

Uri path = getIntent().getData();

in the onCreate of the recieving activity. this is the standard way of checking for path by other activities.




回答2:


Yes you can pass URI object,see putParcelable method in http://developer.android.com/reference/android/os/Bundle.html, URI already implements Parcelable interface,you can use corresponding get methods to get it.If any object that implements Parcelable interface then we can pass it using Bundle.



来源:https://stackoverflow.com/questions/6921906/androidproblem-in-passing-image-and-its-uri-between-two-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!