在我的应用程序中,我收到了通知,我可以在日志中看到它们。但在一些手机上,他们没有被显示。例如:One plus A0001(Android 5.1.1 API22)。我已经阅读了其他的stackoverflow问题,并确保所有必需的方法都在那里。经过一番探索后,我开始知道Cyanogenmod可能是这个原因。但在那种情况下显示应用程序通知。某些Android手机上没有显示通知
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "[email protected]")
.setContentText("Subject")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(6578, n);
}
上述代码适用于所有其他手机。
尝试使用'NotificationCompat'。试一试。 – Wizard
@Wizard已经尝试过那个。但没有用 –