[英]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依赖项:
I also get a lot of these weird comments in my Logcat file: 我在Logcat文件中也得到了很多这些奇怪的评论:
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?
我想念什么?
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.