Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Fri May 18, 2012 4:04 pm

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

1

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by MYMNTWEME on Fri May 18, 2012 12:01 pm in Amministrazione

26

12405

Fri May 18, 2012 12:01 pm

MYMNTWEME

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

44

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

186

Tue May 15, 2012 10:44 am

deran

No new posts Applicazione inserimento eventi

by mauro21 on Mon May 14, 2012 9:20 pm in Sviluppo e programmazione in Android

0

22

Mon May 14, 2012 9:20 pm

mauro21




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Aggiornare widget da sms
PostPosted: Wed May 11, 2011 8:47 am 
Offline
User avatar

Joined: Sun May 01, 2011 9:28 am
Posts: 12
Operatore: 3
Punti Android: ?
Ciao, non mi è molto chiaro come procedere. Ho una Classe:

public class SmsReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
... leggo l'sms e lo processo ...
}
}

E un'AppWidget con un bottone e una textview:
public class MyWidget extends AppWidgetProvider
{
public static String ACTION_WIDGET_UPDATESMS = "ActionUpdateSmsWidget";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
... inizializzazione dell'azione che dal bottone lancia un'activity -> Questo funziona
}
}

Come ho scritto il bottone funziona e richiama un'altra activity che fa altri lavori, ma se volessi invece dalla classe SmsReceiver aggiornare il contenuto a video della textview del widget passando dei parametri?


Top
 Profile  
 
 Post subject: Re: Aggiornare widget da sms
PostPosted: Fri May 13, 2011 11:05 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Sethi wrote:
..ma se volessi invece dalla classe SmsReceiver aggiornare il contenuto a video della textview del widget passando dei parametri?

In Android, due activity o due classi che derivano dalle activity possono comunicare tra loro attraverso gli intent (eventi), che possono contenere i parametri che devono essere trasferiti.
Quindi per fare quello che dici dalla classe SmsReceiver puoi creare un intent esplicito con delle istruzioni del tipo:
Code:
Intent i = new Intent(this, MyWidget.class);
i.putExtra("Valore1", "Valore 1 per la classe MyWidget");
i.putExtra("Valore2", "Valore 2 per la classe MyWidget");
// Set the request code to any code you like, you can identify the callback via this code
startActivityForResult(i, REQUEST_CODE);

Sulla classe Mywidget puoi processare l'intent con un qualcosa del tipo:
Code:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle bundle) {
   super.onCreate(bundle);
   setContentView(R.layout.second);
   Bundle extras = getIntent().getExtras();
   String value1 = extras.getString("Valore1");
   String value2 = extras.getString("Valore2");
   //.......
}


Top
 Profile  
 
 Post subject: Re: Aggiornare widget da sms
PostPosted: Sat May 14, 2011 1:54 pm 
Offline
User avatar

Joined: Sun May 01, 2011 9:28 am
Posts: 12
Operatore: 3
Punti Android: ?
Grazie del consiglio! Nel frattempo ho risolto con un metodo che forse è un po' tarocco, ma funziona:

Code:
strMsg = context.getResources().getString(R.string.stringTextCpuList) + SmsHandling.TipoEvento() + " " + Traduttore.descrizioneCentrale(context, SmsHandling.Cpu());
                RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.main);
                updateViews.setTextViewText(R.id.StatoSistema, strMsg);

                // Push update for this widget to the home screen
                ComponentName thisWidget = new ComponentName(context, MyWidget.class);
                AppWidgetManager manager = AppWidgetManager.getInstance(context);
                manager.updateAppWidget(thisWidget, updateViews);


Che ne dici? A livello di concetto è comunque corretto o è un'accrocchio non proprio "bello" da vedere?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.