我从我的应用程序(而不是服务)管理ONGOING通知.
当我用任务管理器用"结束"按钮终止应用程序时,通知消失.
当我从多任务pannel中删除应用程序时,应用程序被杀死但通知仍然存在.
我的问题是:
作为更新:
我的所有活动都使用以下方法扩展了MyActivity类(扩展了Activity):
@Override protected void onCreate(Bundle state) {
super.onCreate(state);
((MyApplication) getApplication()).onActivityCreate(this, state);
}
@Override protected void onDestroy() {
super.onDestroy();
((MyApplication) getApplication()).onActivityDestroy(this);
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序使用以下方法扩展了MyApplication类(扩展了Application):
private List<Activity> activities = new ArrayList<Activity>();
protected final void onActivityCreate(Activity activity, Bundle state) {
if(activities.isEmpty() && state == null) {
onStart();
}
activities.add(activity);
}
protected final void onActivityDestroy(Activity activity) {
activities.remove(activity);
if(activities.isEmpty() && activity.isFinishing()) {
onExit();
}
}
protected void onStart() {
// some code …Run Code Online (Sandbox Code Playgroud) 在使用Android Messages ver 2.3.063发送彩信时,我正在举报"开发人员警告包com.google.android.apps.messaging".
在日志中
08-12 16:57:52.368 7661 7682 W Notification: Use of stream types is deprecated for operations other than volume control
08-12 16:57:52.368 7661 7682 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
08-12 16:57:52.369 1604 3146 E NotificationService: No Channel found for pkg=com.google.android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.375 1604 3094 D …Run Code Online (Sandbox Code Playgroud) 我遵循了这个示例代码
在Big Text Notifications部分中,他说需要扩展才能看到Big text notification形式,如下图所示:

我不知道我们做不到 set Expanded Notification as default in Big Text Notifications?
知道它的人是否可以,
如果能,
请告诉我怎么做,
谢谢,
我想在Android Wear上实现堆叠通知为此,我为每个"项目"创建了1个摘要通知和N个单独通知.我只想在手机上显示摘要.这是我的代码:
private void showNotifications() {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
showNotification1(notificationManager);
showNotification2(notificationManager);
showGroupSummaryNotification(notificationManager);
}
private void showNotification1(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 1", "message 1", 1);
}
private void showNotification2(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 2", "message 2", 2);
}
protected void showSingleNotification(NotificationManager notificationManager,
String title,
String message,
int notificationId) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.mipmap.ic_launcher)
.setGroupSummary(false)
.setGroup("group");
Notification notification = builder.build();
notificationManager.notify(notificationId, notification);
}
private void showGroupSummaryNotification(NotificationManager notificationManager) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); …Run Code Online (Sandbox Code Playgroud) 我试图从通知发送信息到被调用的活动,而从我的活动我得到null.
通知代码是:
private void showNotification() {
Intent resultIntent = new Intent(this, MainActivity.class);
if (D)
Log.d(TAG, "Id: " + Id);
resultIntent.putExtra("ineedid", deviceId);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MeterActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
// Bundle tmp = resultIntent.getExtras();
// if (tmp == null) {
// Log.d(TAG, "tmp bundle is null");
// } else {
// long id = tmp.getLong("ineedid", -1);
// Log.d(TAG, "tmp id : " + id);
// }
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
BLEMessengerService.this)
.setSmallIcon(R.drawable.ic_action_search)
.setContentTitle("Event tracker")
.setContentText("Events received").setOngoing(true) …Run Code Online (Sandbox Code Playgroud) android bundle android-intent android-notifications android-pendingintent
我想知道是否有可能从掌上电脑(Android手机)发送通知来佩戴设备打开穿戴设备上的活动?我想做的是如下.

到目前为止,我检查了以下文档,但它与我想要做的不同.
有任何想法吗?
我正在开发一个应用程序,我在那里为用户创建通知.我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色.以下是Google Store应用程序执行相同操作的示例.
状态栏中的白色通知:
下拉菜单中的彩色通知:
我怎么能复制这个?我需要设置哪些属性?
编辑: 这是我当前的代码 - 我使图像全白,透明背景,所以它在状态栏中看起来很好,但在通知中,图像仍然是相同的白色:
private NotificationCompat.Builder getNotificationBuilder() {
return new NotificationCompat.Builder(mainActivity)
.setDeleteIntent(deletedPendingIntent)
.setContentIntent(startChatPendingIntent)
.setAutoCancel(true)
.setSmallIcon(R.drawable.skylight_notification)
.setColor(ContextCompat.getColor(mainActivity, R.color.colorPrimary))
.setContentTitle(mainActivity.getString(R.string.notification_title))
.setContentText(mainActivity.getString(R.string.notification_prompt));
}
Run Code Online (Sandbox Code Playgroud) 我有一个类在Android中发送状态栏通知.我找不到测试通知是否发送的方法,这使得编写任何有用的单元测试变得非常困难.
有人有解决方案吗?
我反编译我的系统音乐应用程序(来自索尼爱立信Android版2.3.7),因为我想更改通知布局.我找到了使用此代码创建通知的方法:
private void sendStatusBarNotification(Track paramTrack)
{
if (paramTrack != null)
{
NotificationManager localNotificationManager = (NotificationManager)this.mContext.getSystemService("notification");
String str = paramTrack.getArtist();
if ((str == null) || (str.equals(this.mContext.getString(2131361954))))
str = this.mContext.getString(2131361798);
Notification localNotification = new Notification(2130837696, paramTrack.getTitle() + " - " + str, System.currentTimeMillis());
localNotification.flags = (0x2 | localNotification.flags);
localNotification.flags = (0x20 | localNotification.flags);
PendingIntent localPendingIntent = PendingIntent.getActivity(this.mContext, 0, new Intent(this.mContext, MusicActivity.class), 268435456);
localNotification.setLatestEventInfo(this.mContext, paramTrack.getTitle(), str, localPendingIntent);
localNotificationManager.notify(0, localNotification);
}
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是:如何更改通知布局?我想构建一个看起来像原始Android通知布局但在通知右侧有一个额外图像的布局.我怎样才能做到这一点?