io uso questo codice, come BroadcastReceiver:
public void onReceive(Context context, Intent intent)
{
//this stops notifications to others
this.abortBroadcast();
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
from = msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
msg = msgs[i].getMessageBody().toString();
str += "\n";
}
if(checksomething){
//make your actions
//and no alert notification and sms not in inbox
}
else{
//continue the normal process of sms and will get alert and reaches inbox
this.clearAbortBroadcast();
}
}
ricordati di aggiungerlo nel manifesto e aggiungi una priorità higgest (100) per la trasmissione o sms andrà prima a casella di posta elettronica e ottenere la notifica di avviso.
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
Spero che ti aiuti.
beh, ho bisogno che Android NON mostri la notifica di "nuovo messaggio" predefinita se la mia applicazione ha già gestito gli SMS in arrivo. Quindi questo è un requisito importante per la migliore esperienza utente :( –
beh ci sono molti thread su StackOverflow che ti diranno che non è possibile senza usare le tue classi estese di quelli che sono nascosti ....... ma sì sei pallido attendere la risposta di altri anche ........ – viv
Ora abortBroadcast(); metodo può essere utilizzato per limitare il messaggio in arrivo per andare in Posta in arrivo. – AB1209