如何创建自定义通知包含一些控件

时间:2012-04-27 04:16:12

标签: android notifications

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

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

先谢谢!

1 个答案:

答案 0 :(得分:0)

确保您可以在RemoteViews上使用点击,但具有不同的风格

 onUpdate 

会有这个东西

//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);

你必须使用 remoteView.setOnClickPendingIntent(“id of button / textview”,“相应的peinding意图”)