如何取消/阻止在棉花糖中传播默认短信应用程序

时间:2017-03-06 12:15:57

标签: android broadcastreceiver

我正在处理一个小项目,该项目仅接收并显示特定号码的消息,并且不会显示在收件箱中,是否有任何方法可以阻止或取消默认的短信应用?提前感谢我附上了我的广播和清单代码

 public class reciever extends BroadcastReceiver {
       public String senderNumer=null;
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle=intent.getExtras();
            if (bundle!=null)
            {
                Object[] pdus= (Object[]) bundle.get("pdus");
               // String senderNumer=null;
                for (int i=0;i<pdus.length; i++)
                {
                   SmsMessage sms=SmsMessage.createFromPdu((byte[]) pdus[i]);
                     senderNumer=sms.getOriginatingAddress();
                    String message=sms.getDisplayMessageBody();
                }
    if (senderNumer.equals("+92*******") || senderNumer.equals("03*******"))
                {
                    Toast.makeText(context,senderNumer+ "Message Recieved By Special Num",Toast.LENGTH_SHORT ).show();
                    Intent actionIntent = new Intent(context, MainActivity.class);
                    actionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    actionIntent.putExtra("msg", senderNumer);
                    context.startActivity(actionIntent);
                    abortBroadcast();
                }
            }

清单文件

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <receiver android:name=".reciever" class=".reciever">
              <intent-filter android:priority="100000000" >
                 <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
             </intent-filter>

         </receiver>
    </application>

0 个答案:

没有答案