लघु प्रश्न:नोटिफिकेशन कॉम्पेट.बिल्डर और स्टार्टवार्ग का उपयोग कैसे करें?
मैं आदेश एक सूचना है कि सेवा के लिए इस्तेमाल किया जाएगा बनाने के लिए NotificationCompat.Builder वर्ग का उपयोग करने की कोशिश कर रहा हूँ, लेकिन किसी कारण से, मैं या तो अधिसूचना नहीं दिख रहा है, या जब सेवा को नष्ट किया जाना चाहिए (या अग्रभूमि में होने से रोकना) इसे रद्द नहीं करें।
मेरी कोड:
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
final String action = intent == null ? null : intent.getAction();
Log.d("APP", "service action:" + action);
if (ACTION_ENABLE_STICKING.equals(action)) {
final NotificationCompat.Builder builder = new Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("content title");
builder.setTicker("ticker");
builder.setContentText("content text");
final Intent notificationIntent = new Intent(this, FakeActivity.class);
final PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, 0);
builder.setContentIntent(pi);
final Notification notification = builder.build();
// notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
// notification.flags |= Notification.FLAG_NO_CLEAR;
// notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, notification);
// mNotificationManager.notify(NOTIFICATION_ID, notification);
} else if (ACTION_DISABLE_STICKING.equals(action)) {
stopForeground(true);
stopSelf();
// mNotificationManager.cancel(NOTIFICATION_ID);
}
return super.onStartCommand(intent, flags, startId);
}
टिप्पणी की आज्ञाओं यह काम करने के लिए अपने परीक्षणों कर रहे हैं। किसी ने किसी कारण से काम नहीं किया।
मैंने एक नकली गतिविधि भी जोड़ दी क्योंकि यह एक सामग्री चाहता थान्टेंट, लेकिन यह अभी भी काम नहीं करता है।
क्या कोई मदद कर सकता है?
इस पोस्ट में है स्वीकार किए जाते हैं जवाब के साथ अद्यतन किया गया है एक समाधान पर दिनों के लिए काम करने के बाद मेरी समस्या ठीक हो गई। –