Reputation: 13
I'm trying to get the Longitude and Latitude and Intent user to the map but I get an error, I've searched in Stack and my method are exactly the same as other people, but I get crash when I call startActivity(intent) method.
here's my code:
public void routReq(View view) {
if(saloon.getEntity_address() != null) {
String uri = "http://maps.google.com/maps?q=loc: " + saloon.getEntity_address().getLatitude()+","+saloon.getEntity_address().getLongitude()+"&mode=d";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
} else {
Snackbar.make(view, "there's no map for this place!", Snackbar.LENGTH_LONG).show();
}
}
and this is the cause android studio gave me:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.apps.maps/com.google.android.maps.MapsActivity}; have you declared this activity in your AndroidManifest.xml?
which I did declare in Manifest.
<activity
android:theme="@style/viewSaloneTheme"
android:name="ir.drax.beautyTime.Activities.ViewSalon"
android:screenOrientation="portrait" />
and also:
Caused by: java.lang.reflect.InvocationTargetException
Upvotes: 1
Views: 588
Reputation: 3673
You are getting ActivityNotFoundException
, simply because the defined activity
is not found in defined package by your intent. So, instead of using setClassName
as,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Use setPackageName
. as,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
So, GoogleMap
internally handle your intent(in it's defined activity). It will work.
Upvotes: 1