2017-02-04 81 views
2

在我的应用程序中,我收到了通知,我可以在日志中看到它们。但在一些手机上,他们没有被显示。例如: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); 
} 

上述代码适用于所有其他手机。

+0

尝试使用'NotificationCompat'。试一试。 – Wizard

+0

@Wizard已经尝试过那个。但没有用 –

回答

0

检查您的应用程序的通知权限。你的手机控制哪个。也许在设置或预先安装的应用程序。 特别是在中国,许多手机预装了一款名为“权限管家”的应用来控制第三方应用的权限。例如在通知栏中显示通知,在运行后台或屏幕锁定时连接到互联网。

+0

我检查了这些设置@Oscar Zhang –

相关问题