【问题标题】:android notification not working for 2.3 gingerbreadandroid 通知不适用于 2.3 姜饼
【发布时间】:2014-01-10 09:20:38
【问题描述】:

此代码适用于 2.3 以上版本(不适用于 2.3)

Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder mBuilder =  new NotificationCompat.Builder(this)
     .setSmallIcon(R.drawable.abc_logo)
     .setContentTitle("My Title")
     .setWhen(System.currentTimeMillis())
     .setContentIntent(pendingIntent)
     .setContentText("My text");

    mBuilder.setContentIntent(pendingIntent);

    NotificationManager mNotificationManager =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFY_ID, mBuilder.build());

【问题讨论】:

    标签: android android-intent notifications android-notifications android-2.3-gingerbread


    【解决方案1】:

    使用PendingIntent.getBroadcast(),您打算向所有可能的接收者发送广播。 问题出在:

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    

    它不会用于启动 Activity。因此,您不能设置任何与 Activity 相关的标志,例如 FLAG_ACTIVITY_SINGLE_TOP。

    删除它,它也应该在 GB 上工作。

    PendingIntent中只能设置Activity相关的Intent标志,只要调用getActivity()获取PendingIntent即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多