Phonegap  获取手机设备信息  IMEI

phonegap的Device 提供有:

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

device.cordova  :返回cordova的版本

device.uuid        :返回手机 uuid

device.version   :返回系统版本

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

唯独没有Imei 的获取方法

这里提供增加一个imei的获取

<1> 我们从命令行进入 到工程目录下的  plugins文件夹

<2> 现在开始下载插件

cordova plugin add org.apache.cordova.device

<3> 添加android 平台工程

cordova platform add android

<4> 编译android工程

cordova build

至此  devices 已经生成...

要获取imei  需要改动 原生的Device   2个地方

第一个是  assets 目录下 www/plugins 里面的org.apache.cordova.device / device.js

cordova.define("org.apache.cordova.device.device", function(require, exports, module) { /*

*

* Licensed to the Apache Software Foundation (ASF) under one

* or more contributor license agreements. See the NOTICE file

* distributed with this work for additional information

* regarding copyright ownership. The ASF licenses this file

* to you under the Apache License, Version 2.0 (the

* "License"); you may not use this file except in compliance

* with the License. You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing,

* software distributed under the License is distributed on an

* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

* KIND, either express or implied. See the License for the

* specific language governing permissions and limitations

* under the License.

*

*/

var argscheck = require('cordova/argscheck'),

channel = require('cordova/channel'),

utils = require('cordova/utils'),

exec = require('cordova/exec'),

cordova = require('cordova');

channel.createSticky('onCordovaInfoReady');

// Tell cordova channel to wait on the CordovaInfoReady event

channel.waitForInitialization('onCordovaInfoReady');

/**

* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the

* phone, etc.

* @constructor

*/

function Device() {

this.available = false;

this.platform = null;

this.version = null;

this.uuid = null;

this.cordova = null;

this.model = null;

//添加imei

this.imei = null;

var me = this;

channel.onCordovaReady.subscribe(function() {

me.getInfo(function(info) {

//ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js

//TODO: CB-5105 native implementations should not return info.cordova

var buildLabel = cordova.version;

me.available = true;

me.platform = info.platform;

me.version = info.version;

me.uuid = info.uuid;

me.cordova = buildLabel;

me.model = info.model;

//添加imei

me.imei = info.imei;

channel.onCordovaInfoReady.fire();

},function(e) {

me.available = false;

utils.alert("[ERROR] Error initializing Cordova: " + e);

});

});

}

/**

* Get device info

*

* @param {Function} successCallback The function to call when the heading data is available

* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)

*/

Device.prototype.getInfo = function(successCallback, errorCallback) {

argscheck.checkArgs('fF', 'Device.getInfo', arguments);

exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);

};

module.exports = new Device();

});

第二个是 在 src 当中 修改device类

/*

Licensed to the Apache Software Foundation (ASF) under one

or more contributor license agreements. See the NOTICE file

distributed with this work for additional information

regarding copyright ownership. The ASF licenses this file

to you under the Apache License, Version 2.0 (the

"License"); you may not use this file except in compliance

with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,

software distributed under the License is distributed on an

"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

KIND, either express or implied. See the License for the

specific language governing permissions and limitations

under the License.

*/

package org.apache.cordova.device;

import java.util.TimeZone;

import org.apache.cordova.CallbackContext;

import org.apache.cordova.CordovaInterface;

import org.apache.cordova.CordovaPlugin;

import org.apache.cordova.CordovaWebView;

import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;

import android.content.Context;

import android.provider.Settings;

import android.telephony.TelephonyManager;

import android.util.Log;

