13

I am stuck with a problem when I want open a photosphere picture with my android application. Indeed, I can open it but the application show a sort of preview of the photosphere (it scrolls the picture from left to right). I want that my application open the photosphere with the acceloremeter mode (the mode that we need to turn the phone to show the entire picture) without clicking the button at the bottom right.

I use that code to open the panorama :

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.google.android.gms", "com.google.android.gms.panorama.PanoramaViewActivity"));
intent.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg"));
startActivity(intent);

Thanks in advance,

benoitm76
  • 131
  • 6
  • `"file://" + "/sdcard` - this is bad approach. See `Environment` class – Marcin Orlowski Jan 06 '14 at 15:20
  • Yes i known. I just put this for a test. – benoitm76 Jan 06 '14 at 15:33
  • provide the code of buttons that scrolls your image please. – ProllyGeek Mar 27 '15 at 11:27
  • 1
    Unfortunately, it's currently not possible to supply the mode in which to display the given photo. `PanoramaViewActivity` only looks at the data `Uri` set to the incoming `Intent`, or [`EXTRA_STREAM`](http://developer.android.com/reference/android/content/Intent.html#EXTRA_STREAM) if the former is `null`. There is no 'extra' to supply the mode. – MH. Jan 23 '16 at 09:14

1 Answers1

3

Hope the following below helps:

public class YourActivity extends Activity implements ConnectionCallbacks,
        OnConnectionFailedListener {

private GoogleApiClient gacClient;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    gacClient= new GoogleApiClient.Builder(this, this, this)
            .addApi(Panorama.API)
            .build();
}

@Override
public void onStart() {
    super.onStart();
    gacClient.connect();
}

@Override
public void onConnected(Bundle connectionHint) {
    Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg");

    Panorama.PanoramaApi.loadPanoramaInfo(gacClient, uri).setResultCallback(
            new ResultCallback<PanoramaResult>() {
        @Override
        public void onResult(PanoramaResult result) {
            Intent i;
            if (result.getStatus().isSuccess() && (i = result.getViewerIntent()) != null) {
                startActivity(i);
            } else {
                // Handle unsuccessful result
            }
        }
    });
}

@Override
public void onConnectionSuspended(int cause) {
    // Handle connection being suspended
}

@Override
public void onConnectionFailed(ConnectionResult status) {
    // Handle connection failure.
}

@Override
public void onStop() {
    super.onStop();
    gacClient.disconnect();
}
}

Below is a link and example of library to use PhotoSphere without Google+:

https://github.com/kennydude/photosphere

Intent i = new Intent(MainActivity.this, SphereViewer.class);
                i.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg"));
                startActivity(i);

PhotoSphere uses gyroscope and not accelerometer, however I am sure you can use the second solution and add your own accelerometer functionality.

Kevin Crain
  • 1,905
  • 1
  • 19
  • 28
  • OP said that "I want that my application open the photosphere with the acceloremeter mode (the mode that we need to turn the phone to show the entire picture) without clicking the button at the bottom right." Looks like your solution opens the photosphere in the preview mode, not accelerometer mode. – aga Mar 28 '15 at 12:06
  • 1
    I meant that OP wanted to start the panorama in the mode that, quote, "the mode that we need to turn the phone to show the entire picture without clicking the button at the bottom right". Your solution opens the panorama in the preview mode, just like the OP solution does (the only difference is that your solution is adapted to newer API). – aga Mar 30 '15 at 20:40
  • Do you know to use SensorEventListener along with SensorManager ? – Kevin Crain Apr 02 '15 at 12:48
  • Can this also be used with panorama images in the assets folder? And does the image has to be created with the google camera app? – Bart Burg Jan 25 '16 at 11:15