start google hangouts in android - android

I want to start a new hangout conversation with given people, but I can't find any code for it. Is there any easy solution to do this?
I tryed to make skype call, and it worked easyly with an intent.
Here is the skype code:
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + nickname));
startActivity(sky);
I want something similar to this.
(Or with skype how can I make a conference call? )

There is currently no way to create a Google+ hangout on an android device using an intent or any other API.
This would be a pretty cool feature, though. If you request it, they might add it.

I think I found the solution, it's quite simple, here is the code:
Intent sky = new Intent("android.intent.action.VIEW", Uri.parse("https://talkgadget.google.com/hangouts/extras/talk.google.com/myhangout"));
startActivity(sky);
You just need to give the url of the hangout, but unfortunately google suspended the named hangots, so this url every time changes. :(

public static void sendHangout(Context ctx, String message, String urlShare, String imgPath){
Intent hangouts = new Intent(Intent.ACTION_SEND);
if(!Utilities.isNullorEmpty(imgPath)){
String file = (String)imgPath.subSequence(0, imgPath.lastIndexOf("/") + 1) + message.replace(" ", "").replace(":", "").replace(".", "")
.replace("/", "") + ".jpeg";
Utilities.copyFile(imgPath, file);
hangouts.setType("image/*");
hangouts.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + file));
}
hangouts.setPackage("com.google.android.talk");
hangouts.setType("text/plain");
hangouts.putExtra(Intent.EXTRA_TEXT, message + ": \n" + urlShare);
ctx.startActivity(Intent.createChooser(hangouts, "Hangouts is not installed."));
}
I hope help you.

Intent i = context.getPackageManager().getLaunchIntentForPackage("com.google.android.talk");
context.startActivity(i);

Related

Chooser Intent that checks if there is a default app

Since Waze and Google Maps have different URI formats, I need to create two separate intents in order to make sure that apps will navigate user to the correct location.
The main problem: I don't want to make user select navigation app every time. I want it to behave like this: if user has default navigation app set - use it without asking.
How to have two URIs for separate apps but still have the same interface just like when starting intent with ACTION_VIEW parameter?
This is my code that I am working with. Currently navigation works fine, but user is being asked every time to select navigation app:
if (!StringUtils.isEmpty(address)) {
String q = address + "&mode=d&navigate=yes&geo=" + address + "&ll=" + address;
String urlWaze = "https://waze.com/ul?q=" + q;
Intent wazeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlWaze));
String urlGoogle = "google.navigation:q=" + q;
Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGoogle));
googleMapsIntent.setPackage("com.google.android.apps.maps");
String title = getActivity().getResources().getString(R.string.choose_navigation_app);
Intent chooserIntent = Intent.createChooser(wazeIntent, title);
Intent[] arr = new Intent[1];
arr[0] = googleMapsIntent;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
getContext().startActivity(chooserIntent);
} else {
Toast.makeText(getContext(), getString(R.string.waypoint_not_have_geolocation), Toast.LENGTH_SHORT).show();
}
As it turns out Waze and Google Maps have very different URIs and in ordet to resolve situation that I descibed in my question, the only solution was to create separate user-settings in my application.

Android intent for opening both Waze and Google maps

There are a few similar posts but I couldn't find an exact one. basically, I want to open both Google maps and Waze with the same intent. At first I tried this:
final String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Waze navigated directly to the right location and Google maps opened the right place. then I realized that Google maps doesn't put a pin on the location so it's hard for the user to know where it is exactly. So I looked around and realized that Google maps requires the "?q=..(label)" for that... I changed the uri construction to:
final String uri = String.format(Locale.ENGLISH, "geo:%f,%f?q=%f,%f (%s)", latitude, longitude, latitude, longitude, name);
But then Waze did 2 things: navigated to the right place AND run a search on the label. This required the user to click the back button to close the search results screen and remain with the navigation to the right place.
I looked everywhere for an answer but failed to find a solution that will achieve both.
At first I thought that it's not possible and Waze has a bug... but then I noticed that Facebook messenger is doing exactly what I want. when clicking on a message with a location it will open both apps: Google maps will have a pin (with a label) and Waze will navigate straight to that location without running a search.
Few questions about the above:
1. (Of course) How can I achieve that?
2. How can I know how the Facebook messenger's intent being built? (Can I catch it in anyway)
3. What's the reason behind having the label only with the "?q=.."?
Thanks
Never mind. I was able to intercept the Facebook messenger with the below app and figured that the URI should be as follows:
String.format(Locale.ENGLISH, "geo:0,0?q=") + android.net.Uri.encode(String.format("%s#%f,%f", label, latitude, longitude), "UTF-8");
The app:
https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept&feature=search_result#?t=W251bGwsMSwyLDEsInVrLmNvLmFzaHRvbmJyc2MuYW5kcm9pZC5pbnRlbnRpbnRlcmNlcHQiXQ..
Thanks
Following Nimrod's tip I've installed the app and intercepted the intent from whatsapp's location feature. Here's the full Intent tested on maps and waze:
String uri = "http://maps.google.com/maps?q=loc:"+latitude+","+longitude+" ("+label+")";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
intent.setData(Uri.parse(uri));
startActivity(intent);
My final solution for opening both Waze & GoogleMap applications to get direction ( works like a charm ) :
String uri = "";
Intent intent;
try {
uri = String.format(Locale.ENGLISH,"geo:" + location.getLat() + "," +location.getLng() + "?q=" + location.getLat()+","+location.getLng()+" ("+location.getName()+")");
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException ex) {
try {
Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(unrestrictedIntent);
} catch (ActivityNotFoundException innerEx) {
getSnackbar(getResources().getString(R.string.map_install_application), Snackbar.LENGTH_LONG).show();
}
}
I had the same problem - wanted the navigation app (whatever it is) to show a pin (preferably with a custom label) and be ready to navigate the user there. However, having a label in the query resulted in some apps running a search or (worse) assuming the closest address match to the label and showing that as the destination (ignoring the coordinates). So, to achieve a reliable behaviour I had to forget having a named label and ended up with the following:
final String geoIntentData = "geo:" + latitude + "," + longitude + "?q=" + latitude + "," + longitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(geoIntentData));
So far it works in all apps I tested (Google Maps, Waze, Sygic, Moovit and even Komoot and Windy Maps). Please let me know if you try this solution and it doesn't work in another app!

How to use Uri.parse() with # at the end

I try to use GSM codes to transfer my calls with an android app.
For example, if I call : **21*otherNumber#
All my calls will be transfered on otherNumber.
My code:
Uri transfert = Uri.parse( "tel:**21*" + numero + "#");
Intent intent = new Intent( Intent.ACTION_CALL, transfert );
startActivity(intent);
However, Uri.parse() has for definition:
" A URI reference includes a URI and a fragment, the component of the URI following a '#' "
So, it removes the # but I need it. The GSM code can't works without it.
Somebody would have an idea ?
I don't think you can't dial phone number with extensions, it's a known issue (see this).
According to this thread, you may try to add %23 like Uri.parse( "tel:**21*" + numero + "%23");
You need to send a URI encoded hash to parse it through the URI.
public static final String encodedHash = Uri.encode("#");
It will keep the URI encoded hash and send the USSD message over GSM as you have specified.

Pre-populated recipient in Android email?

I am making an application where the user will click on contact us section and it will open the built-in Gmail application and I have the code to pre-populate the subject and message body in the mail.
I want the code to pre-populate the "To: " section where we add the recipient.
That didn't work for me but this did
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?to="+emailaddress+"&subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
Hope this helps someone else out there
In the intent you use to populate the subject and message, add the following:
intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "youremail#domain.com" });
Check the documentation for EXTRA_EMAIL

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