好吧,这是我的小部件的代码。 我有两个按钮,被点击它们时拨打电话。 我想实现三个按钮,用于发送短信,但我不能为实现这一意图......我我主要的应用程序我用smsmanager功能....
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) {
//Timer timer = new Timer();
//timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
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);
// Get the layout for the App Widget and attach an on-click listener to the button
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);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views1);
appWidgetManager.updateAppWidget(appWidgetId, views2);
}
}
}