Jellybean上的android.intent.action.BOOT_COMPLETED

时间:2014-06-30 12:35:29

标签: java android android-intent

我正在努力让我的意图开始启动,基本上服务没有出现在我的运行或缓存进程中。我知道从3.1开始你必须有一个运行服务才能运行的活动,所以这就是我所拥有的

MainActivity

 import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.Toast;

    public class StartActivity extends Activity {


        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            Context context = getApplicationContext();
            CharSequence text = "Updater Started";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            startService(new Intent(this,UpdaterService.class));
            finish();

        }

    }

我的意图

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class StartIntent extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent myIntent = new Intent(context, UpdaterService.class);
        context.startService(myIntent);

        CharSequence text = "Updater Started";
        int duration = Toast.LENGTH_SHORT;


        Toast toast = Toast.makeText(context, text, duration);
        toast.show();



    }

}

最后我的appmanifest

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />



    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoDisplay">
        <activity
            android:name="com.package.removed.StartActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:enabled="true" android:name=".StartIntent" android:exported="false" />
        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
    </application>

</manifest>

基本上我的祝酒词从未显示过,有谁知道我错过了什么?

1 个答案:

答案 0 :(得分:3)

您的intent-filter位于receiver之外。它应该是这样的:

<receiver android:enabled="true" android:name=".StartIntent" android:exported="false" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>