ZNDS智能电视网 推荐当贝市场

TV应用下载 / 资源分享区

软件下载 | 游戏 | 讨论 | 电视计算器

综合交流 / 评测 / 活动区

交流区 | 测硬件 | 网站活动 | Z币中心

新手入门 / 进阶 / 社区互助

新手 | 你问我答 | 免费刷机救砖 | ROM固件

查看: 15294|回复: 0
上一主题 下一主题
[教程]

Android开发笔记第七篇(源代码的各个文件及ADB 工具使用)

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-28 16:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 meigui 于 2011-8-30 22:28 编辑       第四部分: 源代码的各个文件   
   
   
Android.mk 是整个工程的“Makefile”,其内容如下所示:   
   
   
LOCAL_PATH:= $(call my-dir)   
include $(CLEAR_VARS)   
LOCAL_MODULE_TAGS := samples   
# Only compile source java files in this apk.   
LOCAL_SRC_FILES := $(call all-java-files-under, src)   
LOCAL_PACKAGE_NAME := HelloActivity   
LOCAL_SDK_VERSION := current   
include $(BUILD_PACKAGE)   
# Use the following include to make our test apk.   
include $(call all-makefiles-under,$(LOCAL_PATH))   
   
   
   
   
这个文件在各个 Android 的工程中都是类似的,其中 LOCAL_PACKAGE_NAME 表示了这个包的名字。LOCAL_MODULE_TAGS 表示了模块的标,在这里使用的是samples,正式的应用程序(packages 目录中的应用)中多使用 eng development。   
   
AndroidManifest.xml 是这个 HelloActivity 工程的描述文件,其内容如下所示:   
  1. <?xml version="1.0" encoding="utf-8"?>   
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"   
    package="com.example.android.helloactivity">   
    <application android:label="He llo, Activity!">   
    <activity android:name="He lloActivity">   
    <intent-filter>   
    <action android:name="android.intent.action.MAIN"/>   
    <category android:name="android.intent.category.LAUNCHER"/>   
    </intent-filter>   
    </activity>   
    </application>   
    </manifest>
复制代码
其中 package 用于说明这个包的名称,android:labeapplication 中的内容是表示这个应用程序在界面上显示的标题,activity 中的 android:name 表示这个 Android 的活动的名称。   
文件 src/com/example/android/helloactivity/HelloActivity.java 是程序主要文件,由 JAVA 语言   
写成   
  1. package com.example.android.helloactivity;   
    import android.app.Activity;   
    import android.os.Bundle;   
    public class HelloActivity extends Activity {   
    public HelloActivity() {   
    }   
    @Override   
    public void onCreate(Bundle savedInstanceState) {   
    super.onCreate(savedInstanceState);   
    setContentView(R.layout.hello_activity);   
    }   
    }
复制代码
com.example.android.helloactivity 表示的是这个包的名称, 在文件的头部引入了两个包android.app.Activity 是一个 Android 活动( Activity)包,每一个 Android 活动都需要继承Activity 类。包 android.os.Bundle 用于映射字符串的值。onCreate()是一个重载的函数,在这个函数中实现应用程序创建的所执行的过程。其中setContentView()设置当前的视图(View)。设置的方法是使用一个文件,这个文件因此决定了视图中包含的内容。这里使用的是R.layout.hello_activity,表示从 res/layout/目录中使用 hello_activity.xml 文件。   
res/layout/hello_activity.xml 文件的内容如下所示:   
  1. <?xml version="1.0" encoding="utf-8"?>   
    <EditText xmlns:android="http://schemas.android.com/apk/res/android"   
    android:id="@+id/text"   
    android:layout_width="fill_parent"   
    android:layout_height="fill_parent"   
    android:textSize="18sp"   
    android:autoText="true"   
    android:capitalize="sentences"   
    android:text="@string/hello_activity_text_text" />
复制代码
其中定义了一个可编辑的文本( EditText),下面的各项其实是它的各种属性, android:text 表示这个文本的内 容 ,string/hello_activity_text_text 表 示 找 到 相 应 的 文 件 , 也 就 是 res/value/string.xml 文 件 中 的hello_activity_text_text 文本。   
res/value/string.xml 的内容如下所示:   
  1. <?xml version="1.0" encoding="utf-8"?>   
    <resources>   
    <string name="hello_activity_text_text">He llo, World!</string>   
    </resources>
复制代码
hello_activity_text_text 文本被 res/layout/hello_activity.xml 文件引用,正是应用程序运行时在   
屏幕显示的文本。   
   
Android ADB 工具使用   
   
   
adb(Android Debug Bridge)是 Android 提供的一个通用调试工具,借助这个工具,我妈可以管理设备或手机模   
拟器的状态。   
   
   
adb 功能操作:   
   
   
快速更新设备或手机模拟器中的代码,如应用或 Android 系统升级   
在设备上运行 shell 命令   
管理设备或手机模拟器上预定端口   
在设备或手机模拟器上复制、粘贴文件   
   
   
   
adb 常用操作:   
   
   
安装应用到模拟器   
   
   
adb install app.apk   
   
   
Android 没有提供一个卸载应用的命令,只能手动删除:   
adb shell   
cd data/app   
rm app.apk   
   
   
进入设备或模拟器的 Shell   
   
   
adb shell   
通过以上命令,可以进入设备或模拟器的 shell 环境中,在这个 Linux Shell 中,你可以执行各种 Linux 的命令 ,   
另外如果只想执行一条 shell 命令,可以采用以下方式:   
adb shell [command]   
如:   
adb shell dmesg   
会打印出内核的调试信息   
   
   
发布端口   
   
   
可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:   
adb forward tcp:5555 tcp:8000   
   
复制文件   
   
   
可向一个设备或从一个设备中复制文件   
   
   
复制一个文件或目录到设备或模拟器上:   
   
adb push   
如:   
adb push test.txt /tmp/test.txt   
   
   
从设备或模拟器上复制一个文件或目录   
   
adb pull   
如:   
adb pull /android/lib/libwebcore.os   
   
   
搜索/等待模拟器、设备实例   
   
   
   
取得当前运行的模拟器、设备的实例列表及每个实例的状态 |   
   
   
   
等待正在运行的设备   
   
adb devices   
adb wait-for-device   
   
   
查看 Bug 报告   
   
   
adb bugreport   
   
   
记录无线通讯日志   
   
   
无线通讯记录日志非常多,在运行时没必要记录,可以通过命令设置记录   
adb shell   
logcat -b radio   
   
   
获取设备 ID 和序列号   
   
   
adb get-product   
adb get-serialno   
   
   
   
访问数据库 SQLite3   
   
   
adb shell   
sqlite3   

上一篇:Android入门教程(四)之------Android工程目录结构介绍
下一篇:Android开发笔记第一篇(开放手机联盟--Open Handset Alliance)

相关帖子

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|新帖|标签|软件|Sitemap|ZNDS智能电视网 ( 苏ICP备2023012627号 )

网络信息服务信用承诺书 | 增值电信业务经营许可证:苏B2-20221768 丨 苏公网安备 32011402011373号

GMT+8, 2025-4-26 04:52 , Processed in 0.064354 second(s), 15 queries , Redis On.

Powered by Discuz!

监督举报:report#znds.com (请将#替换为@)

© 2007-2025 ZNDS.Com

快速回复 返回顶部 返回列表