【发布时间】:2016-04-13 08:50:16
【问题描述】:
我无法让NotificationManager 的Notifiy 接受我的论点。该方法应该采用 3 个参数。
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);
}
【问题讨论】:
-
notificationManager 初始化在哪里?
-
你在使用
NotificationManagerCompat吗? -
你能把代码发布为文本而不是图像吗
-
我已经添加了代码副本。
-
复制了你的代码,但我无法重现问题
标签: android compiler-errors notifications