Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:10:19+00:00 2026-05-25T20:10:19+00:00

I want to make a very simple widget: It must consist from just one

  • 0

I want to make a very simple widget:

It must consist from just one image view

1) on incoming sms it should change the image

2) on click it also should change the image

I tried to make it using ImageButton but failed: there were problems with changing the image on sms received event: new image had wrong scale.

Anyway now I want to make an ImageView without anything else.

The problem is that I can’t handle onClick event:

I’ve got a running service which should handle all events: sms received and click:

widget provider:

public class MyWidgetProvider extends AppWidgetProvider {
    @Override
    public void onDisabled(Context context) {
        context.stopService(new Intent(context, UpdateService.class));
        super.onDisabled(context);
    }

    @Override
    public void onEnabled(Context context) {
        super.onEnabled(context);
        Intent intent = new Intent(context, UpdateService.class);
        context.startService(intent);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        for (int i = 0; i < appWidgetIds.length; i++) {
            int appWidgetId = appWidgetIds[i];

            RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
            Intent widgetClickIntent = new Intent(context, UpdateService.class);
            widgetClickIntent.setAction(UpdateService.ACTION_ON_CLICK);
            PendingIntent pendingIntentViewClick = PendingIntent.getService(context, 0, widgetClickIntent, 0);
            remoteViews.setOnClickPendingIntent(R.id.widget_imageview, pendingIntentViewClick);
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
    }
}

service:

public class UpdateService extends Service {
    static final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    static final String ACTION_ON_CLICK = "android.MyWidget.ACTION_ON_CLICK";

    private final static IntentFilter intentFilter;

    static {
        intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_SMS_RECEIVED);
        intentFilter.addAction(ACTION_ON_CLICK);
    }


    public final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();

            if (action.equals(ACTION_SMS_RECEIVED)) {
                reactOnSms(context);
            }
            if (action.equals(ACTION_ON_CLICK)) {
                onCLick(context);
            }
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        registerReceiver(broadcastReceiver, intentFilter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(broadcastReceiver);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    private void reactOnSms(Context context) {
        // doSomething
    }

    public void onCLick(Context context) {
        // doSomething
    }

Manifest:

    <receiver a:name="..."...>
        <intent-filter>
            <action a:name="android.provider.Telephony.SMS_RECEIVED"/>
            <action a:name="android.MyWidget.ACTION_ON_CLICK"/>
        </intent-filter>
        <meta-data a:name="android.appwidget.provider"
                   a:resource="@xml/my_widget_provider_info"/>
    </receiver>
    <service a:name=".UpdateService"
            a:label="UpdateService">

        <intent-filter>
            <action a:name="android.provider.Telephony.SMS_RECEIVED"/>
            <action a:name="android.MyWidget.ACTION_ON_CLICK"/>
        </intent-filter>
    </service>

I tried this Clickable widgets in android

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:10:19+00:00Added an answer on May 25, 2026 at 8:10 pm

    I found the solution.

    Sorry for those of you who read the question. Too much code inside, I understand.

    The problem was that UpdateService was not the real handler of the broadcast intent. Anonymous implementation of BroadcastReceiver made all the work.

    So the problem was in this code (widgetProvider):

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        for (int i = 0; i < appWidgetIds.length; i++) {
            int appWidgetId = appWidgetIds[i];
    
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
            // wrong:
            // Intent widgetClickIntent = new Intent(context, UpdateService.class);
            // widgetClickIntent.setAction(UpdateService.ACTION_ON_CLICK);
            // PendingIntent pendingIntentViewClick = PendingIntent.getService(context, 0, widgetClickIntent, 0);
            // correct:
            Intent widgetClickIntent = new Intent(UpdateService.ACTION_ON_CLICK);
            PendingIntent pendingIntentViewClick = PendingIntent.getBroadcast(context, 0, widgetClickIntent, 0);
            ///////
            remoteViews.setOnClickPendingIntent(R.id.widget_imageview, pendingIntentViewClick);
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a very simple django upload application but I want to make it
I want to make a very simple task in objective-c under IOS5 : convert
I want to make a very simple CMS for my sites. So what I
I want to make a very simple c++ instant messenger for lan networks and
I am working on a very simple game in Flash. I want to make
I am just playing around and trying to make a very simple CMS. Right
I'm trying to make a very simple toggle switch and I want to store
I want to make an very simple chatting page no login required no sql
I have very simple query. I want to make sure that I don't have
I have a very simple crawler. I want to make my current code run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.