gpt4 book ai didi

android - 手机启动时服务没有启动

转载 作者:行者123 更新时间:2023-11-30 05:10:45 24 4
gpt4 key购买 nike

我是 android 编程的新手。我试图在手机启动时启动一项服务,但它不起作用。我已经看到其他用户提出的其他问题,但直到现在还没有人工作过。这是我的广播接收器。

public class StartBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent intent1 = new Intent(context,MyService.class);
context.startService(intent1);
}
}
}

这是我的 list

<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=".StartBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>

<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
</application>

我在日志中看到了这个

W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.android.apps.docs/.app.NotificationChannelReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)

提前感谢您的回答

最佳答案

删除

<category android:name="android.intent.category.DEFAULT"/>

来自 <intent-filter>里面<receiver>标签。只有 <intent-filter> 才需要此类别<activity> 内部声明。对于 <receiver>你只需要行动。

您发布的错误消息与您的应用程序无关,它是在提示另一个应用程序。

关于android - 手机启动时服务没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53795330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com