当我想用我的Android应用程序打开一张photosphere图片时,我遇到了问题。实际上,我可以打开它,但应用程序显示了一些photosphere的预览(它从左到右滚动图片)。我希望我的应用程序使用acceloremeter模式(我们需要将手机转动以显示整个图片的模式)打开光球,而无需单击右下方的按钮。
我使用该代码打开全景图:
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);
提前致谢,
答案 0 :(得分:3)
希望以下内容有所帮助:
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);
PhotoSphere使用陀螺仪而非加速度计,但我相信您可以使用第二种解决方案并添加自己的加速度计功能。