1

我正在尝试为我的音乐应用创建自定义通知。我发现我们可以使用远程视图来自定义通知布局。但它不能用于实现某些事件onClick,例如按钮...

我发现我的 Android 中的默认音乐应用程序有一个很好的通知。(Android 2.3.6)

4

1 回答 1

0

sure you can use clicks on RemoteViews but has a different flavour your

 onUpdate 

will have something this

//To goto class
Intent intent = new Intent(context, "Your class".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.update_class, pendingIntent);

          appWidgetManager.updateAppWidget(widgetId, remoteViews);
//To goto Service
          Intent it = new Intent();
          it.setClass(context, "Your Service".class);
          PendingIntent pendingIntent1 = PendingIntent.getService(context,
          0,
          it, PendingIntent.FLAG_NO_CREATE);
        remoteViews.setOnClickPendingIntent(R.id.service_controller,
                pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

you will have to use remoteView.setOnClickPendingIntent("id of button/textview","corresponding peinding intent")

于 2012-04-27T04:34:00.363 回答