我现在正在创建一个 SMS 广播接收器。我还在手机中使用 GoSMS。
问题是:如果我不设置android:priority
或设置值小于2147483647
(这是 GoSms 的优先级)
对于我的接收者,我无法收到消息。
当我设置时android:priority ="2147483647"
,我的应用程序可以接收消息,但是我手机中的一些应用程序已被强制关闭:
08-01 17:52:47.775: E/AndroidRuntime(3501): FATAL EXCEPTION: main
08-01 17:52:47.775: E/AndroidRuntime(3501): java.lang.RuntimeException: Unable to start service com.android.exchange.SmsRelayService@414f47f8 with Intent { cmp=com.android.exchange/.SmsRelayService (has extras) }: java.lang.NullPointerException
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2388)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.app.ActivityThread.access$1900(ActivityThread.java:127)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1222)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.os.Looper.loop(Looper.java:137)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.app.ActivityThread.main(ActivityThread.java:4507)
08-01 17:52:47.775: E/AndroidRuntime(3501): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 17:52:47.775: E/AndroidRuntime(3501): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 17:52:47.775: E/AndroidRuntime(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-01 17:52:47.775: E/AndroidRuntime(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-01 17:52:47.775: E/AndroidRuntime(3501): at dalvik.system.NativeStart.main(Native Method)
08-01 17:52:47.775: E/AndroidRuntime(3501): Caused by: java.lang.NullPointerException
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.provider.Telephony$Sms$Intents.getMessagesFromIntent(Telephony.java:888)
08-01 17:52:47.775: E/AndroidRuntime(3501): at com.android.exchange.SmsRelayService.onStartCommand(SmsRelayService.java:69)
08-01 17:52:47.775: E/AndroidRuntime(3501): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2371)
这是我的代码
public class SmsListener extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Constants.SMS_RECEIVED_ACTION)){
// Do some thing
}
}
}
和
<receiver android:name=".widget.SmsListener" >
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
我在 Galaxy S2、ICS 中运行
请帮帮我
问候