美文网首页
am命令用法

am命令用法

作者: 12313凯皇 | 来源:发表于2020-10-20 16:13 被阅读0次

以下是平时自己感觉会常用的命令,摘要出来:

Activity

# 启动Activity
am start -W com.example.test/.MainActivity
# 停止应用
am force-stop com.example.test

-W表示等待app启动完成。

Service

# 启动service
am start-service -a com.example.test.SERVICE1 -n com.example.test/.service.TestService1
# 停止service (暂为验证)
am stopservice com.example.test.SERVICE1

参数说明

参数名 作用
-a 指定Intent action,同intent.setAction()
-n 指定组件名,格式为{包名}/.{主Activity名},同intent.setComponent()

BroadCast

# 发送广播
am broadcast -a com.example.test.PRESSURE -n com.example.test/.receiver.Receiver1 --es cmd start 
参数名 作用
-a 指定Intent action,同intent.setAction()
-n 指定组件名,格式为{包名}/.{主Activity名},同intent.setComponent()
--es 设置String类型的extra值}

Extra

参数名 作用
--es 设置String类型的extra值
--esn 设置String类型的extra值为null
--ez 设置boolean类型的extra值}
--ei 设置int类型的extra值}
--el 设置long类型的extra值}
--ef 设置float类型的extra值}
--eu 设置uri类型的extra值}
--ecn 设置component类型的extra值}

这里仅使用了-es,其他参数暂为验证。

参考文章:

相关文章

网友评论

      本文标题:am命令用法

      本文链接:https://www.haomeiwen.com/subject/lbydmktx.html