Hangouts gibi çalışmak için yerel bildirimler almaya çalışıyorum. Yeni bir metin mesajı alındığında bildirimlerin başlamasını istiyorum. Ancak iki veya daha fazla okunmamış bildirim olduğunda, Android bildirim çubuğunda bir özet bildirimi görüntülemek istiyorum. Gruplar aracılığıyla bildirim isteme gibi görünüyor ve bir grup özeti eklediğinde here açıklandığı gibi çalışmalıdır. Aşağıdaki kod Android 5.0 ve 5.1 sürümlerinde benim için işe yarıyor gibi görünüyor, ancak Android 6.0'da yerel bildirim, o grup için bir özet bildirimi mevcut olduğunda, yukarı görünümde alarm vermiyor/görüntülenmiyor. Bu yüzden sadece ilk bildirim görüntülenir.Android grup bildirimi, özet bildirimi ekledikten sonra alarm vermiyor (Android 6.0)
public class MainActivity extends AppCompatActivity {
private Button _button = null;
final static String GROUP_KEY_EMAILS = "group_key_emails";
private int messageNum = 1;
private void CreateNotification() {
// Build the notification, setting the group appropriately
Notification headsUpNotification = new NotificationCompat.Builder(this)
.setContentTitle("Title")
.setContentText("New Message" + messageNum)
.setSmallIcon(R.drawable.pngreceivedtextmessage)
.setGroup(GROUP_KEY_EMAILS)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.build();
// Issue the notification
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(messageNum, headsUpNotification);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.pngreceivedmessageicon);
if(messageNum > 1) {
// Create a summary notification since we have more than 1
Notification summaryNotification = new NotificationCompat.Builder(this)
.setContentTitle("Summary")
.setNumber(messageNum)
.setSmallIcon(R.drawable.pngreceivedtextmessage)
.setLargeIcon(largeIcon)
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.build();
notificationManager.notify(0, summaryNotification);
}
messageNum++;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_button = (Button) findViewById(R.id.button);
_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CreateNotification();
}
});
}
SDK 23'ü hedefliyorum ve pek çok farklı kombinasyonu denedim ancak hiçbir şey işe yaramıyor. Bir kimsenin bir özet bildirimi nasıl oluşturacağını bilen var mı?
Android M için çalışma zamanı izinlerini mi sordunuz? –
İzin gerektiren bir şey yaptığımı düşünmedim. Hangi izinlere ihtiyacım olacak? – Alex