我为了测试<action android:name="android.intent.action.BOOT_COMPLETED" />,希望在Android Emulator中模拟重启动作。

我能怎么做?谢谢!

和更多

如果我希望在重新启动Android Emulator中的电话后测试setPersisted(true)是否正常工作,该怎么办?

val jobInfo = JobInfo.Builder(mContext.getInteger(R.integer.JobID), ComponentName(mContext, RestoreService::class.java))
                        .setPeriodic(interval)
                        .setPersisted(true)
                        .build()


添加:

以下是myAndroidManifest.xml文件。

根据您的回答,代码A和代码B中哪一个是正确的?

还是代码A和代码都错了?

代码A

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/ui.UIApp


代码B

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/bll.BootReceiver


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.dodata.mirror">

    <application
        android:name="ui.UIApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name="ui.UIMain" android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name="ui.UIAbout">
            <intent-filter>
                <action android:name="ui.UIAbout" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>


        <receiver android:name="bll.BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

    </application>


</manifest>

最佳答案

通常,此ADB命令将发送任何广播,您可以使用调试器进行捕获:

adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME


这是一般的引导广播发送:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name


根据清单,首先添加到清单接收方enabledexported this:

<receiver
        android:name="bll.BootReceiver"
        android:enabled="true"
        android:exported="true">


关于类和清单的示例,ADB调用应如下所示:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/bll.BootReceiver

07-24 09:21