3

I am developing an sms blocking app. Which is working fine up to Jelly-Bean. And its not working from Kitkat to Marshmallow. I searched on google and everyone recommending to take permission from user to make it default sms app of this phone by using .

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                if(!Telephony.Sms.getDefaultSmsPackage(getApplicationContext()).equals(getApplicationContext().getPackageName())) {
                    Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
                    intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
                            getApplicationContext().getPackageName());
                    startActivity(intent);
                }
            }

Manifest file :

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".DashboardActivity">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.SENDTO" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </activity>
    <activity android:name=".LoginActivity" />
    <activity android:name=".ContactListActivity" />
    <activity android:name=".CallLogListActivity" />
    <activity android:name=".SMSContactListActivity" />
    <activity android:name=".SettingsActivity" />

    <receiver
        android:name=".PhoneStateReceiver"
        android:enabled="true"
        android:permission="android.permission.BROADCAST_SMS">
        <intent-filter android:priority="9999">
            <action android:name="android.intent.action.PHONE_STATE" />
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.provider.Telephony.SMS_DELIVER" />
            <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
        </intent-filter>
    </receiver>

    <!-- Service that delivers messages from the phone "quick response" -->
    <service
        android:name=".HeadlessSmsSendService"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
        <intent-filter>
            <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </service>

    <activity android:name=".BlockedCallLogActivity" />
    <activity android:name=".BlockedSmsLogActivity" />
    <activity android:name=".AboutUsActivity" />
</application>

I used this code sample. It shows a dialog with messaging app of phone. My app is not showing on this list.

Now i want to show my app on this list also, so user can select my app from this list and it will be default sms app of that phone. How can i do that. Please reply with example/code-sample. Thanks.

AGM Tazim
  • 2,213
  • 3
  • 16
  • 25
  • 2
    http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html – CommonsWare Aug 16 '16 at 13:26
  • I followed it but not worked. My app is not shown on the list dialog. – AGM Tazim Aug 16 '16 at 13:36
  • 1
    Then post your entire manifest. Quoting the blog post that I linked to, "In order for your app to appear in the system settings as an eligible default SMS app, your manifest file must declare some specific capabilities". You have only shown one of these in your question so far. – CommonsWare Aug 16 '16 at 13:42
  • I edited my post. Posted full manifest file. – AGM Tazim Aug 16 '16 at 13:46

2 Answers2

8

I followed it

Not according to the code in your question. Let's review the four requirements from the blog post:

In a broadcast receiver, include an intent filter for SMS_DELIVER_ACTION ("android.provider.Telephony.SMS_DELIVER"). The broadcast receiver must also require the BROADCAST_SMS permission.

You have this, in the form of your PhoneStateReceiver.

In a broadcast receiver, include an intent filter for WAP_PUSH_DELIVER_ACTION ("android.provider.Telephony.WAP_PUSH_DELIVER") with the MIME type "application/vnd.wap.mms-message". The broadcast receiver must also require the BROADCAST_WAP_PUSH permission.

You do not have this.

In your activity that delivers new messages, include an intent filter for ACTION_SENDTO ("android.intent.action.SENDTO") with schemas, sms:, smsto:, mms:, and mmsto:.

You have this, in the form of DashboardActivity.

In a service, include an intent filter for ACTION_RESPONSE_VIA_MESSAGE ("android.intent.action.RESPOND_VIA_MESSAGE") with schemas, sms:, smsto:, mms:, and mmsto:. This service must also require the SEND_RESPOND_VIA_MESSAGE permission.

You have this, in the form of HeadlessSmsSendService.

So, add a <receiver> for WAP_PUSH_DELIVER_ACTION, following the instructions, and see if that helps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Use the below code in manifest file. It should work perfectly.

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".main.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".conversation.ConversationsActivity" />
    <!-- Activity that allows the user to send new SMS/MMS messages -->
    <activity
        android:name=".sendsms.SendSmsActivity"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.SENDTO" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </activity>
    <!-- BroadcastReceiver that listens for incoming SMS messages -->
    <receiver
        android:name=".receivesms.SmsReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.BROADCAST_SMS">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.provider.Telephony.SMS_DELIVER" />
        </intent-filter>
    </receiver>
    <!-- BroadcastReceiver that listens for incoming MMS messages -->
    <receiver
        android:name=".receivesms.MmsReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.BROADCAST_WAP_PUSH">
        <intent-filter>
            <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />

            <data android:mimeType="application/vnd.wap.mms-message" />
        </intent-filter>
    </receiver>

    <!-- Service that delivers messages from the phone "quick response" -->
    <service
        android:name=".service.SmsSendService"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
        <intent-filter>
            <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </service>
</application>
krisDrOid
  • 3,252
  • 3
  • 25
  • 36