8

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

jhdj
  • 631
  • 1
  • 14
  • 26
  • 1
    You can always create your own chooser dialog by filtering on `Intent`. This way, you can show whatever button(s) you want to. See: [How to pass Android intent to anyone but my own app?](http://stackoverflow.com/a/17866142/2558882). The question is about a different intent from yours, but you'll be using the same procedure. – Vikram Aug 02 '13 at 06:29
  • 1
    Sure. Take a look at this one: [Creating a custom Android Intent Chooser](http://pilcrowpipe.blogspot.ca/2012/01/creating-custom-android-intent-chooser.html). What you should know: you will be creating a popup window like any other, and populating it with content based on certain criterion. Android does the same thing for you. By the way, the answer to your question is: No. – Vikram Aug 02 '13 at 06:53
  • thanks adding Intent.createChooser() seemed to work :) – jhdj Aug 02 '13 at 06:56

3 Answers3

18

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);
Ahmad Magdy
  • 293
  • 3
  • 7
1

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.

roy650
  • 633
  • 1
  • 10
  • 18
0

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.

C B J
  • 1,838
  • 16
  • 22