public class Device extends CordovaPlugin {

public static final String TAG = "Device";

public static String cordovaVersion = "dev"; // Cordova version

public static String platform; // Device OS

public static String uuid; // Device UUID

private static final String ANDROID_PLATFORM = "Android";

private static final String AMAZON_PLATFORM = "amazon-fireos";

private static final String AMAZON_DEVICE = "Amazon";

/**

* Constructor.

*/

public Device() {

}

/**

* Sets the context of the Command. This can then be used to do things like

* get file paths associated with the Activity.

*

* @param cordova The context of the main Activity.

* @param webView The CordovaWebView Cordova is running in.

*/

public void initialize(CordovaInterface cordova, CordovaWebView webView) {

super.initialize(cordova, webView);

Device.uuid = getUuid();

}

/**

* Executes the request and returns PluginResult.

*

* @param action The action to execute.

* @param args JSONArry of arguments for the plugin.

* @param callbackContext The callback id used when calling back into JavaScript.

* @return True if the action was valid, false if not.

*/

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

if (action.equals("getDeviceInfo")) {

JSONObject r = new JSONObject();

r.put("uuid", Device.uuid);

r.put("version", this.getOSVersion());

r.put("platform", this.getPlatform());

r.put("cordova", Device.cordovaVersion);

r.put("model", this.getModel());

//添加imei 的返回值

r.put("imei", this.imei());

callbackContext.success(r);

}

else {

return false;

}

return true;

}

//--------------------------------------------------------------------------

// LOCAL METHODS

//--------------------------------------------------------------------------

// 获取本地Imei号码

private String imei() {

// String Imei = ((TelephonyManager) cordova.getActivity().getSystemService(cordova.getActivity().TELEPHONY_SERVICE))

// .getDeviceId();

//return Imei;

TelephonyManager systemService = (TelephonyManager)cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);

String deviceId = systemService.getDeviceId();

Log.i("123", deviceId);

return systemService.getDeviceId();

}

/**

* Get the OS name.

*

* @return

*/

public String getPlatform() {

String platform;

if (isAmazonDevice()) {

platform = AMAZON_PLATFORM;

} else {

platform = ANDROID_PLATFORM;

}

return platform;

}

/**

* Get the device's Universally Unique Identifier (UUID).

*

* @return

*/

public String getUuid() {

String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

return uuid;

}

/**

* Get the Cordova version.

*

* @return

*/

public String getCordovaVersion() {

return Device.cordovaVersion;

}

public String getModel() {

String model = android.os.Build.MODEL;

return model;

}

public String getProductName() {

String productname = android.os.Build.PRODUCT;

return productname;

}

/**

* Get the OS version.

*

* @return

*/

public String getOSVersion() {

String osversion = android.os.Build.VERSION.RELEASE;

return osversion;

}

public String getSDKVersion() {

@SuppressWarnings("deprecation")

String sdkversion = android.os.Build.VERSION.SDK;

return sdkversion;

}

public String getTimeZoneID() {

TimeZone tz = TimeZone.getDefault();

return (tz.getID());

}

/**

* Function to check if the device is manufactured by Amazon

*

* @return

*/

public boolean isAmazonDevice() {

if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) {

return true;

}

return false;

}

}

最后 在androidmanifest.xml 当中 添加权限

这是 获取imei必要的权限

插件获取参数的方法:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {

$scope.devicePlatform = device.platform;

$scope.model = device.model;

$scope.deviceID = device.uuid;

$scope.deviceVersion = device.version;

$scope.deviceManufacturer = device.manufacturer;

$scope.isSim = device.isVirtual;

$scope.string = device.serial;

$scope.imei = device.imei;

console.log("设备model:", $scope.model);

console.log("devicePlatform:", $scope.devicePlatform);

console.log("deviceID:", $scope.deviceID);

console.log("版本信息:", $scope.deviceVersion);

console.log("设备制造商:", $scope.deviceManufacturer);

console.log("isSim:", $scope.isSim);

console.log("serial:", $scope.string);

console.log("imei:", $scope.imei);

$log.debug("device信息:", angular.toJson(device));

}

php获取用户手机imei id,获取手机设备信息  IMEI相关推荐

  1. 华为应用市场上传APP失败多次因为:您的应用在用户同意隐私政策前申请获取用户的(MAC地址)个人信息。

    因为您的应用在用户同意隐私政策前申请获取用户的(MAC地址)个人信息.原因APP审核失败多次,后面发现一个方法挺好用的,记录一下: 1.手机先安装xposed,也就是虚拟系统,务必使用我提供的xpos ...

  2. 【微信小程序】获取用户头像和ID

    课程 中国海洋大学22夏<移动软件开发> 实验名称 实验1:第一个微信小程序 一.实验目标 1.学习使用快速启动模板创建小程序的方法: 2.学习不使用模板手动创建小程序的方法. 二.实验步 ...

  3. js中根据元素名获取对象,根据id获取等等。。。

    获取: //根据ID获取var aa = document.getElementById('bo')://根据元素名获取 返回一个集合var bb = document.getElementsByTa ...

  4. H5获取用户所在城市 网页获取用户城市名称

    获取用户城市名称,这里我是使用的百度地图JSAPI 2.0 文档链接 实现步骤: 1.在index.html中引用百度地图的js文件,如下:(需要使用自己的ak,获取方式:点击去官网申请ak) < ...

  5. springboot 获取访问者的ip地址、访问设备信息、城市地址信息

    1.获取访问者的ip地址: 不多说直接上代码,详解见注释 package com.xr.util;import lombok.extern.slf4j.Slf4j;import javax.servl ...

  6. php怎么获取用户所在地址,php获取客户端ip及获取ip所在地址

    // 获取ip function ip() { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) $ip = $_SERVER[" ...

  7. Android 开启个人热点时 获取连接人数以及连接上的设备信息

    最近在开发过程当中,遇到一个需求 ,开启个人热点后需要知道有多少人连上了这个热点 以及这些设备的信息 经过一段时间的摸索和反复的查阅资料,有了下面的代码和解决办法: 首先 连接热点的所有信息都保存在p ...

  8. 手机银行体验性测试:如何获取用户真实感受

    线上化.移动化的银行金融服务方兴未艾.持续深化,一个显著的标志就是手机银行成为银行领域金融科技发力的重点.整体页面文字的易读性.页面跳转的合理性.操作的便利性.功能响应的敏捷性.页面色彩和排版的美观性 ...

  9. 微信小程序简单实现获取用户授权、用户头像并保存到本地

    文章目录 一.获取用户授权 二.获取用户头像并保存 三.实现效果 一.获取用户授权 以index单页面示例, 1.在index.js中的Page-data注册canIUse,用于调用微信开放接口申请用 ...

  10. vc++6.0获取磁盘基本信息_微信小程序——常用功能2:微信小程序用户登录,申请用户授权并获取用户基本信息...

    微信小程序--常用功能2:申请用户授权并获取用户基本信息 为了更好的用户体验,很多时候我们想要获取用户的基本信息,从而实现将信息呈现到用户界面.给用户划分地域.给用户分类等功能. 但是要想获取用户信息 ...

最新文章

  1. 3.6.1 局域网的基本概念和体系结构
  2. babel import语法 js_Babel 的理解
  3. 如何给基于 SAP Cloud SDK 的应用增添缓存支持 Cache support
  4. ajax传值给python_ajax向python脚本传递参数
  5. android sensor源码,阅读android有关sensor的源码总结 - JerryMo06的专栏 - CSDN博客
  6. OpenCV-Python 识别万用表七段数码管电流值
  7. 常用的数据库索引优化语句总结
  8. 修改图片名称并编号;批量处理及缩小图片内存大小(超实用的批处理图片功能)
  9. 视频剪辑软件产品调研分析
  10. python脚本-自动检测Base16、32、64、85系列编码、多层解码(新增base91解码)
  11. 基于LM331的频率电压转换电路
  12. JavaScript中的动画效果
  13. 伽卡他卡学生端 的卸载!!!
  14. 成为认知高手,要避免这9个认知思维陷阱!
  15. 2021域名过期会引发哪些问题?说说常见弊端
  16. Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest
  17. 安装bugzilla
  18. Java面试常考的 BIO,NIO,AIO 总结
  19. 关于FORALLENTRIESIN去重_SAP刘梦_新浪博客
  20. 微星电脑不能u盘引导linux,华硕笔记本u盘重装微星怎么启动不了系统系统系

热门文章

  1. matlab线性同余发生器,用MATLAB进行随机数模拟--线性同余法
  2. P2P中DHT网络介绍
  3. Java三种方法实现字符串排序
  4. Linux串口驱动(5) - read详解
  5. Android Studio查看Android源码
  6. 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解析
  7. 多年 iOS 开发经验总结
  8. 防止被偷窥和修改 Office文档保护秘笈
  9. 计算机控制的液压提升,LSD液压提升系统(2008).doc
  10. RAPIDXML 中文手册,根据官方文档完整翻译!