Android 未定义PhoneGap 3.1生成设备
我有一个sencha touch项目。我是使用phonegap 2.9构建的,可以很好地使用device.uuid返回到device Id。当我尝试使用3.1 device.uuid构建时抛出“device Is Not Defined”错误。 My config.xmlAndroid 未定义PhoneGap 3.1生成设备,android,ios,extjs,cordova,Android,Ios,Extjs,Cordova,我有一个sencha touch项目。我是使用phonegap 2.9构建的,可以很好地使用device.uuid返回到device Id。当我尝试使用3.1 device.uuid构建时抛出“device Is Not Defined”错误。 My config.xml <preference name="phonegap-version" value="3.1.0" /> <preference name="stay-in-webview" value="true" /&g
<preference name="phonegap-version" value="3.1.0" />
<preference name="stay-in-webview" value="true" />
<access origin="*" />
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
<gap:splash src="images/splash.png" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
我需要帮助。如何解决这个问题 我假设您正在使用phonegap build进行构建,对吗 在PhoneGap3中,默认情况下不再包含核心api,现在是插件,因此您必须显式添加您正在使用的任何api 将以下行添加到config.xml后,您应该能够读取UUID:
<gap:plugin name="org.apache.cordova.device" />
您还可以删除以下行,因为API特性现在由新的插件格式处理
无用线路:
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
将您的注册码置于DeviceRady功能下
var platform = null;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
platform = device.platform;
//alert(platform);
$("#app-status-ul").append('<li>'+ platform +'</li>');
try
{
pushNotification = window.plugins.pushNotification;
$("#app-status-ul").append('<li>registering ' + device.platform + '</li>');
if (device.platform == 'android' || device.platform == 'Android' ||
device.platform == 'amazon-fireos' ) {
pushNotification.register(successHandler, errorHandler, {"senderID":"860557673192","ecb":"onNotification"}); // required!
} else {
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}); // required!
}
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
alert(txt);
}
}
var平台=null;
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
函数ondevicerady(){
平台=设备。平台;
//警报(平台);
$(“#应用程序状态ul”)。附加(“”+平台+” ”);
尝试
{
pushNotification=window.plugins.pushNotification;
$(“#应用程序状态ul”).append(“注册”+device.platform+” );
如果(device.platform=='android'| | device.platform=='android'||
device.platform==“amazon fireos”){
register(successHandler,errorHandler,{“senderID”:“860557673192”,“ecb”:“onNotification”});//必需!
}否则{
注册(tokenHandler,errorHandler,{“badge”:“true”,“sound”:“true”,“alert”:“true”,“ecb”:“onNotificationAPN”});//必需!
}
}
捕捉(错误)
{
txt=“此页面上有错误。\n\n”;
txt+=“错误描述:”+err.message+“\n\n”;
警报(txt);
}
}
感谢您的快速修复答案,我尝试了您的答案,但仍在工作。我还没有在sencha中开发,但是我在jQuery Mobile中遇到了一个类似的问题,我使用延迟对象来检查设备何时准备好,并执行phonegap代码,直到设备准备好,检查它是否适合您
var platform = null;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
platform = device.platform;
//alert(platform);
$("#app-status-ul").append('<li>'+ platform +'</li>');
try
{
pushNotification = window.plugins.pushNotification;
$("#app-status-ul").append('<li>registering ' + device.platform + '</li>');
if (device.platform == 'android' || device.platform == 'Android' ||
device.platform == 'amazon-fireos' ) {
pushNotification.register(successHandler, errorHandler, {"senderID":"860557673192","ecb":"onNotification"}); // required!
} else {
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}); // required!
}
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
alert(txt);
}
}