我面临着令人沮丧的问题.
我创建短信接收器,因为大多数在线和书籍的教程说.
AndroidManifest.xml中:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application android:name="roboguice.application.RoboApplication"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true" >
<!-- ... other stuffs here ... -->
<receiver android:name=".receivers.SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Run Code Online (Sandbox Code Playgroud)
SmsReceiver.java:
public class SmsReceiver extends BroadcastReceiver {
public static final String TAG = "SmsReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "SMS received!");
Toast.makeText(context, "SMS received.", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
虽然它在模拟器(Android 2.2)上正常工作,但它不适用于我的HTC Wildfire(Android 2.2.1,而不是root).
主要问题是我是Android新手,我完全不知道如何调试它.
我可以在接收短信时从我的HTC设备中找到一些有用的LogCat日志发送内容吗?为什么我的设备不同!?
ncr*_*ted 10
理由和解决方案:
我已经解决了这个问题."android.provider.Telephony.SMS_RECEIVED"无法正常工作,因为我的设备上安装了"GO SMS Pro"应用程序并且选中了"禁用其他消息通知"选项("禁用其他短信相关应用"通知栏中的通知,避免重复通知.").取消选中它解决了我的问题.
如何确保我的广播接收器即使其他应用程序阻止它也会收到此意图?由于"android:priority"(在Android中拦截短信并阻止它们出现在Messaging App中)我怎么知道为"GO SMS Pro"应用设置了什么"优先级"?
为了您的理由和解决方案:
Intent intent = new Intent("android.provider.Telephony.SMS_RECEIVED");
List<ResolveInfo> infos = getPackageManager().queryBroadcastReceivers(intent, 0);
for (ResolveInfo info : infos) {
System.out.println("Receiver name:" + info.activityInfo.name + "; priority=" + info.priority);
}
Run Code Online (Sandbox Code Playgroud)
只需查看GO SMS Pro废话的输出.它可能高得离谱.
| 归档时间: |
|
| 查看次数: |
9559 次 |
| 最近记录: |