gpt4 book ai didi

Android 将手机数据写入屏幕

转载 作者:行者123 更新时间:2023-11-30 03:57:11 26 4
gpt4 key购买 nike

我正在尝试将有关我手机的信息写入我的应用程序屏幕。我在下面做错了什么?我在我的 list 中设置了适当的权限。我正在使用 Phonegap 开发应用程序。使用 Jquery。该应用程序启动但不显示电话信息。

<p id="deviceProperties">Loading device properties...</p>

完整页面代码

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="jquery.mobile-1.2.0.css" />
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript" src="jquery.mobile-1.2.0.js"></script>
<script type="text/javascript">

$(document).on("pageinit", "#newpage", function () {
$('#saveButton').click(function () {
localStorage.setItem("name", $('#name').val());
});

});
var wID = navigator.accelerometer.watchAcceleration(onSucess, onerror, { frequency: 1000 });
function onSucess(a) {
$('#aX').html(a.x);
$('#aY').html(a.y);
$('#aZ').html(a.z);
$('#aTime').html(a.timestamp);
}
function onError() {

}

$(document).on('pageshow', '#newpage', function () {
var personName = localStorage.getItem("name");
if (personName.length > 0) {
$('#name').val(personName);
}
});

</script>
<script type="text/javascript" charset="utf-8">

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

// Cordova is ready
//
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 Version: ' + device.version + '<br />';
}

</script>

<title>Hello World 2</title>
</head>
<body>

<div id="home" data-role="page">

<div data-role="header">
<h1>Home Page2</h1>
</div>

<div data-role="content">
hello Phone Gap and JQuery Mobile!
<a href="#newpage" data-role="button">new page</a>
<br>
<p id="deviceProperties">Loading device properties...</p>
<p id="ax"> </p>
<p id="ay"> </p>
<p id="az"> </p>
<p id="aTime"> </p>
</div>

<div data-role="footer" data-position="fixed">
<a href="#dialogpage" data-rel="dialog" data-icon="plus">Add Something</a>

</div>
</div>


<div id="newpage" data-role="page">

<div data-role="header">
<a href="#home" data-icon="delete">Cancel</a>
<h1>New Page</h1>
<a href=#home" data-icon="save">save</a>
</div>

<div data-role="content">
<label for="name">what is your name?</label>
<input id="name" type="text" name="name" value="" />
<a id="saveButton" href="" data-role="button">Save</a>
</div>

<div data-role="footer" data-position="fixed">
<h4>
footer</h4>
</div>

</div>

<div id="dialogpage" data-role="page">
<div data-role="header">
<h1>Dialog</h1>
</div>
<div data-role="content">
this is a dialog
</div>
</div>

<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>

最佳答案

您需要等到从 PhoneGap 获得 deviceready 事件,否则您在 PhoneGap 实际初始化并准备好返回数据之前请求它。请参阅此处的文档/示例:http://docs.phonegap.com/en/2.1.0/cordova_device_device.md.html#Device

关于Android 将手机数据写入屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13159616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com