Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android widget onClick isn't working

I honestly have no idea what I'm doing wrong here. I had this working last night, I messed with the code and I'm pretty sure I have it back to where it was yet it simply doesn't do anything when clicked.

Here is my code

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d(LOG_TAG, "onUpdate(): ");

    for (int appWidgetId : appWidgetIds) {


    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.xx.xx"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT );


    RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
    remoteView.setOnClickPendingIntent(R.id.image, pendingIntent);

    }        
    super.onUpdate(context, appWidgetManager, appWidgetIds);

I'm simply trying to take the user to the market when the widget is clicked but nothing at all happens.

Is this a simple fix?

like image 984
jblz Avatar asked Dec 11 '25 09:12

jblz


1 Answers

OH MY GOD. I've spent about 4-5 hours on this.. just realized what I've done wrong.

I was missing 'appWidgetManager.updateAppWidget(appWidgetId, remoteView);' after my setOnClickPendingIntent.

The joys of programming.

like image 66
jblz Avatar answered Dec 12 '25 21:12

jblz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!