I'm launching Google Maps in Android from a particular view in my app layout like this:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
view.getContext().startActivity(mapIntent);
Once I'm done with the maps and return to my app, the maps app is being launched again when I click anywhere (not just that particular view) on my app.
How do I stop this from happening?
I need maps to launch only when a particular view is displayed.
Try to call finish(); and return(); after you are starting the intent
something like this
Intent mapIntent = new Intent(Intent.ACTION.VIEW,loaction);
view.getContext().startActivity(mapIntent);
finish();
return;
Related
I have an app that makes use of the following intent in order to display a set of places on Google Map and start direction based on user choice:
Intent intent =
new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=" + Uri.encode("mykeyword") + "&z=14"));
// force to use Google maps
intent.setClassName(
"com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
The intent is started as follows:
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")));
}
The code is triggered by my app activity that is displayed on the lock screen (thanks to the android:showOnLockScreen="true" property). It means the device is locked when the intent is used.
Unfortunately, the intent requires the user to unlock the device in order to have access to the Google Map activity.
I am looking for a way to display the Activity associated with the intent without having the user to unlock his/her device.
The only solution I have for now is to reimplement what is done by the com.google.android.maps.MapsActivity in my own activity. Unfortunately, this is a lot of work just to mimic what is done with the existing Google Map intent (i.e. displaying places for a given keyword, offering a field to change the keyword, displaying suggestions list, detail view, and direction, etc. all with a good UX).
Any experiences or ideas with such a scenario are welcome.
What I got is that you want to use your app whether screen is lock or unlock like Google Map Navigation, right?
I call GooglePlay from my app through an intent and again after I kill my own app:
Intent intent = new Intent(Intent.ACTION_VIEW);
String sModule = "market://search?q=pub:mycompany";
intent.setData(Uri.parse(sModule));
startActivity(intent);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
Task manager shows, that only GooglePlay is running. My app isn't there anymore.
So my focus is GooglePlay at the moment. When going to the Desktop through the Home-Button and calling my App again it directs me to GooglePlay again.
Why is that? How can I call GooglePlay from my app independently?
I expected that when starting my app again, which I had previously killed, it would start my app and not focus on google play.
keyword is "launchMode" and "task".
this type of problems are so annoying and much complicated in android.
but this time you can try this.
Intent intent = new Intent(Intent.ACTION_VIEW);
String sModule = "market://search?q=pub:mycompany";
intent.setData(Uri.parse(sModule));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
if u cant solve, try combine another flags with FLAG_ACTIVITY_NEW_TASK.
cheers!
i am working with Google Maps navigation in my Android application ...
When calling Google Maps navigation's Intent from MainActivity Google Map Showing route path completely in my device but now when press back button from Google Maps it close whole application instead go back to MainActivity so i need to go back my MainActivity on Back pressed in Map activity...
My code for calling map activity
String strURL = new StringBuilder()
.append("http://maps.google.com/maps?saddr=")
.append(src_lat).append(",").append(src_long)
.append("&daddr=").append(dest_lat).append(",")
.append(dest_long).toString();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(strURL));
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent);
Can any one help me ??? how to catch back pressed event from Google Maps navigation's Intent ...
You should use startActivityForResult(); and make sure your activity doesn't have any propertly like singleinstance or singleTop.
How can I launch an app (3rd party app) that is installed on my phone with my own app?
I'm having several buttons in my app and when one has pressed an app that is installed should open, for example, Bank of America app. (I want to create a customized menu).
I totally new to android programming, but could it work like this? What URI string could I use or how do I figure it out? Thanks a lot!
Button b_boa = (Button) findViewById(R.id.button_boa);
b_boa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent open_boa = new Intent(Intent.ACTION_VIEW,
Uri.parse("_________"));
startActivity(open_boa);
}
});
You can launch a different app from your application on click of a button or something with the package name and if you dont know the launching activity of the application to be opened..You can use this
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
and if you know the launching activity also which you can see from the manifest file of the app to be open then use this.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);
i am developing android app to get direction between 2 location, as below
Intent intent = new Intent(android.content.Intent.ACTION_VIEW;
Uri.parse("http://maps.google.com/maps?saddr=12.84281852,80.22529753&daddr=13.00355419,80.200881958"));
startActivity(intent);
Running this application, it is prompting me to choose one among 1) Browser 2) Map
How to open it in map by default in coding??
I think if you call setPackage() with 'com.google.android.apps.maps' it should launch Google maps.
This worked fine for me:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);