dimanche 17 mai 2015

Receiving SMS messages when app is closed

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

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

Aucun commentaire:

Enregistrer un commentaire