Share location on android share intent - android

I want to share a location attached to my share intent. Is it possible?
Something like this, but adding location information:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "The status update text");
startActivity(Intent.createChooser(intent, "Dialog title text"));
Thanks.

You can put your location data as part of the text of the message, in EXTRA_TEXT.
Or, you are welcome to invent a new extra (e.g., EXTRA_LOCATION), put the location data in there, and then convince all the world's Android developers to use it where relevant when they implement activities that respond to ACTION_SEND.
But, beyond those two choices, ACTION_SEND does not support anything else related to location.

Related

How to share pdf with title[should not show UNTITLED]

the following code is the sharing pdf with UNTITLED.pdf
how to name the pdf
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("application/pdf");
String shareMessage= "dummy";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(targetPdf));
startActivity(Intent.createChooser(sendIntent, "dummy"));
what I should put in putextra to change the shared pdf from UNTITLTED to dummy?
The activity that handles the ACTION_SEND Intent can do what it wants. There is no way to force it to do anything, in part because there are thousands of ACTION_SEND activities, each created by a different development team. So,
Some might pay attention to your EXTRA_TEXT, and some might not, as the ACTION_SEND specification only supports either EXTRA_TEXT or EXTRA_STREAM, and you are using both
Some might look at the last path segment of the Uri and assume that it is some sort of filename; others might not
So, populate the Intent as you are, perhaps tweak the values a bit, and otherwise just live with it.

How to share a link which is not visible to user

In my android app i want to share a Link to my website using intent but i dont want it to be visible to other user
example i want to share "smoe website link"
But to user it should look like "Click me to see it".
I tried this but wasnt successfull it just shows the simple text and was not clickable
<string name="app_link">Click me!</string>
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra("PostID", postID);
intent.putExtra("UserID", userID);
intent.putExtra(android.content.Intent.EXTRA_TEXT,activity.getString(R.string.app_link);
activity.startActivity(Intent.createChooser(intent, "Share"));
Any help will be really appreciated.
What you want is not realistically possible right now.
EXTRA_TEXT must always be interpreted as plain text by the receiving app. You could try using EXTRA_HTML_TEXT which was added with API 16. But many apps don't support HTML and will simply use EXTRA_TEXT instead (or not show any text at all if you omit EXTRA_TEXT).

Sharing Content On FaceBook Android

I use intent and Action.SEND for sharing my custom message on social networks like WhatsApp , twitter, Facebook and GMail. Everything is ok on Gmail and other applications except Facebook! How can I customize my code to share something on Facebook as well? I do share on Facebook using Facebook SDK with no problem, but I want to do it using an intent.
this is what I use:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, knowTitle+"Read the full article via MomsApp by EnfaMama A+ at http://meadjohnsonasia.com.my/mobileapp");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "I just read "+knowTitle);
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent, "Share Your Favorite Article"));
What I did was actually to intercept the chosen target of the intenthandlers, you can do that by using your actionprovider. Let's say you created an item that with an onclick starts the intent. In order to do that, you can instantiate an actionprovider to do so. This actionprovider can have a setOnShareTargetSelectedListener to intercept any intents that you want to handle differently (or not at all ^^). See the code below for how to configure your actionprovider.
actionProvider.setShareIntent(createShareIntent());
actionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener(){
#Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
if ("com.facebook.katana".equals(intent.getComponent().getPackageName()) && mfacebooksharer != null) {
mfacebooksharer.shareStatus(subject, text);
return true;
}
return false;
}
});
Whenever facebook is chosen, I use my mfacebooksharer to handle the intent and follow the facebook API.
Ofcourse, that actionrpovider needs to have an intent. (Just like you wanted to work with an intent). I use the method below to create the intent.
private Intent createShareIntent() {
intentsetter.setIntentleave(true);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
return shareIntent;
}
As per the Facebook's Platform Policies, you cannot pre-fill the share dialog using
Intent.EXTRA_TEXT. It is usually thought to be a bug, but as per a Bug Report filed here and also, here, Facebook clearly mentions that this is not the case (it's not a bug).
You can read more about their Platform Policies specifically, Platform Policy IV.2
Quote from Platform Policy IV.2:
You must not pre-fill any of the fields associated with the following
products, unless the user manually generated the content earlier in
the workflow: Stream stories (user_message parameter for
Facebook.streamPublish and FB.Connect.streamPublish, and message
parameter for stream.publish), Photos (caption), Videos (description),
Notes (title and content), Links (comment), and Jabber/XMPP.
These fields are intended for users to express themselves. Pre-filling
these fields erodes the authenticity of the user voice.
The only way you can share stories from your App is by integrating the Facebook SDK, which as per your post, you are already able to successfully. That is the only option available (unfortunately).
Using Intent in Android, you can share only a link without text:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "http://www.google.ca");
startActivity(Intent.createChooser(intent, "Share with"));
It'll work. If you want to share text and link , you have to use the Facebook SDK for Android: https://github.com/facebook/facebook-android-sdk

