首页/Ionic/列表

ionic开发——获取手机设备信息

来源:  2018-04-09 15:54:32    评论:0点击:

首先,我们要安装cordova的plugin插件cordova-plugin-device
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git//添加插件  
$ cordova plugin rm org.apache.cordova.core.device//删除插件 

在Android设备中,

1.需要在config.xml里面添加配置

(in app/res/xml/config.xml)
<feature name="Device">
    <param name="android-package" value="org.apache.cordova.Device" />
</feature>

(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
BlackBerry WebWorks

(in www/plugins.xml)
<feature name="Device">
    <param name="blackberry-package" value="org.apache.cordova.device.Device" />
</feature>

(in www/config.xml)
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<rim:permissions>
    <rim:permit>read_device_identifying_information</rim:permit>
</rim:permissions>
Windows Phone (in Properties/WPAppManifest.xml)

<Capabilities>
    <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
    <Capability Name="ID_CAP_IDENTITY_DEVICE" />
    <Capability Name="ID_CAP_IDENTITY_USER" />
</Capabilities>
Reference: Application Manifest for Windows Phone

Tizen (in config.xml)

<feature name="http://tizen.org/api/systeminfo" required="true"/>

 

在项目中获取的代码如下:

device.model     :返回设备的模型或产品的名称

device.cordova  :返回cordova的版本

device.uuid        :返回手机 uuid 

device.version   :返回系统版本  

device.platform  :返回手机的平台信息  (android/ios 等等)



完整的例子:
 

<!DOCTYPE html>
<html>
  <head>
    <title>Device Properties Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        var element = document.getElementById('deviceProperties');
        element.innerHTML = 'Device Name: '     + device.name     + '<br />' +
                            'Device Cordova: '  + device.cordova  + '<br />' +
                            'Device Platform: ' + device.platform + '<br />' +
                            'Device UUID: '     + device.uuid     + '<br />' +
                            'Device Model: '    + device.model    + '<br />' +
                            'Device Version: '  + device.version  + '<br />';
    }

    </script>
  </head>
  <body>
    <p id="deviceProperties">Loading device properties...</p>
  </body>
</html>



 

如果想获取手机imei请查看——ionic开发——获取手机唯一标识imei码点击打开链接

更多cordova-plugin-device信息请查看http://cordova.apache.org/docs/en/3.0.0/cordova/device/device.html点击打开链接

 


为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权