Chooser is not working - android

in my app i want to display the location using map and also browsers(i need to display what are all the browser that installed in the device.) using the Chooser.please any one help me to find a solution.Thanks in advance. and also i need to set that always just once button in it.....
String format = "geo:0,0?q=" + Double.toString(latter)
+ "," + Double.toString(longer) + "(" + sender
+ ")";
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(Intent.createChooser(intent,
"Complete action using"));

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);

Use the below link as an example to implement chooser in android https://github.com/iPaulPro/aFileChooser

Related

Android: Only show email apps OR display a message to user for Intent.ACTION_SEND when attaching a file

Right now for sdk 30, I am successfully able to send and attach a json file to some email client when using ACTION_SEND. However there are two issues that I noticed when using ACTION_SEND:
it shows ALL apps, not just email apps, which is what I want
it does NOT show the intent with title/text for the user to choose an email app. I do NOT just want to use a Toast message
I think this can be solved using ACTION_SENDTO instead, but then I won't be able to attach my file, so that actually won't work.
With this said, I would like to solve either point 1 or 2 (preferably point 1), if not both.
Here is what I have:
private void sendToEmail(String emailAddress, String filePath) {
File file = new File(filePath);
file.setReadOnly();
String[] to = { emailAddress };
Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", file);
grantUriPermission("com.my.package", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setData(Uri.parse("mailto:")); // this does NOT work for the above action type
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_SUBJECT, "Your backup file");
intent.putExtra(Intent.EXTRA_TEXT, "Your data for your backup is attached to the file " + BACKUP_NAME + ".");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("message/rfc822");
// this does NOT create the below title for ACTION_SEND, as per documentation for createChooser()
Intent chooser = Intent.createChooser(intent, "Pick an email app to send attachment: " + BACKUP_NAME);
if (chooser.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
}

Text not passing to Whatsapp application using Intent

I am trying to launch whatsapp app from my app and passing some text to a particular number. Whatsapp App is launching and but text is not able to pass.
String smsNumber = "98*******3";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, textWithClickableLink);
i.setPackage("com.whatsapp");
mContext.startActivity(i);
Is there anything missing in my code?
Please help me on this.
Thanks in advance!
Try this one:
Uri uri = Uri.parse("smsto:" + mobileno);
Intent whatsappIntent = new Intent(Intent.ACTION_SENDTO, uri);
whatsappIntent.setPackage("com.whatsapp");
String str = "https://play.google.com/store/apps/details?id=com.example.activity&hl=en";
whatsappIntent.putExtra("sms_body", str);
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
// Whatsapp have not been installed
}
you can try this method, it should work. I have tested
private void shareWhatsApp() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
//if you have any images to share sue this, uri is the uri of image
//shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
//shareIntent.setType("image/*"); for image sharing
shareIntent.setType("text/plain");
shareIntent.setPackage("com.whatsapp");
startActivity(shareIntent);
}
This will launch WhatsApp application and you have to manually select the contacts and send. since they dont provide any SDK we cant send automatically.
I tried this code. It makes my app to open list of all app by which I can send messages. After selecting any app now I am able to send the message that I am attaching with intent.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "From Stockal App");
intent.putExtra(Intent.EXTRA_TEXT, text);
mContext.startActivity(intent);
Thank you all for your response.

Share intent location

I've been trying to send a location via share intent through whatsapp, my code so far:
String uri = "geo:" + currentLoc.getLatitude() + "," +currentLoc.getLongitude() + "?q=" + currentLoc.getLatitude() + "," + currentLoc.getLongitude();
Intent i=new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
The problem is that when the app chooser opens it only shows "google maps" and "waze". How do I can modify it so I can send it by many other apps that support location like whatsapp or facebook?
You need to replace android.content.Intent.ACTION_VIEW by Intent.ACTION_SEND or Intent.ACTION_SEND_MULTIPLE.
You can find the full information about sending and receiving data between apps here.
Finally, you need to open the Intent like this:
startActivity(Intent.createChooser(shareIntent, "Share via"));
instead of: startActivity(shareIntent); as explained here. This will create an dialog for user to choose which application wants to use for sharing.
EXAMPLE CODE:
String uri = "http://maps.google.com/maps?saddr=" + location.latitude + "," + location.longitude;
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, uri);
startActivity(Intent.createChooser(sharingIntent, "Share in..."));
Try to use the code below, this is an example from official documentation.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my location to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.share, menu);
MenuItem item = menu.findItem(R.id.share_item);
actionProvider = (ShareActionProvider) item.getActionProvider();
// Create the share Intent
String shareText = URL_TO_SHARE;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
actionProvider.setShareIntent(shareIntent);
return true;
}
Another option you can directly specify app to open your intent by adding package name to your intent.
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
Please, for more info check docs whatsapp and android.

ShareActionProvider - send string with link

Couldn't find the answer to my problem, so here is my question:
I have an app storing debts and where i can send the debt info to anyone using ShareActionProvider in the actionbar. It all works fine, i can send a string via, let's say, whatsapp. So far, so good. I wanted to include a link to the app in the play store at the end of the message but couldn't find out how to do it.
Here the intent I'm sending via the ShareActionProvider
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message);
i.setType("text/plain");
How can i achieve to add something like this:
Don't forget to check out this
just append the link to the end.
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=" + getPackageName());
i.setType("text/plain");
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
i.setType("text/plain");

Social sharing on mobile

On a website, one can use a social sharing javascript library like addthis in order to propose share buttons to the user without having to program everything from scratch.
Do you know any library doing the same sort of thing directly inside an android application ?
pathToPicture in previous answer is vague. It should be an Uri.
See Android docs
More elaborate example:
String path = "/mnt/sdcard/dir1/sample_1.jpg";
Intent share = new Intent(Intent.ACTION_SEND);
MimeTypeMap map = MimeTypeMap.getSingleton(); //mapping from extension to mimetype
String ext = path.substring(path.lastIndexOf('.') + 1);
String mime = map.getMimeTypeFromExtension(ext);
share.setType(mime); // might be text, sound, whatever
Uri uri = Uri.fromFile(new File(path));
share.putExtra(Intent.EXTRA_STREAM,uri);//using a string here didnt work for me
Log.d(TAG, "share " + uri + " ext:" + ext + " mime:" + mime);
startActivity(Intent.createChooser(share, "share"));
On Android we have Intents for this.
If you like to give the user an opportunity to share something, you can fire up an intent like this for example:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg") // might be text, sound, whatever
share.putExtra(Intent.EXTRA_STREAM, pathToPicture);
startActivity(Intent.createChooser(share, "share"));

Categories

Resources