It's pretty clear to me how to share a link with the Android sharing Intent...
This is what I usually do:
final String extraText = "String 1";
final String searchUrl = "http://www.example.com?utm_source=SOURCE&utm_medium=social&utm_campaign=socialbuttons&utm_content=app_android";
final Intent intent = new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_SUBJECT, "TITLE").putExtra(Intent.EXTRA_TEXT, extraText + "\n" + searchUrl);
BUT
I would like to customize the tracking in the url for different kind of shares...
Twitter:
http://www.example.com?utm_source=TWITTER&utm_medium=social&utm_campaign=socialbuttons&utm_content=app_android
Facebook:
http://www.example.com?utm_source=FACEBOOK&utm_medium=social&utm_campaign=socialbuttons&utm_content=app_android
Etc...
Is it possible? How can I do it?
Related
I have a application where I want to show different locations (one at the time, picked by user input) by launching Google Maps with their specific geo coordinates.
I'm currently using this (with real lat. and long. values of course):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?z=17"));
startActivity(intent);
It's quite exactly what I want, except that it doesn't show any indicator or marker for the specified point. It only centers at it's location.
Is there some way to get the marker or something else included without using a MapView?
Try this:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.
There are many more options to launch a Google map using an intent...
Double myLatitude = 44.433106;
Double myLongitude = 26.103687;
String labelLocation = "Jorgesys # Bucharest";
1)
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<" + myLatitude + ">,<" + myLongitude + ">?q=<" + myLatitude + ">,<" + myLongitude + ">(" + labelLocation + ")"));
startActivity(intent);
2)
String urlAddress = "http://maps.google.com/maps?q="+ myLatitude +"," + myLongitude +"("+ labelLocation + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
3)
String urlAddress = "http://maps.googleapis.com/maps/api/streetview?size=500x500&location=" + myLatitude + "," + myLongitude + "&fov=90&heading=235&pitch=10&sensor=false";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
The accepted answer is correct, except when your label has an ampersand (&) in it.
Looking at A Uniform Resource Identifier for Geographic Locations ('geo' URI):
Section 5.1 states:
if the final URI is to include a 'query' component, add the
component delimiter "?" to the end of the result, followed by the
encoded query string.
Unfortunately for us, doing this will also escape the '=' which is not what we want.
We should do this:
String label = "Cinnamon & Toast";
String uriBegin = "geo:12,34";
String query = "12,34(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery;
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
This string works well for me:
String geoUriString="geo:"+lat+","+lon+"?q=("+head+")#"+lat+","+lon;
Uri geoUri = Uri.parse(geoUriString);
Log.e(TAG, "String: "+geoUriString);
Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);
Try appending (LocationMarkerName) to the geo: uri. For example, "geo:,?z=17(LocationMarkerName)"
In Google Maps on Android searching for 23.0980,30.6797 (NamedMarker), it seems to centre the map and position a marker with name NamedMarker at that position.
I just confirmed the following snippet from #Kenton Price still works on Android 4.4 (KitKat):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
I have only used Overlays with the MapView for drawing markers on top of a map. If your view is showing your map, it might be possible to simply draw your marker at the centre of the screen, in the same way as you would draw any image on a View.
However, the marker wouldn't be linked to the actual map coordinates, but if it's just a static view, then this might do.
My code is as follows:
/** Called when the user clicks the Get My Image button */
final String baseUrl = "http://examplewebsite.com/";
Button viewimagebutton = null
viewimagebutton = (Button) findViewById(R.id.imagegetter);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
EditText editText1 = (EditText) findViewById(R.id.pixelw);
EditText editText2 = (EditText) findViewById(R.id.pixelh);
EditText editText3 = (EditText) findViewById(R.id.pixels);
String url = baseUrl + editText1.getText().toString() + "/"
+ editText2.getText().toString() + "/"
+ editText3.getText().toString() + "/";
Intent i = new Intent(Intent.ACTION_VIEW , Uri.parse(url));
startActivity(i);
}});
// Do something in response to button
}
However on the line
viewimagebutton = (Button) findViewById(R.id.imagegetter);
I get quite an error which has a few syntax suggestions. I have followed what people have said here, but I am at a loss right now. If you need more info feel free to ask
Totally possible. You haven't stated how the user inputs the 3 inputs. I've assumed 3 different EditText fields you've defined earlier.
If so it would look something like this.
final String baseUrl = "http://examplewebsite.com/";
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String url = baseUrl + editText1.getText().toString() + "/"
+ editText2.getText().toString() + "/"
+ editText3.getText().toString() + "/"
Intent i = new Intent(Intent.ACTION_VIEW , Uri.parse(url));
startActivity(i);
}});
When the user clicks on the button, they'll be directed to the url which is made up of the base url + the inputs of the 3 EditText fields.
As Ken pointed out (unfortunately I don't have enough rep to reply yet) it's just concatenating strings.
If you think the parameter list may grow in the future, an iterative handle may be better and pass the params in as a List or array. Whatever you feel most appropriate.
But also consider using the URL object if this is for the purpose of a web-service. It allows some controlled manipulation:
http://developer.android.com/reference/java/net/URL.html
Apologies if it is irrelevant, I used it for communication with a web-service during my project so it's all I've had experience with so far.
N.B. And also whack some validation on them fields if you're directly reading them in from the onClick action! :)
In my application, when I click on a place, I would like to fire the Intent Chooser that would let the user play with GPS coordinates...
I would like the intent to let the user have the choice between Google Maps, Navigation, StreetView, or any installed GPS....
So far, each one of these apps can be launched with a different intent.. like:
Navigation:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" +mLat+","+mLong));
Google Earth:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:"
+ "?q="
+ e.latitude
+ ","
+ e.longitude)));
Google Maps:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:"
+ e.latitude
+ ","
+ e.longitude
+ "?q="
+ e.latitude
+ ","
+ e.longitude)));
StreetView:
Something different
Navigon:
<action android:name="android.intent.action.navigon.START_PUBLIC" />
Location coordinates.
String INTENT_EXTRA_KEY_LATITUDE = "latitude";
String INTENT_EXTRA_KEY_LONGITUDE = "longitude";
Any GPS app:
Is there a way to use a single intent for all these apps and let the user choose?
Is there a way to use a single intent for all these apps and let the user choose?
Presumably not. You are welcome to use PackageManager and queryIntentActivities() to build your own chooser that combines the results of various Intent objects.
I have a application where I want to show different locations (one at the time, picked by user input) by launching Google Maps with their specific geo coordinates.
I'm currently using this (with real lat. and long. values of course):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?z=17"));
startActivity(intent);
It's quite exactly what I want, except that it doesn't show any indicator or marker for the specified point. It only centers at it's location.
Is there some way to get the marker or something else included without using a MapView?
Try this:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.
There are many more options to launch a Google map using an intent...
Double myLatitude = 44.433106;
Double myLongitude = 26.103687;
String labelLocation = "Jorgesys # Bucharest";
1)
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<" + myLatitude + ">,<" + myLongitude + ">?q=<" + myLatitude + ">,<" + myLongitude + ">(" + labelLocation + ")"));
startActivity(intent);
2)
String urlAddress = "http://maps.google.com/maps?q="+ myLatitude +"," + myLongitude +"("+ labelLocation + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
3)
String urlAddress = "http://maps.googleapis.com/maps/api/streetview?size=500x500&location=" + myLatitude + "," + myLongitude + "&fov=90&heading=235&pitch=10&sensor=false";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
The accepted answer is correct, except when your label has an ampersand (&) in it.
Looking at A Uniform Resource Identifier for Geographic Locations ('geo' URI):
Section 5.1 states:
if the final URI is to include a 'query' component, add the
component delimiter "?" to the end of the result, followed by the
encoded query string.
Unfortunately for us, doing this will also escape the '=' which is not what we want.
We should do this:
String label = "Cinnamon & Toast";
String uriBegin = "geo:12,34";
String query = "12,34(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery;
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
This string works well for me:
String geoUriString="geo:"+lat+","+lon+"?q=("+head+")#"+lat+","+lon;
Uri geoUri = Uri.parse(geoUriString);
Log.e(TAG, "String: "+geoUriString);
Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);
Try appending (LocationMarkerName) to the geo: uri. For example, "geo:,?z=17(LocationMarkerName)"
In Google Maps on Android searching for 23.0980,30.6797 (NamedMarker), it seems to centre the map and position a marker with name NamedMarker at that position.
I just confirmed the following snippet from #Kenton Price still works on Android 4.4 (KitKat):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
I have only used Overlays with the MapView for drawing markers on top of a map. If your view is showing your map, it might be possible to simply draw your marker at the centre of the screen, in the same way as you would draw any image on a View.
However, the marker wouldn't be linked to the actual map coordinates, but if it's just a static view, then this might do.
friend's,
I am working in Facebook,here i need to change the image url value string has dynamic one,
here my code
intent
.putExtra(
"attachment",
"{\"name\":\""
+ Html.fromHtml(title)
+ "\",\"href\":\""
+ Html.fromHtml(url_val)
+ "\",\"description\":\""
+ Html.fromHtml(desc_val)
+ "\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.naicu.edu/imgLib/20070913_small_seal.jpg\",\"href\":\"http://alumni.brown.edu/\"}]}");
this.startActivityForResult(intent, MESSAGEPUBLISHED);
here image source given in code has static,but i need to assign an simple string variable in the place of double quoted image url,for example
i want to place string temp_url in the place of **src\":\"http://www.naicu.edu/imgLib/20070913_small_seal.jpg**,how can i get it.
Thanks in advance.