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

  • Home
  • SEARCH
  • 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 6247857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:57:05+00:00 2026-05-24T12:57:05+00:00

I don’t know what is wrong in my code, but everytime i put widget

  • 0

I don’t know what is wrong in my code, but everytime i put widget on home screen button1 doesn’t work. After phone reboot both buttons works perfectly…

package cro.perger.bonbon;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;



        public class HelloWidget extends AppWidgetProvider {

                @Override
                public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                        int[] appWidgetIds) {

                            String encodedHash = Uri.encode("#");

                            for (int appWidgetId : appWidgetIds) {

                                Intent callIntent1  = new Intent("android.intent.action.CALL",
                                         Uri.parse("tel:*100" + encodedHash));
                                Intent callIntent2  = new Intent("android.intent.action.CALL",
                                         Uri.parse("tel:*200*1" + encodedHash));

                                PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 0, callIntent1, 0);
                                PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, callIntent2, 0);

                                RemoteViews views1 = new RemoteViews(context.getPackageName(), R.layout.widget);
                                views1.setOnClickPendingIntent(R.id.button1, pendingIntent1);

                                RemoteViews views2 = new RemoteViews(context.getPackageName(), R.layout.widget);
                                views2.setOnClickPendingIntent(R.id.button2, pendingIntent2);

                                appWidgetManager.updateAppWidget(appWidgetId, views1);
                                appWidgetManager.updateAppWidget(appWidgetId, views2);
                            }

                }
    }

Any help, please ??

EDIT 2 : Ok, now it’s working, but now I have another two questions . First i managed three buttons for sending messages, but I always get the same Message body, no mather what button I press. And second what do I need to change this code, so thah message is sent automaticly (now only composed message is opened) ….

package cro.perger.bonbon;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;



        public class HelloWidget extends AppWidgetProvider {

                @Override
                public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                        int[] appWidgetIds) {

                            String encodedHash = Uri.encode("#");

                            for (int appWidgetId : appWidgetIds) {

                                Intent callIntent1  = new Intent("android.intent.action.CALL",
                                         Uri.parse("tel:*100" + encodedHash));
                                Intent callIntent2  = new Intent("android.intent.action.CALL",
                                         Uri.parse("tel:*200*1" + encodedHash));

                                Intent sendIntent1 = new Intent(Intent.ACTION_VIEW);
                                sendIntent1.putExtra("sms_body", "Poruka 1");
                                sendIntent1.putExtra("address", "5556");
                                sendIntent1.setType("vnd.android-dir/mms-sms");

                                Intent sendIntent2 = new Intent(Intent.ACTION_VIEW);
                                sendIntent2.putExtra("sms_body", "Poruka 2");
                                sendIntent2.putExtra("address", "5556");
                                sendIntent2.setType("vnd.android-dir/mms-sms");

                                Intent sendIntent3 = new Intent(Intent.ACTION_VIEW);
                                sendIntent3.putExtra("sms_body", "Poruka 3");
                                sendIntent3.putExtra("address", "5556");
                                sendIntent3.setType("vnd.android-dir/mms-sms");

                                Intent openintent = new Intent(context, bonbon.class);

                                PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 0, callIntent1, 0);
                                PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, callIntent2, 0);
                                PendingIntent pendingIntent3 = PendingIntent.getActivity(context, 0, sendIntent1, PendingIntent.FLAG_UPDATE_CURRENT);
                                PendingIntent pendingIntent4 = PendingIntent.getActivity(context, 0, sendIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
                                PendingIntent pendingIntent5 = PendingIntent.getActivity(context, 0, sendIntent3, PendingIntent.FLAG_UPDATE_CURRENT);
                                PendingIntent pendingIntent6 = PendingIntent.getActivity(context, 0, openintent, 0);

                                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
                                views.setOnClickPendingIntent(R.id.button1, pendingIntent1);
                                views.setOnClickPendingIntent(R.id.button2, pendingIntent2);
                                views.setOnClickPendingIntent(R.id.button3, pendingIntent3);
                                views.setOnClickPendingIntent(R.id.button4, pendingIntent4);
                                views.setOnClickPendingIntent(R.id.button5, pendingIntent5);
                                views.setOnClickPendingIntent(R.id.button6, pendingIntent6);

                                appWidgetManager.updateAppWidget(appWidgetId, views);

                            }

                }

        }
  • 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-24T12:57:06+00:00Added an answer on May 24, 2026 at 12:57 pm

    What you do there is updating the same widget (appWidgetId) with two layouts (views1 and views2). Basically you are setting the widgets layout with a pending intent on button1 (->views1).
    Then you overwrite it with a layout where only button2 has a pending intent (-> views2). I’m not sure why this is working after a restart, maybe android notices that you use the same base layout resource and doesn’t create it from scratch somewhere in the internals.

    So how do you do it correct?

    You may just shorten your snippet. Create one layout, set the pending intents for both buttons on the same layout and update as you did. But only once, you will never need more than one call to updateAppWidget() per appWidgetId (this is basically the same thing that setContentView() is for a normal activity).

    Should look like this in the end:

    Intent callIntent1  = new Intent("android.intent.action.CALL",
                                 Uri.parse("tel:*100" + encodedHash));
    Intent callIntent2  = new Intent("android.intent.action.CALL",
                         Uri.parse("tel:*200*1" + encodedHash));
    
    PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 0, callIntent1, 0);
    PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, callIntent2, 0);
    
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    views.setOnClickPendingIntent(R.id.button1, pendingIntent1);
    views.setOnClickPendingIntent(R.id.button2, pendingIntent2);
    
    appWidgetManager.updateAppWidget(appWidgetId, views);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand why this code doesn't work: function Messages(type,text) { console.log(In function Message);
Don't know why, but sometimes LocationManager is still working also after closing application. I
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know what I did wrong. I have two indices with identical documents in
Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't know what's wrong here, when I run the application it says Specified method
Don't know a whole lot about streams. Why does the first version work using
Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a

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.