Android Can';发送短信时无法达到工作目的

Android Can';发送短信时无法达到工作目的,android,sms,android-intent,widget,send,Android,Sms,Android Intent,Widget,Send,好的,我将首先粘贴我的代码: 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;

好的,我将首先粘贴我的代码:

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

                            }

                }
}

这是我的小部件的代码。6个按钮。。。有两个电话号码。。。。3发送短信(至少他们被支持),一个按钮用于打开应用程序。打电话的按钮工作得很好,打开应用程序的按钮也很好,但我就是找不到发送短信的按钮。这段代码只打开短信创建页面,我需要点击发送按钮,但没有更多。请我需要帮助,有人可以告诉我如何改变我的例子,为这工作。我尝试了短信管理器,但我无法让它工作。。。所以请帮帮我。提前感谢大家。

首先,确保您的应用程序具有发送SMS消息的正确权限(
android.permission.send\u SMS

那么您肯定应该使用中解释的实例

这些问题似乎几乎是一样的:


我有预选任务。我有一个发送短信的应用程序,我只是不知道如何从widget中执行…@Goran:要么使用smsmsmanager和SEND_SMS权限,要么使用默认应用程序的意图。你应该给意图一个
SMS:
(后跟收件人号码)Uri。看见