从android appwidgetprovider点击按钮打开其他应用程序

时间:2017-01-30 04:56:49

标签: android-appwidget appwidgetprovider

我想通过按钮/ imageButton从我的应用小部件提供商点击打开另一个已安装的应用。 这是我的代码,

 @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int count = appWidgetIds.length;

    for (int i = 0; i < count; i++) {
        int widgetId = appWidgetIds[i];
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.activity_main);


        Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.imageViewBus, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
}

提前致谢。

0 个答案:

没有答案