I want that when the user press on the widget, the widget stops itself, and when the user press again, the widget put ON his functions
i'm using the solution of this post to achieve onClick on my widget: http://stackoverflow.com/questions/2748590/clickable-widgets-in-android The solution works fine in android 2.2 phone and android 4.1 phone but doesn't works on Nexus One with android 2.3.6. I click on the widget but nothing happens... This is my full widget class: public class mWidgetProvider extends AppWidgetProvider{ public static String ACTION_WIDGET_CLICK = "ActionWidgetClick"; public static final String ACTION_AUTO_UPDATE = "AUTO_UPDATE"; DecimalFormatSymbols symbols; DecimalFormat tempDecimalFormat; int pMaxFreq=-1; String cCurrentFreq=null; int freq = 0; float usage =-1; BufferedReader freqBufferedReader; PowerManager pm; RemoteViews remoteViews; ComponentName thisWidget; WidgetAlarm widgetAlarm; ActivityManager manager; @Override public void onDisabled(Context context) { super.onDisabled(context); context.stopService(new Intent(context, UpdateService.class)); //stop alarm widgetAlarm = new WidgetAlarm(context.getApplicationContext()); widgetAlarm.stopAlarm(); System.out.println("XXXXX onDISABLED"); } @Override public void onDeleted(Context context, int[] appWidgetIds) { super.onDeleted(context, appWidgetIds); System.out.println("XXXXX onDELETED"); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); context.startService(new Intent(context, UpdateService.class)); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); thisWidget = new ComponentName(context, CPUWidgetProvider.class ); //preparamos el evento para cuando el usuario presiona en el widget, ese evento será recibido en onReceive() Intent active = new Intent(context, CPUWidgetProvider.class); active.setAction(ACTION_WIDGET_CLICK); PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); remoteViews.setOnClickPendingIntent(R.id.fondo, actionPendingIntent); AppWidgetManager.getInstance(context).updateAppWidget( thisWidget, remoteViews ); // start alarm widgetAlarm = new WidgetAlarm(context.getApplicationContext()); widgetAlarm.startAlarm(); System.out.println("XXXXX onUPDATE"); } @Override public void onReceive(Context context, Intent intent){ if (intent.getAction().equals(ACTION_WIDGET_CLICK)){ switchWidget(context); }else if(intent.getAction().equals(ACTION_AUTO_UPDATE)){ symbols = new DecimalFormatSymbols(Locale.GERMAN); symbols.setDecimalSeparator('.'); tempDecimalFormat = new DecimalFormat("#.#", symbols); pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); thisWidget = new ComponentName(context, CPUWidgetProvider.class ); if (pm.isScreenOn()){ /* here i do some work to update the textviews of the widget */ AppWidgetManager.getInstance(context).updateAppWidget( thisWidget, remoteViews ); System.out.println("XXXXX UPDATING WIDGET"); } }else{ super.onReceive(context, intent); } System.out.println("XXXXX onRECEIVE: "+intent.getAction()); } @Override public void onEnabled(Context context) { super.onEnabled(context); System.out.println("XXXXX onENABLED"); } public void switchWidget(Context context){ symbols = new DecimalFormatSymbols(Locale.GERMAN); symbols.setDecimalSeparator('.'); tempDecimalFormat = new DecimalFormat("#.#", symbols); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); thisWidget = new ComponentName(context.getPackageName(), CPUWidgetProvider.class.getName()); widgetAlarm = new WidgetAlarm(context.getApplicationContext()); if (isMyServiceRunning(context)==true){ //si el widget está encendido la apagamos context.stopService(new Intent(context, UpdateService.class)); widgetAlarm.stopAlarm(); remoteViews.setTextViewText(R.id.freq,"HERE I CHANGE THE VALUE"); } else{ //si el widget está apagado lo encendemos context.startService(new Intent(context, UpdateService.class)); widgetAlarm.startAlarm(); remoteViews.setTextViewText(R.id.freq,"HERE I CHANGE THE VALUE"); } AppWidgetManager.getInstance(context).updateAppWidget(thisWidget,remoteViews); } private boolean isMyServiceRunning(Context context) { manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (UpdateService.class.getName().equals(service.service.getClassName())) { return true; } } return false; } public void getpMaxFreq(){ int freq = 0; try{ //HERE I DO SOME WORK } catch (Exception e){e.printStackTrace();} } } PD: i tryed also putting the intent in onEnabled() function, with the same result... didn't work on Nexus One 2.3.6 thanks -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

