Note that there are some explanatory texts on larger screens.

plurals
  1. POWidget: onUpdate, onReceive - appWidgetManager - not working in v2.3.5 and v3.2.1
    primarykey
    data
    text
    <p>I am new to Android applications and hence have a few questions. Using the code below, I am trying action on ImageButton. And it would be important to remember that this is a <strong>Widget</strong>, not an Activity.</p> <p>I searched online for examples on using ImageButton in a Widget and found very little information. However, this working example seems to have problems with different versions of Android.</p> <p>Now, the code works on old version (2.1-update1) of Android and not in new version of phone(2.3.5) or on Tablet (3.2.1)</p> <ul> <li>Working - (2.1-update1, Samsung 5700)</li> <li>Not working - (2.3.5, HTC Desire HD )</li> <li>Not working - (3.2.1, ASUS)</li> </ul> <p>It seems as if there have been some changes in the API due to which it has stopped working. (My suggestion of a possibility. Not sure about it though.)</p> <p>LogCat of 2.1-update1 </p> <p>Log:</p> <p>D/AAAAAA ( 3408): ======= onReceive </p> <p>D/AAAAAA ( 3408): ======= onUpdate</p> <p>Looks like in other versions even functions onUpdate() and onReceive() are not working. </p> <p>My code: ( Test code... :) )</p> <p>Could you please look at the code and explain this behaviour.</p> <pre><code>public class A_Org_WidgetActivity extends AppWidgetProvider { private static final String LOG_TAG = "AAAAAA"; Button btn; TextView txt1; ImageButton button; boolean bIcon = true; public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget"; public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(LOG_TAG, " ======= onUpdate"); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.hor_bott_4x3); Intent configIntent = new Intent(context, ClickOneActivity.class); configIntent.setAction(ACTION_WIDGET_CONFIGURE); Intent active = new Intent(context, A_Org_WidgetActivity.class); active.setAction(ACTION_WIDGET_RECEIVER); active.putExtra("msg", "Message for Button 1"); PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.ImageButton06, actionPendingIntent); remoteViews.setOnClickPendingIntent(R.id.ImageButton07, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); } @Override public void onReceive(Context context, Intent intent) { // v1.5 fix that doesn't call onDelete Action final String action = intent.getAction(); String msg = "null"; Log.d(LOG_TAG, " ======= onReceive"); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID ); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId } ); } } else { // check, if our Action was called if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { try { msg = intent.getStringExtra("msg"); Log.d(LOG_TAG, " ======= msg = null"); } catch (NullPointerException e) { Log.d(LOG_TAG, " Error msg: " + e); } Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification noty = new Notification(R.drawable.icon, "Button 1 clicked", System.currentTimeMillis()); noty.setLatestEventInfo(context, "Notice", msg, contentIntent); notificationManager.notify(1, noty); } super.onReceive(context, intent); } } } </code></pre> <p>And...</p> <p>My manifest <em>*</em>.xml</p> <pre><code>&lt;application android:icon="@drawable/red_circle" android:label="@string/app_name"&gt; &lt;receiver android:name="A_Org_WidgetActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /&gt; &lt;/receiver&gt; &lt;!-- &lt;action android:name="com.widget.bla-bla.A_Org_WidgetActivity.ACTION_WIDGET_RECEIVER" /&gt; --&gt; &lt;!-- Service to perform web API queries --&gt; &lt;service android:name="A_Org_WidgetActivity$UpdateService" /&gt; &lt;!-- this activity will be called, when we fire our self created ACTION_WIDGET_CONFIGURE --&gt; &lt;activity android:name="CommonActivity"&gt; &lt;intent-filter&gt; &lt;action android:name="com.widget.bla-bla.A_Org_WidgetActivity.ACTION_WIDGET_CONFIGURE" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;uses-sdk android:minSdkVersion="7"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload