好的我先粘贴我的代码:
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个按钮...... 2是呼叫号码.... 3发送短信(至少它们被接通),以及一个用于打开应用程序的按钮。呼叫的按钮工作得很好,并且按钮也用于打开应用程序,但我只是无法获取发送短信的按钮。这段代码只能打开短信创建页面,我需要点击发送按钮,但仅此而已。我需要帮助,可以告诉我如何改变我的例子,让这个工作。我试过短信经理,但我不能让这个工作......所以请帮助我。提前谢谢大家。
答案 0 :(得分:0)
首先,确保您的应用程序具有发送短信的正确权限(android.permission.SEND_SMS
)
然后你绝对应该使用SmsManager中解释的this tutorial实例。
这个问题似乎几乎相同: