2014-09-27 85 views
1

我想在我的应用中收到短信,但我不希望我的Android显示关于该事件的通知。短信接收不通知android 4.4.2

我是申报

<receiver android:name="mypackage.SMSReceiver"> 
    <intent-filter> 
    <action android:name="android.provider.Telephony.SMS_RECEIVED"/> 
    </intent-filter> 
</receiver> 

<uses-permission android:name="android.permission.RECEIVE_SMS" /> 

编写的代码

public class SMSReceiver extends BroadcastReceiver 
{ 
    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
    Bundle extras = intent.getExtras(); 

    Object[] pdus = (Object[])extras.get("pdus"); 
    for (Object pdu: pdus) 
    { 
     SmsMessage msg = SmsMessage.createFromPdu((byte[])pdu); 

     String origin = msg.getOriginatingAddress(); 
     String body = msg.getMessageBody(); 

     // Parse the SMS body 
     if (isMySpecialSMS) 
     { 
     // Stop it being passed to the main Messaging inbox 
     abortBroadcast(); 
     } 
    } 
    } 
} 

,并尝试设置优先级

<intent-filter android:priority="100"> 

但不行!电话显示通知!

拥有的是Android 4.4.2(API 19)(注三星3)

回答

1

与奇巧(4.4),您的应用程序将需要为了抑制通知默认的短信应用,作为默认的应用程序正在启动负责发布它们。试图中止SMS_RECEIVED广播不再有效。系统忽略任何中止广播的企图。此外,默认应用程序将侦听广播,该广播无法中止,因为广告仅传递到默认应用程序。您可以参考以下链接了解如何让您的应用成为默认的短信应用。

Getting Your SMS Apps Ready for KitKat