简体   繁体   中英

Cordova - How to display 360 images on Android

I am building a cordova application which fetches JSON data from the server. One piece of information that I receive is the URL of 360 online images. I need to display those images in a photo sphere viewer (for Android). I' ve seen this API (needs cordova google play services plugin) and this library but I haven't managed to successfully use them inside the application. Does anyone know a way of doing that? Can I open that type of image in a native intent? Thanks in advance

Actually I managed to make it work. I am posting the solution, in case someone else finds it useful. Also created a plugin for that which can be found here

creating a simple plugin, I call from cordova the plugin class which downloads using AsyncTask an image from a URL and onPostExecute I call the Panorama activity that shows the viewer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM