Android:adb shell am命令行发送Activity/Service/Broadcast
来源:互联网 发布:netty 监听多个端口 编辑:程序博客网 时间:2024/05/19 22:28
0.adb shell am命名行参数
F:\>adb shell# amamusage: am [subcommand] [options] start an Activity: am start [-D] [-W] <INTENT> -D: enable debugging -W: wait for launch to complete start a Service: am startservice <INTENT> send a broadcast Intent: am broadcast <INTENT> start an Instrumentation: am instrument [flags] <COMPONENT> -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT) -e <NAME> <VALUE>: set argument <NAME> to <VALUE> -p <FILE>: write profiling data to <FILE> -w: wait for instrumentation to finish before returning start profiling: am profile <PROCESS> start <FILE> stop profiling: am profile <PROCESS> stop <INTENT> specifications include these flags: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] ...] [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...] [--esn <EXTRA_KEY> ...] [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...] [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...] [-n <COMPONENT>] [-f <FLAGS>] [--grant-read-uri-permission] [--grant-write-uri-permission] [--debug-log-resolution] [--activity-brought-to-front] [--activity-clear-top] [--activity-clear-when-task-reset] [--activity-exclude-from-recents] [--activity-launched-from-history] [--activity-multiple-task] [--activity-no-animation] [--activity-no-history] [--activity-no-user-action] [--activity-previous-is-top] [--activity-reorder-to-front] [--activity-reset-task-if-needed] [--activity-single-top] [--receiver-registered-only] [--receiver-replace-pending] [<URI>]#adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME
1. 启动activity/service
在adb shell中,通过am命令行启动一个Activity程序:
从superuser源代码中摘录一段使用示例:
am start -a android.intent.action.MAIN -n com.koushikdutta.superuser/com.koushikdutta.superuser.SuperuserRequestActivity --ei uid %d --ei pid %d
这个示例中:
-a 表示action (android.intent.action.MAIN)
-n 表示packagename (com.koushikdutta.superuser)
SuperuserRequestActivity是对应的Activity name
对应于AndroidManifest.xml文件中的描述。
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"android:versionCode="4" android:versionName="1.0.3" package="com.koushikdutta.superuser"><application android:icon="@drawable/icon" android:label="@string/app_name"android:debuggable="true"><activity android:name=".SuperuserActivity" android:label="Superuser Whitelist"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".SuperuserRequestActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></activity></application></manifest>
2.发送broadcast,比如在模拟器中发生关机的broadcast
F:\>adb shell am broadcast -a android.intent.action.ACTION_SHUTDOWN -c android.intent.category.HOME
-n com.andy.androidtest/.ShutdownBroadcastReceiver
结果:
Broadcasting: Intent { act=android.intent.action.ACTION_SHUTDOWN cat=[android.intent.category.HOME]
cmp=com.andy.androidtest/.ShutdownBroadcastReceiver }
Broadcast completed: result=0
相关源代码:
ShutdownBroadcastReceiver.java
public class ShutdownBroadcastReceiver extends BroadcastReceiver {private static final String TAG = "ShutdownBroadcastReceiver"; public ShutdownBroadcastReceiver() { } //Once boot completed,start server public void onReceive(Context context, Intent intent) {String action = intent.getAction();if (action.equals(Intent.ACTION_SHUTDOWN)){//Toast.makeText(context, "Ready to shutdown....", 1000);Log.v(TAG,"action:"+action);} }}
AndroidManifest.xml:
<receiver android:name=".ShutdownBroadcastReceiver" > <intent-filter> <action android:name="android.intent.action.ACTIOIN_SHUTDOWN" /> <action android:name="android.intent.action.QUICKBOOT_POWEROFF" /> </intent-filter> </receiver>
Logcat将抓到action:
10-26 02:37:01.684: V/ShutdownBroadcastReceiver(293): action:android.intent.action.ACTION_SHUTDOWN
- Android:adb shell am命令行发送Activity/Service/Broadcast
- Android:adb shell am命令行发送Activity/Service/Broadcast
- 通过命令行执行adb shell am broadcast发送广播通知。
- 通过命令行执行adb shell am broadcast发送广播通知。
- 在命令行通过adb shell am broadcast发送广播
- Android 通过adb shell am broadcast发送广播 adb命令
- Android:adb 启动activity、service,发送broadcast
- Android:adb 启动activity、service,发送broadcast
- Android:adb 启动activity、service,发送broadcast
- Android:adb 启动activity、service,发送broadcast
- Android:adb 启动activity、service,发送broadcast
- Android:adb 启动activity、service,发送broadcast
- Android 通过adb shell am broadcast发送广播
- Android 通过adb shell am broadcast发送广播
- Android 通过adb shell am broadcast发送广播
- 在命令行中通过adb shell am broadcast发送广播通知以及Android的常用adb命令
- 在命令行中通过adb shell am broadcast发送广播通知以及Android的常用adb命令
- 在命令行中通过adb shell am broadcast发送广播通知以及Android的常用adb命令
- Android Bitmap 透明度(Picture 透明度)
- 正则表达式3——匹配一组字符
- Linux下的getopt()函数
- 初学STL子仿函数和函数适配器之一
- 正则表达式4——使用元字符
- Android:adb shell am命令行发送Activity/Service/Broadcast
- hibernate的集合属性 .
- 百度、腾讯、搜狐、360等产品职位笔试智力题分析
- 正则表达式5——重复匹配
- WPF显示列表按字段排序
- poj 3259 bellman-ford
- HTML页面底脚浮动图片添加
- 图解ubuntu中修改计算机名
- 关于 'xterm': unknown terminal type的问题