【发布时间】:2014-01-14 15:28:23
【问题描述】:
我正在尝试使用 1 button 制作一个简单的小部件。按此button 将启动android 设置活动(例如android.provider.Settings.ACTION_WIFI_SETTINGS)。
我的代码有什么问题?我应该怎么做才能让它发挥作用?
代码sn-p:
public class WiFiShortcut extends AppWidgetProvider{
//ImageButton imagebutton;
static RemoteViews remoteViews;
public static String ACTION="SetWIFI";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//ComponentName watchWidget;
remoteViews = new RemoteViews( context.getPackageName(), R.layout.wifi_shortcut_main );
Intent cel= new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
//Intent cel = new Intent(context, WiFiShortcut.class);
cel.setAction(ACTION);
PendingIntent pcel = PendingIntent.getBroadcast(context,0, cel,0);
remoteViews.setOnClickPendingIntent(R.id.bwifi, pcel);
}
}
我应该使用onReceive 方法吗?
【问题讨论】:
标签: android button android-activity widget