当我想用我的android应用程序打开photosphere图片时,我遇到了一个问题。实际上,我可以打开它,但是应用程序显示了一种photosphere预览(它将图片从左向右滚动)。我希望我的应用程序打开光球与加速度计模式(我们需要转动手机显示整个图片的模式),而不点击右下角的按钮。
我用那个代码打开全景图:

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);

提前谢谢你,

最佳答案

希望以下帮助:

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();
}
}

下面是在没有PhotoSphere的情况下使用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);

光球使用陀螺仪,而不是加速度计,但我相信你可以使用第二个解决方案,并添加自己的加速度计功能。

07-27 15:54