启动应用程序没有活动,我的广播接收机无法正常工作 [英] Start application without activity, my Broadcast Receiver not work

查看:156
本文介绍了启动应用程序没有活动,我的广播接收机无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有一个广播接收器捕捉发送到我的手机信息

In my app, I have a Broadcast Receiver for catching the message sent to my phone

<receiver
            android:name="com.qmobile.ows.SMS_Receiver"
            android:enabled="true" 
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />                  
            </intent-filter>
</receiver>

如果我开始与活动的GUI应用程序,广播接收器正常工作。

If I start app with activity GUI, the BroadCast Receiver works normally.

我要开始我没有活动的应用程序和不显示图标的应用程序,所以我的删除这code以下从我的活动

I want to start my application without activity and do not show icon app, so I remove this code below from my activity

 <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>

在这之后,广播接收器不工作。

And after that, Broadcast Receiver do not work.

请帮我解决这个问题。

推荐答案

这是因为Android操作系统不允许广播接收器收到一些重要广播( android.provider.Telephony.SMS_RECEIVED 必须是它的一个),如果app's过程不alive.It的目的是要对抗邪恶的应用程序。如果你有一个活动的运行,你的过程是活的,所以你的接收器被允许接收广播。

This is because Android OS does not allow BroadcastReceiver to receive some important broadcast(android.provider.Telephony.SMS_RECEIVED must be one of it) if the app´s process is not alive.It was designed to against the evil apps. If you have an activity running,your process is alive and so your receiver is allowed to receive the broadcast.

我觉得你可以做一个透明 活动并使用startService启动服务在后台,然后完成活动。作为您的服务正在运行,你的进程是活的,所以Android操作系统将会让你接收广播。

I think you can make a transparent activity and use startService to start a service in background,then finish the activity.As your service is running ,your process is alive,so the Android OS will let you to receive the broadcast.

这篇关于启动应用程序没有活动,我的广播接收机无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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