Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Handle Button Click on Widget
    primarykey
    data
    text
    <p>I've a widget on my app and <code>Service</code> in order to update automatically. </p> <p>Widget has a <code>ImageButton</code> which <strong>triggers</strong> updating content manually. But I couldn't handle click event. </p> <p>Here is my <code>AppWidgetProvider</code>:</p> <pre><code>public class MyWidget extends AppWidgetProvider { public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); RemoteViews rmViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); Intent active = new Intent(context, MyWidget.class); active.setAction(ACTION_WIDGET_RECEIVER); active.putExtra("msg", "Message for Button 1"); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, active, 0); rmViews.setOnClickPendingIntent(R.id.buttonus1, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, rmViews ); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { Log.d(debug_tag, intent.getAction()); } } } </code></pre> <p>When I clicked the button nothing changed. It doesn't even logged. </p> <p>Manifest.xml declaration:</p> <pre><code>&lt;receiver android:name=".MyWidget" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;action android:name="com.app.example.MyWidget.ACTION_WIDGET_RECEIVER"/&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget"/&gt; &lt;/receiver&gt; </code></pre> <p>What's wrong?</p> <p>By the way, if I could handle the click, how should I use for updating manually? Do I pass it to service and which way?</p> <p><strong>Edit</strong>: Changed <code>getActivity()</code> with <code>getBroadcast()</code> and handled click well. But couldn't pass this message to Service. Any recommendations? </p>
    singulars
    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.
    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