I want to open Google Street View Android directly from my app. Can anyone help me in doing this?
I have successfully opened the Maps app with Streeview thanks to SO but that's not what I am looking for.
I actually want to open Streetview camera directly from my app so I can take a panoramic photo.
My actual task is to develop a camera app that can take panoramic images but I couldn't find anything for that, So I am working on things can be done instead of camera app like cardboard. Here is the link to the question that I had asked earlier- App to capture 360 View android
Please help in this!
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.