如何捕捉到系统广播BOOT_COMPLETED,我的计划是行不通的? [英] how to catch the system broadcast BOOT_COMPLETED, my program just doesn't work?

查看:88
本文介绍了如何捕捉到系统广播BOOT_COMPLETED,我的计划是行不通的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所著一个小程序来捕捉系统广播 BOOT_COMPLETED ,但它只是不工作:

I writed a small program to catch the system broadcast BOOT_COMPLETED, but it just doesn't work:

package com.alex.app.testsysreboot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("my_tag", "system reboot completed.......");
    }    
}

manifest.xml的

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.alex.app.testsysreboot"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name=".MyReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
</manifest>

我关上了AVD,然后点击Eclipse中的按钮运行,和Eclipse开始了新的AVD,但系统开机后,我看不出在日志中的LogCat中...

I closed the AVD, and then clicked the button "run" in Eclipse, and the Eclipse started a new AVD, but after the system boot, I just cannot see the log in the LogCat...

推荐答案

那么我想这和它的作品对我来说,

Well I tried this and it Works for me,

public class Autostart extends BroadcastReceiver 
{
    public void onReceive(Context arg0, Intent arg1) 
    {
        Log.i("Autostart", "**********started************");
    }
}

AndroidManifest文件

AndroidManifest file

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <receiver android:name=".Autostart">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
</manifest>

这篇关于如何捕捉到系统广播BOOT_COMPLETED,我的计划是行不通的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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