PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
//设置图标
builder.setSmallIcon(R.mipmap.ic_launcher);
//设置标题
builder.setContentTitle(context.getString(R.string.new_message));
//设置内容
builder.setContentText(context.getString(R.string.click_view));
//设置时间
builder.setWhen(System.currentTimeMillis());
//声音、震动和响铃
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setAutoCancel(true);
builder.setContentIntent(pendingIntent);
notificationManager.notify(0, builder.build());
权限
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />