[英]Notification created within wear app doesn't display on Android smartwatch
我整天都在努力,无法弄清断开的位置。 请在下面的我的穿戴应用方法中找到我从广播接收方调用通知请求的方法:
私人无效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());
}
我的androidmanifext.xml文档中包含以下声明:
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
这是我的Wear应用程序的build.gradle依赖项:
我在Logcat文件中也得到了很多这些奇怪的评论:
我已经尝试了所有方法-有趣的是,当我从主手机应用程序运行此程序作为常规通知时,它可以正常工作。 我可以打开使用布局的应用程序-这仅在通知发生吗? 我想念什么?
任何想法和建议,不胜感激!
是的 。 。 这样。 。 。 我没有分配通知渠道 :
Android O中的NotificationChannel问题
如果您在较新的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,callingUid = 10049,userId = 0,incomingUserId = 0,notificationUid = 10049,通知=通知(channel = null pri = 0 contentView = null振动=默认声音= null defaults = 0x2标志= 0x0 color = 0x00000000操作= 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'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.