0

OK i will paste my code first :

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.telephony.SmsManager;
import android.widget.RemoteViews;



        public class HelloWidget extends AppWidgetProvider {

                private static final String ACTION_SEND_SMS = null;

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

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

                            for (int appWidgetId : appWidgetIds) {


                                Intent smsIntent = new Intent(context, HelloWidget.class);
                                smsIntent.setAction(ACTION_SEND_SMS);


                                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);
                                PendingIntent pendingIntent7 = PendingIntent.getBroadcast(context, 0, smsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

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

                            }

                }
}

This code for my widget. 6 buttons ... 2 are calling numbers .... 3 sends SMS (at least they are suposed to), and one button for opening application. Buttons for calling are working great, and button for opening application too, but I just Can't get buttons to send SMS. This code only get to open SMS create page, and I need to click on send button, but nothing more. Please I need help, of someone who can show me how to change my examplet, for this to work. I tried sms manager, but I can't get this to work... So please help me. Thank you all in advance.

Goran
  • 1,239
  • 4
  • 23
  • 36
  • You should give the intent a `sms:` (followed by the recipient number) Uri. See [Send SMS in Android](http://stackoverflow.com/questions/4967448/send-sms-in-android). – Jan Hudec Jun 19 '13 at 12:07

1 Answers1

0

First, make sure your application has the right permissions to send SMS messages (android.permission.SEND_SMS)

Then you definitely should use a SmsManager instance as explained in this tutorial.

This questions seem to be almost the same:

Community
  • 1
  • 1
Guido
  • 46,642
  • 28
  • 120
  • 174
  • I have premission. And I have an app that sends SMS, I just don't know how to do it from widget.... – Goran Aug 17 '11 at 07:30
  • @Goran: _Either_ you use SmsManager and the SEND_SMS permission, _or_ intents for the default application. – Jan Hudec Jun 19 '13 at 12:05