1

I have a ListView of SMSItem objects . When any new SMS arrives , it is shown in the ListView . But after clicking the ListView or if the activity is relaunched , the item is disappearing . The item is not showed in the ListView .

The most probably reason is beacause of changing manifest file. I am trying to set my app as default app . My manifest file is as follows :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.commlink.smscheck"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="20" />


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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".ShowIndividualSMS"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

          <receiver android:name=".SmsBroadcastReceiver"
                android:permission="android.permission.BROADCAST_SMS">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_DELIVER" /> 
            </intent-filter>
        </receiver>

        <!-- BroadcastReceiver that listens for incoming MMS messages -->
        <receiver android:name=".MmsReceiver"
            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>

        <!-- Activity that allows the user to send new SMS/MMS messages -->
        <activity android:name=".ComposeSmsActivity" >
            <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>

        <!-- Service that delivers messages from the phone "quick response" -->
        <service android:name=".HeadlessSmsSendService"
                 android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
                 android:exported="true" >
            <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>

</manifest>

If the manifest file is as follows then the problem is solved . The item in the list is not disappearing . But in this case , the app is not set as default .

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.commlink.smscheck"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="20" />


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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

       <receiver
            android:name=".SmsBroadcastReceiver"
            android:exported="true" >
            <intent-filter android:priority="999" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ShowIndividualSMS"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- BroadcastReceiver that listens for incoming MMS messages -->
        <receiver android:name=".MmsReceiver"
            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>

        <!-- Activity that allows the user to send new SMS/MMS messages -->
        <activity android:name=".ComposeSmsActivity" >
            <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>

        <!-- Service that delivers messages from the phone "quick response" -->
        <service android:name=".HeadlessSmsSendService"
                 android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
                 android:exported="true" >
            <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>

What is the reason that item in the list is not disappearing ? How can I solve this ?

Jas
  • 3,207
  • 2
  • 15
  • 45
osimer pothe
  • 2,827
  • 14
  • 54
  • 92
  • 1
    If the problem occurs when your app is the default SMS app, it sounds like you're not writing the message to the Provider. The default SMS app is responsible for saving all incoming messages. – Mike M. Oct 06 '15 at 04:15
  • Yes , I am not writing the message to the provider . How can I do that ? @MikeM. How can I save all incoming message ? – osimer pothe Oct 06 '15 at 04:16
  • 1
    Pretty much the same way as always. [This post](http://stackoverflow.com/questions/642076/how-to-save-sms-to-inbox-in-android) shows the basics. As of API 19, though, there are classes in `android.provider.Telephony.*` that provide convenient constants and methods that can be used in your default app. – Mike M. Oct 06 '15 at 04:26
  • Can you provide code of android.provider.Telephony.* that provide convenient constants and methods that can be used in my default app – osimer pothe Oct 06 '15 at 04:29
  • 1
    I mainly meant `Telephony.Sms.CONTENT_URI`, `Telephony.Sms.ADDRESS`, `Telephony.Sms.BODY`, etc. So you don't have to have String literals in your code, like the top answer in that link. – Mike M. Oct 06 '15 at 04:36
  • 1
    You can post this as answer . I will accept this . – osimer pothe Oct 06 '15 at 05:32

1 Answers1

1

Given your problem statement, it sounded like your app wasn't writing incoming messages to the SMS Provider when it was the default SMS app, which apparently was the case.

The default SMS app is responsible for writing all incoming messages to the Provider. When your app neglected to write the message, and then refreshed the ListView, the new message wouldn't be in the list returned from the inbox query.

The basics of writing an SMS message to the Provider haven't changed much since prior to the API going public. This post has several examples.

I would also point out, as of API 19, the android.provider.Telephony.Sms class exists, and contains some handy constants, e.g. Telephony.Sms.CONTENT_URI, Telephony.Sms.ADDRESS, Telephony.Sms.BODY, etc.

Community
  • 1
  • 1
Mike M.
  • 38,532
  • 8
  • 99
  • 95