android.permission.RECEIVE_BOOT_COMPLETED不起作用 [英] android.permission.RECEIVE_BOOT_COMPLETED does not work

查看:85
本文介绍了android.permission.RECEIVE_BOOT_COMPLETED不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序在启动时启动,但是以下代码不起作用.我看到了更多类似的线程,但是找不到适合我的解决方案.

I want my application to start at bootup, but the following code does not work. I have seen few more similar threads, but unable to find a solution that works for me.

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:largeHeap="true"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
            android:name="app.com.blynq.services.BootReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

    </application>

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

我的广播接收器:

public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {

        Intent pushIntent = new Intent(context, MainActivity.class);
        pushIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(pushIntent);
    }
}

我错过了一些非常琐碎的事情吗?我使用的这种权限组合不寻常吗?

Am I missing something very trivial ? Is this combination of permissions I've used are unusual ?

推荐答案

包括完整的启动权限:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

这篇关于android.permission.RECEIVE_BOOT_COMPLETED不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