【问题标题】:Launching Camera App Using Javascript in android在android中使用Javascript启动相机应用程序
【发布时间】:2014-04-07 07:27:26
【问题描述】:

是否可以通过 Android JSInterface 启动相机应用程序?目前我可以通过 android 代码中的 javascript 访问 test()。我想使用 JSInterface 通过 javascript 启动相机应用程序。

jQuery:

  $(function() {
      FastClick.attach(document.body);
      $('.btn-primary-panel').click(function(){
        alert(android.test());// WebViewFragment.Java->JsInterface->getPhoneNumber
      });
  });

Android 代码:

  public class JsInterface{
      public String test()
      {
          // Here call any of the public activity methods....
          return "WebViewFragment.Java->JsInterface->getPhoneNumber";
      }
  }

【问题讨论】:

    标签: android android-fragments android-camera hybrid-mobile-app


    【解决方案1】:

    不妨试试这个:

    public class JsInterface{
          public void launchCamera()
          {
              Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
              startActivityForResult(intent, 0); 
          }
    }
    

    别忘了权限:

    <uses-permission android:name="android.permission.CAMERA"></uses-permission>
    

    然后就使用

    android.launchCamera() 来自 JS。

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多