简体   繁体   English

在Wear应用中创建的通知不会显示在Android SmartWatch上

[英]Notification created within wear app doesn't display on Android smartwatch

I have been working on this all day and can't figure out where the disconnect is. 我整天都在努力,无法弄清断开的位置。 Please find below my wear app method in which I call the notification request from a broadcast receiver: 请在下面的我的穿戴应用方法中找到我从广播接收方调用通知请求的方法:

private void createWearNotification(final String notificationString, final String name, final String extensionRequested) { 私人无效createWearNotification(最终字符串NotificationString,最终字符串名称,最终字符串extensionRequested){

    // Wear 2.0 allows for in-line actions, which will be used for "reply".
    NotificationCompat.Action.WearableExtender inlineNotification =
            new NotificationCompat.Action.WearableExtender()
                    .setHintDisplayActionInline(true)
                    .setHintLaunchesActivity(true);

    //Create View Message Intent
    Intent intent = new Intent(this, ViewMessageActivity.class);
    PendingIntent replyIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Add an action to allow replies.
    NotificationCompat.Action replyAction =
            new NotificationCompat.Action.Builder(
                    R.drawable.ic_curved_arrow_right,
                    getString(R.string.reply_action),
                    replyIntent)
                    .extend(inlineNotification)
                    .build();

    int notificationId = 001;
    // The channel ID of the notification.
    String id = "my_channel_01";

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.drawable.ic_email)
                    .setContentTitle("")
                    .setDefaults(NotificationCompat.DEFAULT_VIBRATE)
                    .setContentText(notificationString)
                    .addAction(replyAction)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setContentIntent(replyIntent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());
}

I have the below declaration in my androidmanifext.xml doc: 我的androidmanifext.xml文档中包含以下声明:

    <meta-data
        android:name="com.google.android.wearable.standalone"
        android:value="true" />

Here are my build.gradle dependencies for the wear app: 这是我的Wear应用程序的build.gradle依赖项:

  • implementation fileTree(dir: 'libs', include: ['*.jar']) 实现fileTree(dir:'libs',包括:['* .jar'])
  • implementation 'com.google.android.support:wearable:2.3.0' 实施'com.google.android.support:wearable:2.3.0'
  • implementation 'com.google.android.gms:play-services-wearable:15.0.1' 实施'com.google.android.gms:play-services-wearable:15.0.1'
  • implementation 'com.android.support:percent:27.1.1' 实施'com.android.support:percent:27.1.1'
  • implementation 'com.android.support:support-v4:27.1.1' 实施'com.android.support:support-v4:27.1.1'
  • implementation 'com.android.support:recyclerview-v7:27.1.1' 实施'com.android.support:recyclerview-v7:27.1.1'
  • implementation 'com.android.support:wear:27.1.1' 实施'com.android.support:wear:27.1.1'
  • compileOnly 'com.google.android.wearable:wearable:2.3.0' compileOnly'com.google.android.wearable:wearable:2.3.0'
  • implementation 'com.android.support:appcompat-v7:27.1.1' 实施'com.android.support:appcompat-v7:27.1.1'
  • implementation 'com.android.support.constraint:constraint-layout:1.1.1' 实施'com.android.support.constraint:constraint-layout:1.1.1'
  • implementation 'com.android.support:cardview-v7:27.1.1' 实施'com.android.support:cardview-v7:27.1.1'
  • implementation 'com.android.support:support-compat:27.1.1' 实施'com.android.support:support-compat:27.1.1'
  • implementation 'com.android.support:support-core-utils:27.1.1' 实现'com.android.support:support-core-utils:27.1.1'
  • implementation 'com.android.support:support-core-ui:27.1.1' 实施'com.android.support:support-core-ui:27.1.1'

I also get a lot of these weird comments in my Logcat file: 我在Logcat文件中也得到了很多这些奇怪的评论:

  • I/vndksupport: sphal namespace is not configured for this process. I / vndksupport:未为此过程配置sphal命名空间。 Loading /vendor/lib/hw/gralloc.mt2601.so from the current namespace instead. 而是从当前名称空间加载/vendor/lib/hw/gralloc.mt2601.so。

I have tried everything - the funny thing is that when I run this from the main phone app as a regular notification it works. 我已经尝试了所有方法-有趣的是,当我从主手机应用程序运行此程序作为常规通知时,它可以正常工作。 I am able to open up apps that I use layouts for - this only happens for notifications? 我可以打开使用布局的应用程序-这仅在通知发生吗? What am I missing? 我想念什么?

  • Is one of my library references conflicting with another one? 我的一个库引用是否与另一个引用冲突?
  • Is there a rule that prohibits us from being able to open up a notification from a wear app as opposed to a regular android app? 是否有一条规则禁止我们打开Wear应用(而不是常规android应用)的通知?
  • Is there some way to make sure that the notification bar at the bottom of the interface is enabled? 有什么方法可以确保启用了界面底部的通知栏?

Any thoughts and suggestions are greatly appreciated! 任何想法和建议,不胜感激!

Yeah . 是的 . . so . 这样。 . . I didn't assign a notification channel : 我没有分配通知渠道

NotificationChannel issue in Android O Android O中的NotificationChannel问题

If you don't have a notification channel in the newer API versions (API 26+) it doesn't allow your notification to be displayed. 如果您在较新的API版本(API 26+)中没有通知通道,则不允许您显示通知。

Of course the new documentation points it out as well: ) Otherwise, you have to notice the tiny error message amongst a million others that don't seem to have an overly negative effect: 当然,新文档也指出了这一点:)否则,您必须注意一百万个微小的错误消息,这些错误消息似乎并没有产生过大的负面影响:

06-20 20:15:16.251 296-900/? 06-20 20:15:16.251 296-900 /? E/NotificationService: No Channel found for pkg=com.xxxx.xxxxxxx, channelId=null, id=1, tag=null, opPkg=com.xxxx.xxxxxxx, callingUid=10049, userId=0, incomingUserId=0, notificationUid=10049, notification=Notification(channel=null pri=0 contentView=null vibrate=default sound=null defaults=0x2 flags=0x0 color=0x00000000 actions=1 vis=PRIVATE) E / NotificationService:未找到以下频道:pkg = com.xxxx.xxxxxxx,channelId = null,id = 1,tag = null,opPkg = com.xxxx.xxxxxxx,callingUid = 10049,userId = 0,incomingUserId = 0,notificationUid = 10049,通知=通知(channel = null pri = 0 contentView = null振动=默认声音= null defaults = 0x2标志= 0x0 color = 0x00000000操作= 1 vis = PRIVATE

Also, changed my minSdkVersion to 26 and ended up with the below Gradle dependency declarations: 此外,将我的minSdkVersion更改为26,并得到以下Gradle依赖项声明:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.support:wearable:2.3.0'
    implementation 'com.google.android.gms:play-services-wearable:15.0.1'
    implementation 'com.android.support:percent:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:wear:27.1.1'
    compileOnly 'com.google.android.wearable:wearable:2.3.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM