Home » Android » android intent action_send option to only once

android intent action_send option to only once

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&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);

Answer:

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.

Answer:

You can build a list of applications that can handle the intent in your application and present the list in your own dialog, in that case you might not want to have any buttons, just send the intent to that application when the user touches it.