【问题标题】:Notification limitation on android wearAndroid Wear 的通知限制
【发布时间】:2016-01-21 15:09:23
【问题描述】:

在 Wear 设备上,我看到它每个应用只能显示 12 个通知。例如,当我收到大约 20 封新电子邮件时,Wear 应用程序只显示最近的 12 封电子邮件,并且不会超过。

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

是 google 的 android wear 限制吗?

这是我的代码..

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

Wear 应用上的 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 条通知。一旦我采取行动并且通知被清除,待处理的通知就会进来。

【问题讨论】:

  • 如果可以的话,可以发一下代码吗?
  • 您需要完整的代码还是只需要我构建并抛出通知的部分?
  • 只是构建通知的部分应该是好的。谢谢。
  • 我已经编辑了我的问题并添加了代码。
  • 我不知道这些限制,但这是您想要的吗?无论如何,最好将通知合二为一。

标签: android wear-os android-wear-notification


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多