SMS 广播接收器只能在模拟器上调试
我有一个应用程序尝试捕获来自特定发件人的短信,然后启动新活动。当使用 Debug As 并使用模拟器我的 BroadcastReceiver 在 Eclipse 中运行时,它工作得很好,它按预期命中了断点。当我在 Eclipse 中使用 Run As 在模拟器中启动时,SMS 消息永远不会被捕获。由于缺少日志输出,似乎永远不会调用 BroadcastReceiver。在我的手机上运行时,短信也不会被捕获。任何想法为什么它以一种方式工作而不是另一种方式?
我手机上的应用程序很少,据我所知,唯一可以接收短信的应用程序是内置的即时通讯程序。
<receiver android:name=".sms.ConfirmationResponder">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
...
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
接收者:
public class ConfirmationResponder extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("SMS", "############################ Confirmation being read");
// More stuff after this but I don't even get the log message
}
}
I have an app that tries to catch SMS messsages from a specific sender and then starts a new activity. When running in Eclipse using Debug As and using emulator my BroadcastReceiver it works great, it hits the breakpoints as expected. When I use Run As in Eclipse to launch in the emulator the SMS messages never get caught. It appears the BroadcastReceiver is never called based on the lack of Log outputs. The SMSes also do not get caught when running on my phone. Any ideas why it works one way but not another?
I have very few apps on my phone and the only one I know of that catches text messages is the built-in messenger one.
<receiver android:name=".sms.ConfirmationResponder">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
...
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
The receiver:
public class ConfirmationResponder extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("SMS", "############################ Confirmation being read");
// More stuff after this but I don't even get the log message
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的程序:
和清单文件:
希望有帮助
Here is my program:
And the manifest file:
Hope it Helps
我认为它可以工作,但在“运行方式”模式下 Eclipse 未连接到设备并且不显示 logcat 信息。
I think it works but eclipse is not attached to device when "Run as" mode and do not show logcat info.