As we all know there are ways to share the content between the applications,
Sending and Receiving the data between two application with intent is most commonly used methodology.
Method to share text/plain
using setType function use can set type of content ex: text/plain, image/jpeg,
Share multiple pieces of content
Sending and Receiving the data between two application with intent is most commonly used methodology.
Method to share text/plain
Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.setType("text/plain"); startActivity(sendIntent);In the above case user first need to set action to send, using putExtra function one can specify the content which user would like to share with other apps,
using setType function use can set type of content ex: text/plain, image/jpeg,
Share multiple pieces of content
To share multiple pieces of data, android has given inbuilt function parcelableArraylist wherein user can form list uri and put into parcelableArraylist and can start intent to share data over other apps
ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
Sample code:
To share multiple pieces of data, android has given inbuilt function parcelableArraylist wherein user can form list uri and put into parcelableArraylist and can start intent to share data over other apps
Sample code:
0 comments:
Post a Comment