次のコードを使用して、Phonegap/CordovaプラグインからYouTubeStandalonePlayerインテントを開始します。
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ファイルに戻ることです。どうすればこれを修正できますか?