Notification limitation on android wear

174 Views Asked by At

On the wear device I see that it can only display 12 Notifications per app. E.g., when I get around 20 new emails, the wear app only shows the recent 12 emails and not more than that.

Similarly, I wrote a wear app which throws notifications and even there it doesn't display more than 12 notifications, any new notifications are queued after that and doesn't get shown in the notification until the existing ones are cleared. So, at any given point a max of 12 notifications can only be shown.

Is it googles android wear limitation?

Here is my code..

PhoneDataListener which receives the dataItems from the mobile app..

public class PhoneDataListenerService extends WearableListenerService {
    private static final String TAG = "Listener-W";


    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {


        for (DataEvent event : dataEvents) {
            Log.v(TAG, "DataMap received on watch: " + DataMapItem.fromDataItem(event.getDataItem()).getDataMap());
            // Check the data type
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                // Check the data path
                String path = event.getDataItem().getUri().getPath();
                if (path.equals("/weardatapath")) {}
                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                ArrayList<DataMap> dataItemsList = dataMapItem.getDataMap().getDataMapArrayList
                        ("dataMapItems");
                // Broadcast DataMap contents to wearable show in notification..
                if (dataItemsList != null && dataItemsList.size() > 0) {
                    // start service for each Item in the dataItemsList
                    for (DataMap dMapItem : dataItemsList) {
                        startNotificatioService(this, dMapItem);
                    }
                }
            }
        }
    }

    public static void startNotificatioService(Context context, DataMap dataMap) {
        Log.w(TAG, "start Service to show notification...");
        Intent intent = new Intent(context, NotificationService.class);
        intent.setAction(NotificationService.ACTION_NOTIFICATION);
        intent.putExtra(NotificationService.DATA_PARAM, dataMap.toBundle());
        context.startService(intent);
    }
}

The NotificationService on the wear app which builds and throws the notification

public class NotificationService extends IntentService {

    private final static String TAG = "NotificationService-W";

    public static final String ACTION_NOTIFICATION = "com.test.phonewearsample.action.NOTIFIY";
    public static final String DATA_PARAM = "dataMap";
    private final static String MY_GROUP_KEY = "myGroupKey";

    public NotificationService() {
        super("NotificationService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (intent != null) {
            final String action = intent.getAction();
            if (ACTION_NOTIFICATION.equals(action)) {
                final Bundle data = intent.getBundleExtra(DATA_PARAM);
                handleActionNotification(data);
            }
        }
    }

    private void handleActionNotification(Bundle data) {
        // Display received data in UI

        int dataId = data.getInt(SharedConstants.EXTRA_MAIL_ID);
        Log.w(TAG, "###########DataItems############# :"+dataId);
        String name = data.getString(SharedConstants.WearMails.CONTACT_NAME);
        String number = data.getString(SharedConstants.WearMails.PHONE_NUMBER);
        String duration = data.getString(SharedConstants.WearMails.DURATION);
        Long uniqueVal = data.getLong(SharedConstants.EXTRA_UNIQUE_ID);

        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
        style.bigText(number + "\n" + duration);


        NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
                .setStyle(style)
                .setContentTitle(name)
                .setSmallIcon(R.mipmap.ic_launcher)
                .addAction(R.mipmap.ic_launcher, "Play On Phone",
                        NotificationUtil.getReplyPendingIntent(this, Integer.toString(dataId)))
                .setGroup(MY_GROUP_KEY)
                .setVibrate(new long[]{0, 100, 50, 100}) 
                .setSortKey(Long.toString(uniqueVal));

        NotificationManagerCompat.from(this).notify(dataId, notification.build());
    }
}

Please note that at a time it can only show 12 notifications for a group. Once I take a action and notification gets cleared the pending one comes in.

1

There are 1 best solutions below

0
On

Reading about this, I think this is a defect in Android Wear devices which Google is currently working on. Here is a link you can look at: https://code.google.com/p/android/issues/detail?id=130689. I think this issue is wearable-specific.