Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android intent action_send option to only once

Hi have a java with this code to create sharing intent

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "text" );
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject" );
sendIntent.setType("text/plain");

It now creates a popup of available apps and ask if you want to use the chosen app always or just once is there a setting to put it on just once and remove this 2 buttons?

Is there such a option in android like Intent.setOption('just once')?

Thanks

Android device

like image 338
jhdj Avatar asked Aug 02 '13 06:08

jhdj


People also ask

What is the use of intent createChooser () method?

createChooser(intent, title); // Try to invoke the intent. // Define what your app should do if no activity can handle the intent. This displays a dialog with a list of apps that respond to the intent passed to the createChooser() method and uses the supplied text as the dialog title.

What is setType in intent android?

Basically what it does is, it lets you set the type of data that you are using to send in an intent. You might also want to check out an existing question: Android - Intent.setType() arguments.

How can I share data between two apps on android?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.


2 Answers

Use

Intent sharingIntent = new Intent ( android.content.Intent.ACTION_SEND );
sharingIntent.setType ( "text/plain" );
sharingIntent.putExtra ( android.content.Intent.EXTRA_TEXT, body.toString () );
startActivity(Intent.createChooser(sharingIntent, "Share using?"));

Instead of

startActivity(sharingIntent);
like image 181
Ahmad Magdy Avatar answered Oct 05 '22 09:10

Ahmad Magdy


see example:

final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Some text");
Intent chooser = Intent.createChooser(sendIntent, "Share Using...");
this.cordova.startActivityForResult(this, chooser, 0);

where the important line in this context is:

Intent chooser = Intent.createChooser(sendIntent, "Share Using...");

This is a convenience technique for wrapping your intents in a "custom" chooser. Alternatively you can start with an ACTION_CHOOSER intent and add a target intent to it as EXTRA_INTENT.

like image 33
roy650 Avatar answered Oct 05 '22 10:10

roy650