1

i'm working on a little project which receive and show Message only by specific number,and don't show in inbox, is there is any method to prevent or cancel the default sms app?thanks in advance i'm attaching my code of Broadcasting and Manifest

 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();
                }
            }

Manifest file

<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>
roalz
  • 2,699
  • 3
  • 25
  • 42
Learner313
  • 11
  • 7
  • you can something like delete SMS from the device storage after you know it is your SMS. – Vladyslav Matviienko Mar 06 '17 at 12:23
  • but how can i delete Desired/Specific SMS from storage? but if i delete from storage then it will also disappear from my own app? – Learner313 Mar 06 '17 at 12:26
  • if you save it separately, then it won't disappear from your app. – Vladyslav Matviienko Mar 06 '17 at 12:28
  • To delete SMS simply search for `android delete sms programmatically` – Vladyslav Matviienko Mar 06 '17 at 12:28
  • hmm thanks, after searching i'll be here – Learner313 Mar 06 '17 at 12:31
  • i guess you can not delete the sms storage unless your app is the default sms app. – siva Mar 06 '17 at 13:12
  • @7383 so it is possible that first i make it default and then store sms in my own app DB and then i can delete sms from main DB and then show it? – Learner313 Mar 06 '17 at 14:12
  • Only the user can set the default messaging app. You cannot do it yourself programmatically. There really is no way to block incoming messages in Marshmallow unless the user has chosen your app to be the default. – Mike M. Mar 06 '17 at 14:54
  • @MikeM. So its clear without default app we can't delete or hide messages from main DB, will u please provide some links regarding making default app and how to delete sms ? – Learner313 Mar 06 '17 at 15:42
  • http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html, http://stackoverflow.com/a/30133663, http://stackoverflow.com/q/8614211 – Mike M. Mar 06 '17 at 15:53

0 Answers0