我一整天都在努力,无法找出断开连接的位置。请在下面找到我的磨损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依赖项:
我在Logcat文件中也收到了很多这些奇怪的评论:
我已经尝试了一切 - 有趣的是,当我从主手机应用程序运行此作为常规通知时,它可以工作。我可以打开我的应用程序 使用布局 - 这只发生在通知中?我错过了什么?
非常感谢任何想法和建议!
答案 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'
}