Android的手机写数据到屏幕 [英] Android writing phone data to screen

查看:110
本文介绍了Android的手机写数据到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写一下我的手机信息,以我的应用程序的屏幕。我究竟做错了下面在这里?
我在我的清单设置适当的权限。即时通讯使用PhoneGap的到了下发展应用。使用jQuery。
该应用程序lanuches它仅仅指刚没有按不显示手机信息。

 < p n =deviceProperties>加载设备属性...< / P>

整版code

 <!DOCTYPE HTML>
< HTML和GT;
< HEAD>
< META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8/>
< META NAME =格式检测CONTENT =电话=无/>
&所述;元名称=视口含量=用户可扩展=无,初始规模= 1,最大规模= 1,最小规模= 1,宽度=设备宽度,高度=设备高度,目标-densitydpi =设备DPI/>
<链接rel =stylesheet属性类型=文/ CSS的href =jquery.mobile-1.2.0.css/>
<脚本类型=文/ JavaScript的SRC =jQuery的-1.8.2.js>< / SCRIPT>
 <脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-2.1.0.js>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =jquery.mobile-1.2.0.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>    $(文件)。在(pageinit,#newpage功能(){
        $('#saveButton')。点击(函数(){
            localStorage.setItem(名,$('#姓名)VAL());
        });    });
    VAR WID = navigator.accelerometer.watchAcceleration(onSucess,onError的,{频率:1000});
    功能onSucess(一){
        $('#AX')HTML(a.x);
        $('#一条Y')HTML(a.y);
        $('#AZ)HTML(a.z)。
        $('#ATIME')HTML(a.timestamp);
    }
    功能的onError(){    }    $(文件)。在('pageshow','#newpage',函数(){
        VAR PERSONNAME = localStorage.getItem(名称);
        如果(personName.length大于0){
            $('#姓名)VAL(PERSONNAME)。
        }
    });< / SCRIPT>
<脚本类型=文/ JavaScript的字符集=utf-8>//等待科尔多瓦加载
//
document.addEventListener(deviceready,onDeviceReady,FALSE);//科尔多瓦准备就绪
//
功能onDeviceReady(){
    VAR元=的document.getElementById('deviceProperties');    element.innerHTML ='设备名称:'+ device.name +'< BR />' +
                        设备科尔多瓦:'+ device.cordova +'< BR />' +
                        设备平台:'+ device.platform +'< BR />' +
                        设备UUID:'+ device.uuid +'< BR />' +
                        设备版本:'+ device.version +'< BR />';
}< / SCRIPT><标题>的Hello World 2'; /标题>
< /头>
<身体GT;< D​​IV ID =家的数据角色=页面>    < D​​IV数据角色=头>
        < H1>首页第2页< / H1>
    < / DIV>    < D​​IV数据角色=内容>
        你好电话Gap和jQuery Mobile的!
        < A HREF =#NEWPAGE数据角色=按钮>全新网页< / A>
        < BR>
    < p n =deviceProperties>加载设备属性...< / P>
         < p n =开刀> &所述; / P>
        &下,P ID =AY> &所述; / P>
        &下,P ID =AZ> &所述; / P>
        &下,P ID =ATIME> &所述; / P>
    < / DIV>    < D​​IV数据角色=页脚数据位=固定>
    < A HREF =#dialogpage数据相对=对话框中的数据图标=加>添加的东西< / A>    < / DIV>
< / DIV>
< D​​IV ID =NEWPAGE数据角色=页面>    < D​​IV数据角色=头>
    < A HREF =#家数据图标=删除>取消< / A>
        < H1>新建页面< / H1>
        < A HREF =#家数据图标=拯救>保存< / A>
    < / DIV>    < D​​IV数据角色=内容>
        <标签=名与GT;你叫什么名字<?/标签>
        <输入ID =名称类型=文本名称=名字值=/>
        &下;一个ID =saveButton的href =数据角色=按钮>保存与所述; / A>
    < / DIV>    < D​​IV数据角色=页脚数据位=固定>
        < H4>
            页脚< / H4>
    < / DIV>< / DIV>< D​​IV ID =dialogpage数据角色=页面>
 < D​​IV数据角色=头>
        < H1>对话框和LT; / H1>
    < / DIV>
     < D​​IV数据角色=内容>
        这是一个对话
     < / DIV>
< / DIV><脚本类型=文/ JavaScript的SRC =JS / index.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
    app.initialize();
< / SCRIPT>
< /身体GT;
< / HTML>


解决方案

您需要等待,直到你得到的 deviceready 事件从PhoneGap的,否则您请求之前的PhoneGap实际上是初始化并准备返回的数据。请参阅该文档/例子在这里: HTTP://docs.phonegap。 COM / EN / 2.1.0 / cordova_device_device.md.html#设备

Im trying to write information about my phone to my app screen. What am i doing wrong below here? I have the proper permissions set in my manifest. Im using Phonegap to develope the app. With Jquery. The app lanuches it jsut doesn not display the phone information.

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

Full page code

<!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>

解决方案

You need to wait until you get the deviceready event from PhoneGap, otherwise you are requesting it before PhoneGap is actually initialized and ready to return data. See the docs/example here: http://docs.phonegap.com/en/2.1.0/cordova_device_device.md.html#Device

这篇关于Android的手机写数据到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