how to get list of installed instant messenger apps?

My app should be able to send the text in a TextView via WhatsApp, Email, SMS etc. For that i need a list of installed Messging Applications. I tried it with the PackageManger but i get all apps. How can i get only the Instant Messaging Apps?
This is my code to list the installed apps:
PackageManager packageManager=this.getPackageManager();
List<PackageInfo> applist=packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it=applist.iterator();
while(it.hasNext()){
PackageInfo pk=(PackageInfo)it.next();
if(PackageManager.PERMISSION_GRANTED==(packageManager.checkPermission(Manifest.permission.INTERNET, pk.packageName)& packageManager.checkPermission(Manifest.permission.RECEIVE_SMS, pk.packageName))) //checking if the package is having INTERNET permission
{
myList.add(""+pk.applicationInfo.loadLabel(packageManager));
}
}
Supposed you manage to get the list of the apps you want, then what are you going to do with them?
I think that you need to let android to present a list of apps to your users for them to choose which application they want to handle the text, depending on the action performed. Fortunately this is a build in feature in Android. Here is my function for sending e-mails:
public static void StartEmailIntent (Context cx, String EmailAddress){
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAddress});
cx.startActivity(Intent.createChooser(email, cx.getString(R.string.dlg_sendmail_selectortitle)));
}
As you can see I am setting Intent.ACTION_SEND as the action and then with the Intent.createChooser android creates a list of applications capable to handle that action based on the type and the extras of the Intent. It shouldn't be hard to adapt other actions like SMS, Phone calls etc. You can read more about it here Sending Content to Other Apps
Hope this helps...
If you are targeting Ice Cream Sandwich you should go with the ShareActionProvider. There you get your desired list of ways to share whatever you want.
You could also read this android-developer-blogpost where they explain how to share via intent. So for example for your emailsharing:
Intent intent=new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, “Some Subject Line”);
intent.putExtra(Intent.EXTRA_TEXT, “Body of the message, woot!”);

how to add a Ymail/Gmail share button in android app?

hi friends i have a custom list coming from server and i want to add two share buttons for Gmail and Ymail resp. in that , its like when i click the Ymail share button it asks for username and password and then redirects me into the compose message section with message body as the link of the respective list and then i can access my contacts to send it to anyone i like.
1. please tell me how to do this??
2. is there any sdk available for Ymail/gmail
please suggest something..thanks in advance
to share text you don't pick the app you want to use. You pick the type of app you want to use. You can simply start an ACTION_SEND intent.
public void help() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
String s = getString(R.string.sharesubject);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, s);
startActivity(sendIntent);
}
(source: android.com)
How about a share action provider its brand new. my 1st app has a share action provider and it looks a little like this.
Basically you just fill up a share intent with the message and attach the intent to the share menu item.
search for share action provider example
Good Luck

Categories

Resources