【问题标题】:Uncaught (in promise) Error: "Device" plugin is not implemented on android未捕获(承诺)错误:“设备”插件未在 android 上实现
【发布时间】:2021-08-19 10:41:43
【问题描述】:

我正在使用来自 Capacitor (https://capacitorjs.com/docs/apis/device#deviceinfo) 的设备 API 以及 Ionic Framework 和 VueJS。目标是从 Android 设备检索 UUID。

在浏览器中打开应用程序时,我可以看到正在记录的设备信息。但是,在 Android 设备/Android Studio 上打开它时出现此错误:

未捕获(承诺)错误:“设备”插件未在 android 上实现

据我所知,Android 支持该插件。我做错了什么?

代码:

import { Device } from "@capacitor/device";
async getDeviceInfo() {
  const info = await Device.getId();
  this.uuid = info.uuid;
  alert(this.uuid);
  const moreInfo = await Device.getInfo();
  const battery = await Device.getBatteryInfo();
  alert(JSON.stringify(moreInfo));
  alert(JSON.stringify(battery));
  alert("test");
},

【问题讨论】:

  • "import { Device } from "@capacitor/device"; 适用于电容器 3.0 和此 import { Plugins } from '@capacitor/core'; const { Device } = Plugins; 电容器 2.0
  • 奇怪:我确实更新到电容器 3,但是第一行不起作用。我尝试了第二个,确实有效;)..
  • 谢谢,这回答了我的问题

标签: javascript android vue.js ionic-framework capacitor


【解决方案1】:

同样的错误发生在我身上,我根据 Android 的电容器更新文档修复了它,从 MainActivity 类中删除了 onCreate 方法。

 public class MainActivity extends BridgeActivity {

 }

【讨论】:

    【解决方案2】:

    有趣的是,在 Capacitor 3.x 中,他们已将 uuid 移动到它自己的函数中。

    import { Device } from '@capacitor/device';
    
      async getdevinfo(){
        console.log('trying to get device info');
    // works in browser
          const info = await Device.getId();
          console.log(info);
          console.log(info.uuid);
    
    //wont work in browser
          const moreInfo = await Device.getInfo();
          const battery = await Device.getBatteryInfo();
          console.log(JSON.stringify(moreInfo));
          console.log(JSON.stringify(battery));
    
        console.log('post device info request');
      }
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2021-11-28
      相关资源
      最近更新 更多