我无法让NotificationManager的Notify方法接受我的参数。该方法应该接受三个参数。
String tag
int id
Notification notification
为构建通知,我使用的是NotificationCompat类,但我甚至尝试过Notification.Builder。
import android.app.Notification;
import android.support.v4.app.NotificationCompat;
关于我的构建配置,如下所示:
compileSdkVersion 23
buildToolsVersion "23.0.2"
minSdkVersion 14
targetSdkVersion 21
编辑:代码转录:
import android.app.Notification;
import android.support.v4.app.NotificationCompat;
private void showNotification(Context context, String category, String title, String text, int tag, boolean ongoing)
{
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
PendingIntent pendingIntent = PendingIntent.getActivity(context, new Random().nextInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title);
builder.setContentText(text);
builder.setContentIntent(pendingIntent);
builder.setOngoing(ongoing);
builder.setSmallIcon(R.drawable.ic_launcher);
Notification notification = builder.build();
notificationManager.showNotification(context, category, title, text, new Random().nextInt(), ongoing);
notificationManager.notify(null, 0, notification);
}
NotificationManagerCompat
? - Pedro Oliveira