某些Android手机上没有显示通知
在我的应用程序中,我收到通知,我可以在日志中看到它们。但在一些手机上,它们并没有被显示出来。例如:一加A0001(Android 5.1.1 API22)。我已经阅读了其他stackoverflow问题,并确保所有必需的方法都在那里。经过一些探索,我知道Cyanogenmod可能是原因。但在这种情况下,其他应用程序通知是如何显示的某些Android手机上没有显示通知,android,notifications,cyanogenmod,Android,Notifications,Cyanogenmod,在我的应用程序中,我收到通知,我可以在日志中看到它们。但在一些手机上,它们并没有被显示出来。例如:一加A0001(Android 5.1.1 API22)。我已经阅读了其他stackoverflow问题,并确保所有必需的方法都在那里。经过一些探索,我知道Cyanogenmod可能是原因。但在这种情况下,其他应用程序通知是如何显示的 public class MainActivity extends AppCompatActivity { @Override protected void onC
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 " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(6578, n);
}
以上代码适用于所有其他手机。检查应用程序的通知权限。通过你的手机控制它。可能在设置或预装应用程序中。
特别是在中国,许多手机预装了一款名为权限管家" 控制第三方应用程序的权限。例如,在通知栏中显示通知,在运行后台或屏幕锁定时连接到internet。尝试使用
NotificationCompat
。试一试。@向导已经尝试过了。但没有使用我检查了这些设置@Oscar Zhang