在佩戴应用程序中创建的通知不会在Android智能手表上显示

时间:2018-06-18 00:04:41

标签: android android-studio android-wear-notification

我一整天都在努力,无法找出断开连接的位置。请在下面找到我的磨损app方法,我在其中调用来自广播接收器的通知请求:

private void createWearNotification(final String notificationString,final String name,final String 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());
}

我在androidmanifext.xml doc中有以下声明:

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

以下是wear app的build.gradle依赖项:

  • 实施fileTree(目录:&#39; libs&#39;,包括:[&#39; * .jar&#39;])
  • 实施&#39; com.google.android.support:wearable:2.3.0&#39;
  • 实施&#39; com.google.android.gms:play-services-wearable:15.0.1&#39;
  • 实施&#39; com.android.support:百分比:27.1.1&#39;
  • 实施&#39; com.android.support:support-v4:27.1.1&#39;
  • 实施&#39; com.android.support:recyclerview-v7:27.1.1&#39;
  • 实施&#39; com.android.support:穿:27.1.1&#39;
  • compileOnly&#39; com.google.android.wearable:wearable:2.3.0&#39;
  • implementation&#39; com.android.support:appcompat-v7:27.1.1&#39;
  • implementation&#39; com.android.support.constraint:constraint-layout:1.1.1&#39;
  • 实施&#39; com.android.support:cardview-v7:27.1.1&#39;
  • implementation&#39; com.android.support:support-compat:27.1.1&#39;
  • implementation&#39; com.android.support:support-core-utils:27.1.1&#39;
  • 实施&#39; com.android.support:support-core-ui:27.1.1&#39;

我在Logcat文件中也收到了很多这些奇怪的评论:

  • I / vndksupport:未为此进程配置sphal命名空间。 从当前命名空间加载/vendor/lib/hw/gralloc.mt2601.so 代替。

我已经尝试了一切 - 有趣的是,当我从主手机应用程序运行此作为常规通知时,它可以工作。我可以打开我的应用程序 使用布局 - 这只发生在通知中?我错过了什么?

  • 我的某个图书馆参考资料是否与另一个图书馆资料相冲突?
  • 是否有规则禁止我们从磨损应用程序打开通知而不是常规的Android应用程序?
  • 是否有某种方法可以确保界面底部的通知栏已启用?

非常感谢任何想法和建议!

1 个答案:

答案 0 :(得分:0)

是的。 。 。这样。 。 。我没有分配通知频道

NotificationChannel issue in Android O

如果您在较新的API版本(API 26+)中没有通知通道,则不允许您显示通知。

当然,新文档也指出了这一点:)否则,您必须注意到一百万个微小的错误消息,这些错误消息似乎并没有产生过大的负面影响:

06-20 20:15:16.251 296-900 /? E / NotificationService:未找到pkg = com.xxxx.xxxxxxx,channelId = null,id = 1,tag = null,opPkg = com.xxxx.xxxxxxx,ChannelingUid = 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)

另外,将我的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'
}