将第三方Android JAR集成到Titanium Mobile应用程序中



我正在编写一个Titanium应用程序,尝试播放YouTube视频。目标是让用户留在应用程序中,所以调用本地youtube应用程序是不可能的,我已经可以这么做了我有适用于iOS的代码,但这只是因为嵌入到webView中支持内容。不幸的是,安卓系统并非如此。

看起来http://code.google.com/p/android-youtube-player/wiki/OpenYouTubePlayerActiviyInstructions将解决我的问题,但我不确定如何利用钛。医生建议从安卓系统做到这一点:

Intent lVideoIntent = new Intent(null, Uri.parse("ytpl://"+YOUTUBE_PLAYLIST_ID), this, OpenYouTubeActivity.class);//public Intent (String action, Uri uri, Context packageContext, Class<?> cls) from Android doc
startActivity(lVideoIntent);

因此,利用http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Intent-object.html和http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Activity-object.html作为向导,想出了:

var intent = Ti.Android.createIntent({
            action: 'null',
            data: 'ytv://'+vguid,
            packageName: 'com.keyes.youtube',
            className: 'com.keyes.youtube.OpenYouTubeActivity'
        });
        Ti.Android.Activity.startActivity(intent);

在我的TiApp.XML中,我添加了以下内容:

<android xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission> 
        <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
        <activity android:name="com.keyes.youtube.OpenYouTubePlayerActivity"></activity>
    </android>

当我尝试运行代码时,会出现以下错误:TypeError:无法调用未定义的方法"startActivity"(file:///android_asset/Resources/app.js#162)其中162是startActivity(intent)的行号;

我认为这与源代码不在类路径上有关(我试过只使用他的.jar和单独的.java文件)和/或它没有用作模块。我使用了一个iOS模块,但不知道如何编写自己的Android模块,更不用说将某人的代码移植到一个模块了。

有什么帮助吗?我相信这是很多钛用户所反对的。

编辑1

我在这方面取得了一些进展,但仍然没有解决方案。我选择了"模块"路线,因为我还没有看到其他方法可以将jars/java文件包含在项目构建中。我将模块构建为"ytModule",并通过添加将其包含在内

<module version="0.1">com.keyes.ytModule</module>

到tiapp.xml。然后我得到

[DEBUG] Looking for Titanium Module id: com.keyes.ytModule, version: 0.1, platform: <any platform>
[DEBUG] module_id = com.keyes.ytModule
[DEBUG] appending module: com.keyes.ytModule.YtplayerModule

当我在TitaniumStudio制作时。我正在处理这个问题,并将不断发布更新/尝试建议

尝试使用新的SDK。http://developer.appcelerator.com/doc/mobile/android/module_sdk

The reason is its not able to call the Activity's method which is

抛出此错误。

 Ti.Android.currentActivity.startActivity(intent)

这应该行得通。

最新更新