Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I receive SMS messages when app is closed?
Following code works fine, but when app is closed, e.g. after reboot, It doesn't work. (Actually, it works just first few minutes after app is closed, Strange...)

My AndroidManifest.xml
XML
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
    <activity ....>
    ....
    </activity>

    <receiver android:name=".Receiver" android:exported="true" android:enabled="true">
        <intent-filter android:priority="1">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
</application>


My Receiver.java

public class Receiver extends BroadcastReceiver
{
    @Override public void onReceive(Context context, Intent intent)
    {
        if(cond)
        {
            abortBroadcast();
            Toast.makeText(context, "Registration Completed", Toast.LENGTH_LONG).show();
        }
    }
}
Posted
Comments
Sergey Alexandrovich Kryukov 17-May-15 15:04pm    
When an application is really closed, it's a bit too late to receive messages. :-)
Perhaps you mean when the application is about to be closed? Or when it is started again, after being closed? Please explain everything properly.
—SA
Member 11695946 18-May-15 16:49pm    
I'm still looking for a solution. Can you please help, if you can?
Sergey Alexandrovich Kryukov 18-May-15 17:01pm    
Not sure, sorry. :-)
—SA
Member 11695946 18-May-15 19:31pm    
Thank you anyway, and... DON'T BE SORRY, please :)
Member 11695946 17-May-15 17:34pm    
All I want is that check if received message is from a specific number, call abortBroadcast() and place it's content on sqlite database to process it later in PhoneGap. I need Something similar to push notification, but It should be based on text messaging. The app needs to receive text messages even when it is really closed. I believe third party sms messaging apps and sms blacklist apps use same thing that I want. Every bit of code is written and working fine, but it doesn't work when app is closed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900