我使用以下代码从我的 Phonegap / Cordova 插件启动 YouTubeStandalonePlayer Intent:
package com.remcob00.plugins.youtube;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubeStandalonePlayer;
public class YouTube extends Plugin {
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
JSONObject jo = args.getJSONObject(0);
doSendIntent(jo.getString("videoid"));
return new PluginResult(PluginResult.Status.OK);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
private void doSendIntent(String videoid) {
// API key instructions https://developers.google.com/youtube/android/player/register
Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) this.cordova, "YOUR_API_KEY", videoid);
this.cordova.startActivityForResult(this, youtubeIntent, 0);
}
}
但问题是,如果我打开 YouTube 意图并按下后退按钮 I,它不会返回到我打开意图的页面,而是返回 index.html 文件。我怎样才能解决这个问题?