试图在 android 中获取 imei 号码 - phonegap
trying to get imei number in android - phonegap
我在查看一些博客后尝试在 android 中获取 IMEI 号码。
下面是我的原生 Activity 代码:
public class MainActivity extends CordovaActivity
{
private static String imei;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
super.init();
loadUrl(launchUrl);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei=tm.getDeviceId();
LOG.d("kp","hello");
}
@JavascriptInterface
static public String getIMEI(){
return imei;
}
}
并在 ionic 框架创建的 app.js 文件中调用 getIMEI 函数。
angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
var imei = window.MainActivity.getIMEI();
alert("hi "+imei);
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
警报本身不会出现。
如果我在下面替换
var imei = window.MainActivity.getIMEI();
alert("hi "+imei);
和
alert("Hi");
警报按预期出现,但当我添加 var imei = window.MainActivity.getIMEI();
时警报中断
有人可以帮助我获取 IMEI 号码吗?
我终于明白了。
appview 有获取 webview 的方法。
Webview 有方法来设置允许从 JavaScript.
调用的 javainterface
我在查看一些博客后尝试在 android 中获取 IMEI 号码。
下面是我的原生 Activity 代码:
public class MainActivity extends CordovaActivity
{
private static String imei;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
super.init();
loadUrl(launchUrl);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei=tm.getDeviceId();
LOG.d("kp","hello");
}
@JavascriptInterface
static public String getIMEI(){
return imei;
}
}
并在 ionic 框架创建的 app.js 文件中调用 getIMEI 函数。
angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
var imei = window.MainActivity.getIMEI();
alert("hi "+imei);
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
警报本身不会出现。
如果我在下面替换
var imei = window.MainActivity.getIMEI();
alert("hi "+imei);
和
alert("Hi");
警报按预期出现,但当我添加 var imei = window.MainActivity.getIMEI();
有人可以帮助我获取 IMEI 号码吗?
我终于明白了。 appview 有获取 webview 的方法。 Webview 有方法来设置允许从 JavaScript.
调用的 javainterface