android - 在 sencha 触摸 Controller 中调用 android 函数

标签 android sencha-touch-2

Sencha Touch Controller JavaScript:

test:function(name)
{
    alert("function called");
    window.AndroidFunction.playAudio(name);
    alert("completed");
},

安卓JavaScript处理程序:

public class MyJavaScriptInterface {
Context mContext;
MediaPlayer mediaPlayer;

MyJavaScriptInterface(Context c) {
    mContext = c;
}

public void playAudio(String path)
{
    System.out.println("path "+path);
    try {
        int resID = mContext.getResources().getIdentifier(path, "raw", mContext.getPackageName());
        if(mediaPlayer != null)
        {
            mediaPlayer.stop();
            mediaPlayer.reset();
            mediaPlayer.release();
            mediaPlayer = null;
        }   

        mediaPlayer = MediaPlayer.create(mContext, resID);
        mediaPlayer.start();
    } catch (Exception e) {
        System.out.println("ERROR in Play Audio : " + e.getMessage());
    }
}
}

我正在从 sencha 触摸 Controller 功能调用 android 功能 但它不起作用

最佳答案

您是否正在尝试在模拟器或设备中运行您的应用程序。

在我的例子中,我试图在模拟器中运行它不工作但在设备中它运行完美。

关于android - 在 sencha 触摸 Controller 中调用 android 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11721043/

相关文章:

android - 在Android中实现类似扑克牌的控件布局(附原型(prototype)图)

java - 当移动到另一个 fragment 并返回到它时,保存 fragment 内的 textView 值的正确方法是什么?

model - 如何在 Sencha 触摸模型中创建构造函数?

sencha-touch - 如何遍历 Ext.dataview.List 中的项目列表

javascript - 定义中尖括号中类名的用途是什么?

Javafx - 任务 ':run' 执行失败

android - 上网查,使用MVP、RX和Retrofit时放在哪里

android - 动态壁纸中的动态文本

javascript - Sencha 触摸2 : Populating Tree Store with JSON data

ios - 滚动时,光标跟随滚动而不是停留在 iOS 上的字段中?