在Android中使用JavaScript更改活动

change activity with JavaScript in Android

本文关键字:活动 JavaScript Android      更新时间:2023-09-26

我有一个应用程序,当JavaScript被激发时,它应该调用一个活动,

这是我的JavaScript,正在中工作

javascript接口

private class JsInterface{
    //function that will be called from assets/test.js
     
    public void log(String msg){
        Log.d("MSG FROM JAVASCRIPT", msg);
                
    }

这就是我用触摸按钮来调用活动的方式:

 Button next = (Button) findViewById(R.id.button1);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), VideoVC.class);
            startActivityForResult(myIntent, 0);
        }
    });

但由于我对安卓系统一无所知,开发人员不知道如何更改JsInterface 上的活动

我在我的JSinterface中尝试过:

 Intent myIntent2 = new Intent(JsExampleMain.this, VideoVC.class);
startActivity(myIntent2);

但不喜欢";startActicity(myIntent2)"

如何完成这个简单的任务?

好吧,所以我已经想好了!,哈哈让我疯了!

所以我只需要把Intent的代码放在我的日志方法中!

  //javascript interface
     private class JsInterface{
   //function that will be called from assets/test.js
    public void log(String msg){
        Log.d("MSG FROM JAVASCRIPT", msg);
        Log.d("kukusha", "mensaje");
        Intent i = new Intent(JsExampleMain.this,VideoVC.class);    
        startActivity(i); 
    }
 }