0

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!

Rajat Porwal
  • 101
  • 8

2 Answers2

1

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.

Akshay Katariya
  • 1,464
  • 9
  • 20
  • Thanks, man It works like charm! Can u pls help me with one more thing- I want to send the user to play store if Streetview is not installed? or some link where I can learn more about using Streetview actually I want to directly open Streetview camera for clicking a panoramic image from my app. Meanwhile, I accept your answer. thanks – Rajat Porwal Mar 14 '18 at 11:20
  • you can easily navigate the user to play store if StreetView is not installed via `intent` and you can also open the camera activity for clicking pictures as well try searching for open custom activity via intent – Akshay Katariya Mar 14 '18 at 11:27
  • check my edited answer i know its long but you can achieve what you want – Akshay Katariya Mar 14 '18 at 11:46
  • intent.setComponent(new ComponentName("com.google.android.street", "com.google.android.street.CameraActivity")); this doesn't work? App crashes with ** "have you declared this activity in your AndroidManifest.xml?"** – Rajat Porwal Mar 14 '18 at 12:34
  • Do you know any other class Activity that can be called besides com.google.android.street.CameraActivity ? – Derzu Jun 27 '18 at 15:08
1
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.google.android.street"));
context.startActivity(intent);

@Rajat you can use the above code to redirect the user to Google Street View play store page.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163