广播接收器Android版 [英] BroadCastReceiver Android

查看:162
本文介绍了广播接收器Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android的新手真的,我在我的项目有难治与广播接收器。

I'm realy newbie in android, and i'm having dificult with broadcastreceiver in my project.

我创建使用许可权,并在AndroidManifest.xml接收器,创建的类,但它不是通过在logcat的消息。

I've created uses-permission and the receiver in AndroidManifest.xml, created the class but it not passing on the logcat message.

我的Receiver类

package com.polifrete.polifreteFunctions;

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) {
        // TODO Auto-generated method stub
        Log.i("Script", "Passou AQUI");
        Intent i = new Intent(context, VerificaNovoFreteService.class);
        context.startService(i);
    }
}

我的Andr​​oidManifest.xml

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

    <receiver android:name="com.polifrete.polifreteFunctions.MyReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
    </receiver>

我在做什么错了?请帮帮我!

What i'm doing wrong? Please, help me!

推荐答案

不是每个手机发送 BOOT_COMPLETED 广播。举例来说,我认为这是HTC,发送 QUICKBOOT_POWERON 广播,如果有启动。此外,您的logcat的是也许不是在启动时,时间连接到您的手机。我建议创建一个吐司来检查,你阉引导Reciever 执行

Not every Phone sends the BOOT_COMPLETED Broadcast. For example, I think it was HTC, sends the QUICKBOOT_POWERON Broadcast, if it has boot up. Also your logcat is maybe not connected to your phone at Boot-Up-Time. I'd suggest to create a Toast to check, wether your Boot-Reciever is executed.

您可以创建此吐司这个code:

You can create this Toast with this code:

Toast toast = Toast.makeText(getApplicationContext(), "Boot-Reciever Started", Toast.LENGT_LONG);

这篇关于广播接收器Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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