android - Not Clickable Button -


on code below action_widget_clicked doesn't work... knows why? my_widget_update works fine. toast on receive never see intent.getaction() of action_widget_clicked. seems went somewhere wrong , button click doesn't create broadcast...

i've distinguish click between istances, every istances of widget has different action on action_widget_clicked. example: on updateappwidget i've pass toast appwidgetid of widget clicked

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="it.fraschi.controllogiardinowg"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="it.fraschi.controllogiardinowg.configurazione"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.appwidget.action.appwidget_configure"/>             </intent-filter>         </activity>         <receiver android:name="controllowidget" android:label="@string/app_name">             <intent-filter>                 <action android:name="android.appwidget.action.appwidget_update" />                 <action android:name="it.fraschi.controllogiardinowg.controllowidget.action_widget_clicked"/>                 <action android:name="it.fraschi.controllogiardinowg.controllowidget.my_widget_update" />             </intent-filter>             <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" />         </receiver>     </application>  </manifest> 

widget code:

public class controllowidget extends appwidgetprovider {     public static string action_widget_clicked = "it.fraschi.controllogiardinowg.controllowidget.action_widget_clicked";     public static string my_widget_update = "it.fraschi.controllogiardinowg.controllowidget.my_widget_update";     static string strwidgettext = "";     public static boolean choice = false;          @override          public void onreceive(context context, intent intent) {           // todo auto-generated method stub           super.onreceive(context, intent);           toast.maketext(context, intent.getaction(), toast.length_long).show();           if(my_widget_update.equals(intent.getaction())){               bundle extras = intent.getextras();                if(extras!=null) {                 appwidgetmanager appwidgetmanager = appwidgetmanager.getinstance(context);                 componentname thisappwidget = new componentname(context.getpackagename(), controllowidget.class.getname());                 int[] appwidgetids = appwidgetmanager.getappwidgetids(thisappwidget);                  onupdate(context, appwidgetmanager, appwidgetids);                }               toast.maketext(context, "autoupdate", toast.length_long).show();           }           if(action_widget_clicked.equals(intent.getaction())){                 bundle extras = intent.getextras();                     /*if(extras!=null) {                         appwidgetmanager appwidgetmanager = appwidgetmanager.getinstance(context);                         componentname thisappwidget = new componentname(context.getpackagename(), controllowidget.class.getname());                         int[] appwidgetids = appwidgetmanager.getappwidgetids(thisappwidget);*/                         choice=true;                         toast.maketext(context, "widget premuto", toast.length_long).show();                         //onupdate(context, appwidgetmanager, appwidgetids);                // }              }          }          @override         public void onenabled(context context) {             // todo auto-generated method stub             //super.onenabled(context);              toast.maketext(context, "onenabled()", toast.length_long).show();         }          @override         public void onupdate(context context, appwidgetmanager appwidgetmanager,int[] appwidgetids) {             // todo auto-generated method stub             //super.onupdate(context, appwidgetmanager, appwidgetids);              final int n = appwidgetids.length;             (int i=0; i<n; i++) {                 int appwidgetid = appwidgetids[i];                  updateappwidget(context, appwidgetmanager, appwidgetid);               }              remoteviews remotewidget = new remoteviews(context.getpackagename(),r.layout.widget);           }            public static void updateappwidget(context context, appwidgetmanager appwidgetmanager,int appwidgetid){                 //testonclick                remoteviews remoteviews = new remoteviews(context.getpackagename(),r.layout.widget);                intent active2 = new intent(context, controllowidget.class);                active2.setaction(action_widget_clicked);                pendingintent actionpendingintent2 = pendingintent.getbroadcast(context, appwidgetid, active2, 0);                remoteviews.setonclickpendingintent(r.id.btnesegui, actionpendingintent2);                  if (choice){                     remoteviews updateviews = new remoteviews(context.getpackagename(), r.layout.widget);                     updateviews.settextviewtext(r.id.btnesegui, "[" + string.valueof(appwidgetid) + "]" + strwidgettext + configurazione.getcolor(context, configurazione.nome, appwidgetid));                     appwidgetmanager.updateappwidget(appwidgetid, updateviews);                      toast.maketext(context, "esecuzione_ " + string.valueof(appwidgetid), toast.length_long).show();                  }else{                         int number = (new random().nextint(100));                         strwidgettext = integer.tostring(number);                          remoteviews updateviews = new remoteviews(context.getpackagename(), r.layout.widget);                         updateviews.settextviewtext(r.id.btnesegui, "[" + string.valueof(appwidgetid) + "]" + strwidgettext + configurazione.getname(context, configurazione.nome, appwidgetid));                         appwidgetmanager.updateappwidget(appwidgetid, updateviews);                          log.d("log_update", "log update, widget n."+string.valueof(appwidgetid));                         //toast.maketext(context, "update_" + string.valueof(appwidgetid), toast.length_long).show();                     }         } 

it seems don't call appwidgetmanager.updateappwidget(...) on correct instance of updateviews setonclickpendingintent called. should like:

final remoteviews updateviews = new remoteviews(context.getpackagename(), r.layout.widget_layout);             updateviews.settextviewtext(...); ... intent intent = new intent(context, mywidget.class); intent.setaction(action_widget_clicked+string.valueof(appwidgetid)); pendingintent pendingintent = pendingintent.getbroadcast(context, 0, intent, 0); updateviews.setonclickpendingintent(r.id.mywidget_id, pendingintent); appwidgetmanager.updateappwidget(appwidgetid, updateviews); 

and in onreceive:

string action = intent.getaction(); if (action.startswith(action_widget_clicked)) {   int widgetid = integer.parseint(action.substring(action_widget_clicked.length()));   ... } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -