You can get the launch intent through the PackageManager
class:
PackageManager pm = context.getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage("com.google.android.street");
context.startActivity(launchIntent);
Note that getLaunchIntentForPackage
returns null if the package isn't found.
So you might want to add a null check:
if (launchIntent != null) {
context.startActivity(launchIntent);
} else {
Toast.makeText(context, "StreetView not Installed", Toast.LENGTH_SHORT).show();
launchPlayStore(mContext,com.google.android.street);
}
You can use the below code to navigate him to install StreetView application via play store
public void launchPlayStore(Context context, String packageName) {
Intent intent = null;
try {
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" + packageName));
context.startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}
}
You can also open Streetview camera for clicking a panoramic image from my app with the following code
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.street", "com.google.android.street.CameraActivity"));
//provided you should know the camera activity name
startActivity(intent);
Also, you may need to add android:exported="true"
to the Activity's manifest
from which you are invoking the above code.