Android的 - 广播接收器工作在模拟器不上电话 [英] Android - Broadcast Receiver works on Emulator Not on Phone
本文介绍了Android的 - 广播接收器工作在模拟器不上电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个简单的应用程序,它只是ATM弹出敬酒消息在网络状态发生变化时。这工作完全在模拟器上,但我试图在2个不同的Android手机,它看起来像广播reciever决不会在这些事件触发。
这是我的广播reciever:
I have written a simple app which atm just pops up a toast message when the network state changes. This works perfectly on the emulator but I've tried it on 2 different android phones and it seems like the broadcast reciever is never trigger on these events. This is my broadcast reciever:
public class PhoneStateReceiver extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
Toast.makeText( context, "Hi", Toast.LENGTH_SHORT ).show();
}
}
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
..
<uses-sdk android:minSdkVersion="8" />
<application
..
<receiver android:name=".PhoneStateReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>
</intent-filter>
</receiver>
..
</application>
<!-- Needed to check when the network connection changes -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
任何人都知道为什么会这样还是什么我可能做错了?
Anyone know why this is happening or what I might have done wrong?
谢谢,
罗布
推荐答案
我找不到任何东西显然是不正确在code,所以这里是一个尽力而为的。
I can't find anything obviously incorrect in your code, so here is a best-effort.
在您的清单中把块在
PVS
这篇关于Android的 - 广播接收器工作在模拟器不上电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文