不能接收广播ICS [英] Cannot receive broadcast in ICS

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

问题描述

我写1的应用程序为Android 4.0,而且它通过BroadcastReceiver的开始。我的code是如下:

I writing 1 app for Android 4.0, and it's started via broadcastreceiver. My code is below:

在AndroidManifest.xml中:

In AndroidManifest.xml:

 <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name="com.Android.Exercise.StartUpReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <!--<action android:name="StartInstrument" /> 
                <action android:name="PrintControlName" />      -->     
            </intent-filter>
        </receiver>         
        <service android:enabled="true" android:name="StartAUT_Service">
            <intent-filter>
                <action android:name="com.Android.Exercise.StartAUT_Service" />
            </intent-filter>
        </service>  
    </application>

在StartU preceiver类:

In StartUpReceiver class:

public class StartUpReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i("Broadcast", "onReceive");

        Intent i = null;

        if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
             i = new Intent(context, StartAUT_Service.class);          
             i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        context.startService(i);            
    }       
}

在我重新启动我的设备,我无法接收broardcast。 请帮帮我,谢谢这么多

After I rebooted my device, I can not receive broardcast. Please help me, thank so much

推荐答案

从的Andr​​oid 3.0开始,应用状态进行了介绍。 所有的应用程序现在的状态设置为停用安装,使得它所有的BroadcastReceivers无效。

Starting from Android 3.0, application state was introduced. All applications are now installed with a state set to inactive, making all it's BroadcastReceivers inactive.

为使国家作为活动的,用户必须启动应用程序至少一次,操作系统会自动启动应用程序及其所有BroadcastReceivers。

To make the state as active, the user must launch the application at least once and the OS will automatically activate the app and all its BroadcastReceivers.

在你的情况,你需要添加一个活动,无论是许可协议或帮助页面。这将为你的应用程序的图标供用户点击并激活该应用程序。

In your case, you need to add an activity, be it a license agreement or a help page. This will create an icon for your app for the user to click and activate the app.

请注意,该应用程序的状态将被设置为不活动的备份,如果用户强制关闭应用程序。

Note that the application's state will be set to back inactive if the user force-closes the application.

我遇到了类似的问题:安卓ICS不接收数据短信

I faced a similar problem: Android ICS not receiving data sms

我希望解决您的问题,或者至少把你在正确的轨道。

I hope that solves your problem or at least put you on the right track.

问候, 艾哈迈德

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

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