简体   繁体   English

设备启动完成后无法启动服务。 引导完成的BroadcastReceiver onReceive()未调用

[英]Unable to start Service after Device Boot Completed. Boot Completed BroadcastReceiver onReceive() not Calling

I am working on one app which will start a service automatically at device start ( after boot complete ). 我正在开发一个应用程序,它将在设备启动时(启动完成后)自动启动服务。 i did code but i think something is going wrong with my code. 我做了代码,但是我认为我的代码出了点问题。 i have tried google too and all the tricks while research. 我也尝试过Google以及研究时的所有技巧。 can you please help me? 你能帮我么? Thanx in advance. 提前感谢。

here is my code : 这是我的代码:

My BroadcastReceiver is 我的BroadcastReceiver是

public class AutostartReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Toast.makeText(this, "Booting Completed", Toast.LENGTH_LONG).show(); 
            //context.startService(new Intent(context, MyService.class));
        }
    }
}

My AndroidMenifest file is 我的AndroidMenifest文件是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myhiddenapp"
    android:installLocation="internalOnly"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="MyHiddenApp" >
        <receiver
            android:name=".AutostartReceiver"
            android:enabled="true"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

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

</manifest>

Note : I have not any Activity, i just want to start Service on Boot Complete. 注意: 我没有任何活动,我只想在启动完成时启动服务。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="internalOnly"
    ... >

You Must set android:installLocation="internalOnly" 您必须设置android:installLocation =“ internalOnly”

https://developer.android.com/guide/topics/data/install-location.html#Should https://developer.android.com/guide/topics/data/install-location.html#应该

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM