Android广播接收器未启动(Kotlin)
几周前,我在Java中安装了一个广播接收器,现在我想在Kotlin中安装,但不幸的是,它无法工作 我的舱单:Android广播接收器未启动(Kotlin),android,kotlin,broadcastreceiver,Android,Kotlin,Broadcastreceiver,几周前,我在Java中安装了一个广播接收器,现在我想在Kotlin中安装,但不幸的是,它无法工作 我的舱单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.test" android:installLocation="internalOnly">
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.test.test.BootReceiver"
android:enabled="true"
android:exported="true"
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
当我重新启动设备(Android 8.0.0)时,它不会启动服务。我跑步的时候也一样
adb shell
am broadcast -a android.intent.action.BOOT_COMPLETED
与
但它确实有效。我的代码有什么问题?启动完成的广播接收器已被弃用,不再工作。哦,我不知道。有什么东西可以让我的服务在启动后启动吗?嗯,当它被弃用的时候?文档中没有找到任何内容。我找到了,但没有任何更改。还尝试添加android:priority=“500”检查您的代码,它对我有效。你是否尝试打开你的应用程序?安装后至少需要打开一次
<receiver android:name="com.example.startuptest.StartUpBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" /> // add this line
</intent-filter>
am broadcast -a android.intent.action.BOOT_COMPLETED -n com.test.test/.Bootreceiver
<receiver android:name="com.example.startuptest.StartUpBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" /> // add this line
</intent-filter>
private fun startWork(context: Context) {
Log.d("Test", "Test") // remove this and toast
Toast(context,"Test", Toast.LENGTH_SHORT).show()
}