नहीं दिखा रहा है मैं एक अग्रभूमि सेवा शुरू करने की कोशिश कर रहा हूं। मुझे अधिसूचित किया जाता है कि सेवा शुरू होती है लेकिन अधिसूचना हमेशा दबा दी जाती है। मैंने दो बार जांच की है कि ऐप को मेरे डिवाइस पर ऐप जानकारी में नोटिफिकेशन दिखाने की अनुमति है।एंड्रॉइड फोरग्राउंड सर्विस अधिसूचना
private void showNotification() {
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
Notification notification = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("Revel Is Running")
.setTicker("Revel Is Running")
.setContentText("Click to stop")
.setSmallIcon(R.mipmap.ic_launcher)
//.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setContentIntent(pendingIntent)
.setOngoing(true).build();
startForeground(Constants.FOREGROUND_SERVICE,
notification);
Log.e(TAG,"notification shown");
}
यहाँ केवल त्रुटि मैं संबंध में देख रहा है: 06-20 12:26:43.635 895-930/? E/NotificationService: Suppressing notification from the package by user request.
क्या इसे संभालने का एक और सुविधाजनक तरीका है? यानी समर्थन/रचना शैली? वही कोड जो "if" और डुप्लिकेट कोड का उपयोग किए बिना प्री -26 और 26+ प्लेटफ़ॉर्म दोनों पर काम करता है। –
यदि (Build.VERSION.SDK_INT> = Build.VERSION_CODES.O) {createNotificationChannel (संदर्भ);} // यहां कोड का REST –
लेकिन कोड के इस नए स्निपेट में, मुझे लगता है कि आप 'mnotifyManager.notify () 'startForeground()' के बजाय '। इस मामले में, क्या यह वास्तव में सेवा अग्रभूमि बना रहा है? –