1
我WidgetProvider打開的應用程序是這樣的:如何通過點擊小工具
package br.com.pedro.widget;
import android.appwidget.AppWidgetProvider;
public class MyWidgetProvider extends AppWidgetProvider {
}
如何顯示,顯示佈局和點擊後進入我的主類的窗口小部件?
我WidgetProvider打開的應用程序是這樣的:如何通過點擊小工具
package br.com.pedro.widget;
import android.appwidget.AppWidgetProvider;
public class MyWidgetProvider extends AppWidgetProvider {
}
如何顯示,顯示佈局和點擊後進入我的主類的窗口小部件?
這裏將MainActivity
替換爲您想要打開的活動。
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Toast.makeText(context, "Touched view ", Toast.LENGTH_SHORT).show();
Log.i("ExampleWidget", "Updating widgets " + Arrays.asList(appWidgetIds).size());
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}