1

在穿戴设备上,我看到它只能显示 12 Notifications per app。例如,当我收到大约 20 封新电子邮件时,Wear 应用程序只显示最近的 12 封电子邮件,并且不会更多。

同样,我编写了一个会抛出通知的磨损应用程序,即使在那里它也不会显示超过 12 个通知,任何新通知都会在此之后排队,并且在现有通知被清除之前不会显示在通知中。因此,在任何给定点上,最多只能显示 12 条通知。

是谷歌的安卓磨损限制吗?

这是我的代码..

PhoneDataListener 从移动应用程序接收数据项..

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);
    }
}

穿戴应用程序上的 NotificationService 构建并抛出通知

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());
    }
}

请注意,一次只能为一个群组显示 12 条通知。一旦我采取行动并且通知被清除,待处理的通知就会进入。

4

1 回答 1

0

读到这个,我认为这是谷歌目前正在开发的 Android Wear 设备的一个缺陷。这是您可以查看的链接:https ://code.google.com/p/android/issues/detail?id=130689 。我认为这个问题是可穿戴设备特有的。

于 2016-01-21T16:04:42.190 回答