爲了趕上android.intent.action.BOOT_COMPLETED
事件,只需在AndroidManifest.xml
中註冊BroadcastReceiver
就足夠了嗎?像這樣:爲了捕獲BOOT_COMPLETED,僅僅在`AndroidManifest.xml`中註冊BroadcastReceiver就足夠了?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myDomain.myApp"
android:installLocation="internalOnly">
<!-- ... stuff ... -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- ... stuff ... -->
<application ...>
<!-- ... stuff ... -->
<receiver android:name=".bgServices.MyBootBroadcastReceiver">
</receiver>
<!-- ... stuff ... -->
</application>
</manifest>
的BroadcastReceiver
:
package com.myDomain.myApp.bgServices;
// imports ...
public class MyBootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("my-log", "MyBootBroadcastReceiver.onReceive()");
Toast.makeText(context, "YEAY!", Toast.LENGTH_LONG).show();
}
}
我這麼問是因爲我要送:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.myDomain.myApp/.bgServices.MyBootBroadcastReceiver
但沒有任何反應。
(我運行的應用程序,不只是推到設備)
@jankigadhiya,看到我的文章的最後一行:「(我運行的應用程序,不只是推到設備)」 – Tar