Autore Topic: app SMS - salvataggio SMS ricevuto  (Letto 595 volte)

Offline teo_

  • Utente junior
  • **
  • Post: 70
  • Respect: +1
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S
  • Sistema operativo:
    Windows 7 - Ubuntu 11.10
Re:app SMS - salvataggio SMS ricevuto
« Risposta #15 il: 11 Settembre 2011, 00:58:24 CEST »
0
ho risolto, faccio direttamente venire fuori una notifica e poi faccio aggiornare la listview di messaggi in questo modo

Codice (Java): [Seleziona]
public void onReceive(Context context, Intent intent)
        {
                //---get the SMS message passed in---
                Bundle bundle=intent.getExtras();
                SmsMessage[] msgs=null;
                String str="";
                if(bundle!= null)
                {
                        //richiama l'sms ricevuto
                        Object[] pdus=(Object[])bundle.get("pdus");
                        msgs=new SmsMessage[pdus.length];
                       
                        String address="";
                        String message="";
                        String nomeContatto="";
                       
                        for(int i=0;i<msgs.length;i++)
                        {
                                msgs[i]=SmsMessage.createFromPdu((byte[])pdus[i]);
                                address = msgs[i].getOriginatingAddress();
                                message = msgs[i].getMessageBody().toString();
                        }
                        //mostra il messaggio
                        //Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
                       
                        con=context;
                        address=removePrefix(address);
                       
                        nomeContatto=isInRubrica(address);
                       
                        String ns = Context.NOTIFICATION_SERVICE;
                        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
                       
                        int icon = R.drawable.icon;
                        CharSequence tickerText = "Sms da "+address+": "+message;
                        long when = System.currentTimeMillis();
                        Notification notification = new Notification(icon, tickerText, when);
                       
                        CharSequence contentTitle = address;
                        CharSequence contentText = message;
                        Intent notificationIntent = new Intent(context, SMSConversation.class);
                        String pkg=context.getPackageName();
                       
                        notificationIntent.putExtra(pkg+".myContact", address);
                        if(nomeContatto!=null) {
                                notificationIntent.putExtra(pkg+".myContactName", nomeContatto);
                        }
                        else notificationIntent.putExtra(pkg+".myContactName", address);
                       
                        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
                        notification.setLatestEventInfo(context.getApplicationContext(), contentTitle, contentText, contentIntent);
                       
                        mNotificationManager.notify(NOTIFICATION_ID, notification);
                       
                }
        }

GRAZIE MILLE PER L'AIUTO A ENTRAMBI!!!!!