九鼎创展论坛

标题: android命令行播放mp3 [打印本页]

作者: armeasy    时间: 2012-7-19 11:52
标题: android命令行播放mp3
android命令行播放mp3

在android的在命令行下,可以使用强大的am指令做很多事情。

在android终端输入am,正常情况下会有如下提示信息:
# am
usage: 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>]

#

启动的方法为:

# am start -n 包(package)名/包名.活动(activity)名称

启动的方法可以从每个应用的AndroidManifest.xml的文件中得到,以计算器(calculator)为例,

<?xml version="1.0" encoding=""?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

package="com.android.calculator2">

<applicationandroid:label="@string/app_name"android:icon="@drawable/icon">

<activity android:name="Calculator"

android:theme="@android:style/Theme.Black">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<categoryandroid:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

</application>

</manifest>

由此计算器(calculator)的启动方法为:

# am start-ncom.android.calculator2/com.android.calculator2.Calculator

Music的启动方法为:
# am start-ncom.android.music/com.android.music.MusicBrowserActivity

这时,屏幕上会有music的播放列表,但是并没有播放。如果需要播放,得执行下面的指令:

am start -n com.android.music/com.android.music.MediaPlaybackActivity -d /sdcard/liangliangxianwang.mp3







欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) Powered by Discuz! X3.2