我正在构建一个从服务器获取JSON数据的cordova应用程序。我收到的一条信息是360在线图片的网址。我需要在Photo Sphere照片查看器中显示这些图像(适用于Android)。我已经看到了API(需要cordova google play服务插件)和this库,但我还没有成功地在应用程序中使用它们。 有谁知道这样做的方法?我可以在原生意图中打开那种类型的图像吗? 提前致谢
答案 0 :(得分:4)
实际上我设法让它发挥作用。我发布解决方案,以防其他人发现它有用。还为here
创建了一个插件创建一个简单的插件,我从cordova调用插件类,该插件类使用AsyncTask
从URL下载图像,onPostExecute
我调用显示查看器的Panorama活动。
Intent intent = new Intent(cordova.getActivity().getApplicationContext(), PanoramaActivity.class);
intent.putExtra("filepath", file.getAbsolutePath());
cordova.getActivity().startActivity(intent);.
PanoramaActivity.java
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.panorama.Panorama;
import com.google.android.gms.panorama.PanoramaApi.PanoramaResult;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import java.io.File;
import android.os.Environment;
public class PanoramaActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener{
File file;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mClient = new GoogleApiClient.Builder(this, this, this)
.addApi(Panorama.API)
.build();
Intent i= getIntent();
Bundle b = i.getExtras();
file = new File(b.getString("filepath"));
@Override
public void onStart() {
super.onStart();
mClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
Uri uri = Uri.fromFile(file);//Uri.parse(path);//Uri.fromFile(file);
Panorama.PanoramaApi.loadPanoramaInfo(mClient, uri).setResultCallback(
new ResultCallback<PanoramaResult>() {
@Override
public void onResult(PanoramaResult result) {
if (result.getStatus().isSuccess()) {
Intent viewerIntent = result.getViewerIntent();
Log.i(TAG, "found viewerIntent: " + viewerIntent);
if (viewerIntent != null) {
startActivity(viewerIntent);
}
} else {
Log.e(TAG, "error: " + result);
}
}
});
}
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "connection suspended: " + cause);
}
@Override
public void onConnectionFailed(ConnectionResult status) {
Log.e(TAG, "connection failed: " + status);
}
@Override
public void onStop() {
super.onStop();
mClient.disconnect();
Log.e(TAG, "ON Stop ");
}