Android 如果出现其他通知,我的第一次推送通知将不起作用
我在android推送通知中遇到了一个问题,正如标题所示,如果出现其他通知,我的第一个推送通知将不起作用 这是我的密码 Java的Android 如果出现其他通知,我的第一次推送通知将不起作用,android,notifications,push-notification,Android,Notifications,Push Notification,我在android推送通知中遇到了一个问题,正如标题所示,如果出现其他通知,我的第一个推送通知将不起作用 这是我的密码 Java的 public class MyNotifications { public static NotificationManager mNotificationManager; private Context _context; public MyNotifications(Context context) { _context = context; }
public class MyNotifications {
public static NotificationManager mNotificationManager;
private Context _context;
public MyNotifications(Context context) {
_context = context;
}
public void SetNotification(int drawable, String sender, String msg,
String story_ID, Class<?> cls) {
mNotificationManager = (NotificationManager) _context
.getSystemService(Context.NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(drawable, sender
+ ":" + msg, System.currentTimeMillis());
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
long[] vibrate = { 100, 100, 200, 300 };
notifyDetails.vibrate = vibrate;
notifyDetails.ledARGB = 0xff00ff00;
notifyDetails.ledOnMS = 300;
notifyDetails.ledOffMS = 1000;
notifyDetails.defaults |= Notification.DEFAULT_SOUND;
// notifyDetails.number=4;
notifyDetails.defaults = Notification.DEFAULT_ALL;
Context context = _context;
CharSequence contentTitle = sender;
CharSequence contentText = msg;
Intent notifyIntent = new Intent(context, cls);
Bundle bundle = new Bundle();
// bundle.putBoolean(AppConfig.IS_NOTIFICATION, true);
notifyIntent.putExtras(bundle);
notifyIntent.putExtra("NEWS_SECTION", "PUSH_NOTIFICATION");
notifyIntent.putExtra("STORY_ID", story_ID);
PendingIntent intent = PendingIntent.getActivity(_context, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
intent);
mNotificationManager.notify(Integer.parseInt(story_ID), notifyDetails);
}
}
问题在我的下图中描述
试试看,这会有用的
改变这个
PendingIntent intent = PendingIntent.getActivity(_context, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
对此
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
试试这种方法,希望这能帮助你解决问题。
int count=1;
PendingIntent intent = PendingIntent.getActivity(_context,(int) (Math.random() * 100), notifyIntent, android.content.Intent.FLAG_UPDATE_CURRENT);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,intent);
mNotificationManager.notify(count, notifyDetails);
count = count + 1;
它的Q mobile A11 noir android 4.0应该开始使用,而不是使用通知类directly@hoomi调用需要API级别16(当前最小值为11):android.app.Notification.Builder#build。我把minSDK设置为11。我必须支持高达android 4的应用程序。0@hoomi应用程序崩溃,出现此异常java.lang.NoSuchMethodError:android.app.Notification$Builder。build@QadirHussain您可以使用支持库。“通知对象的生成器类。提供了一种方便的方法来设置通知的各个字段,并使用平台的通知布局模板生成内容视图。如果您的应用程序支持旧到API级别4的Android版本,您可以改为使用Android支持库中提供的NotificationCompat.Builder。”
int count=1;
PendingIntent intent = PendingIntent.getActivity(_context,(int) (Math.random() * 100), notifyIntent, android.content.Intent.FLAG_UPDATE_CURRENT);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,intent);
mNotificationManager.notify(count, notifyDetails);
count = count + 1;