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 6318285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:37:20+00:00 2026-05-24T15:37:20+00:00

I have an app with widget. Three buttons on widget should sent predefined SMS

  • 0

I have an app with widget. Three buttons on widget should sent predefined SMS messages to predefined numbers … this is my code:

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);

                            }

                }

        }

Problem is that button3, button4 and button5 (when I click on them) don’t send sms, but only open new sms screen, and I need to click on send SMS. What do I need to change, that SMS automaticly sends to recipient ??

  • 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-24T15:37:20+00:00Added an answer on May 24, 2026 at 3:37 pm

    Just ripped some of my old code from an app, this should work for sending SMS messages:

    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.telephony.gsm.SmsManager;
    import android.util.Log;
    
     send_text_message (Number, "This is a message"); 
    
    private void send_text_message (String phoneNumber, String message) 
    {
     if (phoneNumber.length() > 0 && message.length() > 0)
     {
      Log.i (TAG, "MyPhoneStateListener: onCallStateChanged(); test text sent to " + phoneNumber);    
      sendSMS(phoneNumber, message);      
     }
     else
     {
      Log.i (TAG, "MyPhoneStateListener: onCallStateChanged(); test text was NOT sent to " + phoneNumber);                   
     }
    }   
    
    private void sendSMS(String phoneNumber, String message)
    {                     
     SmsManager sms = SmsManager.getDefault();
     sms.sendTextMessage(phoneNumber, null, message, null, null);        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an App Widget for Android 1.5. It uses a TextView to
I have a JavaScript widget which communicates with my Rails app by creating tags
I have a widget that supposed to call an Activity of the main app
I've developed an Application (called Instant Buttons) and the app has a widget feature.
I have a webkit widget in my app and you can print it. It
i have three classess.activity,service and appwidget. i have two buttons in appwidget. and onclicking
Please take a look at my code: package com.yarin.android.Examples_04_23; import android.app.Activity; import android.app.Notification; import
I have some trouble while try using broadcast receiver. Target: I have three app
So, I have an app/assets/stylesheets/ directory structure that looks something like this: |-dialogs |-mixins
I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1). I

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.