Cordova插件没有什么异常

时间:2022-11-20 20:28:58

I am trying to use YoutubeAndroidPlayerAPI for my Cordova application. I have successfully built the project and I am able to pass data from Javascript to Java, and also am able to display a Toast, but I am not able to start the Youtube's activity.

我正在用YoutubeAndroidPlayerAPI进行我的Cordova应用。我已经成功构建了这个项目,我可以将数据从Javascript传递到Java,也可以显示Toast,但是我不能启动Youtube的活动。

My code which is getting the exception:

我的代码得到了例外:

private void openVideo(final String videoid) {
    Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) this.cordova, "myapikey", videoid);
    this.cordova.startActivityForResult(this, youtubeIntent, 0);
}

From the logcat:

从logcat:

E/PluginManager(14974): Uncaught exception from plugin
E/PluginManager(14974): java.lang.ClassCastException: org.apache.cordova.CordovaActivity$1 cannot be cast to android.app.Activity
E/PluginManager(14974):         at YoutubePlugin.openVideo(YoutubePlugin.java:44)
E/PluginManager(14974):         at YoutubePlugin.execute(YoutubePlugin.java:30)
E/PluginManager(14974):         at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:95)
E/PluginManager(14974):         at org.apache.cordova.PluginManager.exec(PluginManager.java:130)
E/PluginManager(14974):         at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
E/PluginManager(14974):         at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:135)
E/PluginManager(14974):         at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:119)
E/PluginManager(14974):         at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:580)
E/PluginManager(14974):         at android.os.Handler.dispatchMessage(Handler.java:99)
E/PluginManager(14974):         at android.os.Looper.loop(Looper.java:130)
E/PluginManager(14974):         at android.app.ActivityThread.main(ActivityThread.java:3687)
E/PluginManager(14974):         at java.lang.reflect.Method.invokeNative(Native Method)
E/PluginManager(14974):         at java.lang.reflect.Method.invoke(Method.java:507)
E/PluginManager(14974):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
E/PluginManager(14974):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
E/PluginManager(14974):         at dalvik.system.NativeStart.main(Native Method)
D/SystemWebChromeClient(14974): : Line -1470026189 : org.apache.cordova.CordovaActivity$1
I/Web Console(14974): org.apache.cordova.CordovaActivity$1 at :-1470026189

1 个解决方案

#1


1  

You are not supplementing the right arguments to the method. Also I don't believe cordova has startActivityForResult method.

您没有为方法添加正确的参数。我也不相信科尔多瓦有直观的结果法。

Try the following though.

试试以下。

private void openVideo(final String videoid) {
    Context mcontext=this.cordova.getActivity().getApplicationContext();
    Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent(this.cordova.getActivity(), "myapikey", videoid);
    youtubeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mcontext.startActivity(youtubeIntent);
}

#1


1  

You are not supplementing the right arguments to the method. Also I don't believe cordova has startActivityForResult method.

您没有为方法添加正确的参数。我也不相信科尔多瓦有直观的结果法。

Try the following though.

试试以下。

private void openVideo(final String videoid) {
    Context mcontext=this.cordova.getActivity().getApplicationContext();
    Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent(this.cordova.getActivity(), "myapikey", videoid);
    youtubeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mcontext.startActivity(youtubeIntent);
}