是否有Android标准徽章或方法来显示带有Google示例的计数的操作栏通知图标?

如果没有,那么最好的方法是什么呢?
我是android的新手,请帮忙.
notifications icons android actionbarsherlock android-actionbar
将我的项目升级到Android O后
buildToolsVersion "26.0.1"
Run Code Online (Sandbox Code Playgroud)
Android Studio中的Lint显示以下通知构建器方法的已弃用警告:
new NotificationCompat.Builder(context)
Run Code Online (Sandbox Code Playgroud)
问题是: Android开发人员更新了描述NotificationChannel的文档以支持Android O中的通知,并为我们提供了一个代码段,但使用了相同的弃用警告:
Notification notification = new Notification.Builder(MainActivity.this)
.setContentTitle("New Message")
.setContentText("You've received new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setChannelId(CHANNEL_ID)
.build();
Run Code Online (Sandbox Code Playgroud)
我的问题:是否还有其他解决方案可用于构建通知,并且仍然支持Android O?
我找到的解决方案是将通道ID作为Notification.Builder构造函数中的参数传递.但是这种解决方案并不完全可以重复使用.
new Notification.Builder(MainActivity.this, "channel_id")
Run Code Online (Sandbox Code Playgroud) 如果我想在通知栏中显示通知问题.虽然我将通知标志设置为通知,Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL但在单击后不会消失.我有什么想法我做错了吗?
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence tickerText = "Ticker Text";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, time);
notification.flags = Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL;
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, SilentFlipConfiguration.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,notification);
Run Code Online (Sandbox Code Playgroud) 我在Android中有一个前台服务设置.我想更新通知文本.我正在创建服务,如下所示.
如何更新在此前台服务中设置的通知文本?更新通知的最佳做法是什么?任何示例代码将不胜感激.
public class NotificationService extends Service {
private static final int ONGOING_NOTIFICATION = 1;
private Notification notification;
@Override
public void onCreate() {
super.onCreate();
this.notification = new Notification(R.drawable.statusbar, getText(R.string.app_name), System.currentTimeMillis());
Intent notificationIntent = new Intent(this, AbList.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
this.notification.setLatestEventInfo(this, getText(R.string.app_name), "Update This Text", pendingIntent);
startForeground(ONGOING_NOTIFICATION, this.notification);
}
Run Code Online (Sandbox Code Playgroud)
我正在我的主要活动中创建服务,如下所示:
// Start Notification Service
Intent serviceIntent = new Intent(this, NotificationService.class);
startService(serviceIntent);
Run Code Online (Sandbox Code Playgroud) 我使用Notification.Builder来构建通知.现在我想使用默认声音通知:
builder.setSound(Uri sound)
Run Code Online (Sandbox Code Playgroud)
但是Uri在默认通知中的位置是什么?
我想要在用户点击后关闭通知.我看到每个人都说使用标志,但我无法在任何地方找到标志,因为我使用的是NotificationCompat.Builder类,而不是Notification类.有人知道如何通过她自己删除通知?
我在设置通知时是我的代码:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Question")
.setContentText("" + QuestionData.getAuthor().getUserName() + ": " + QuestionData.getQuestion() + "");
Intent openHomePageActivity = new Intent("com.example.ihelp.HOMEPAGEACTIVITY");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(openHomePageActivity);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
Run Code Online (Sandbox Code Playgroud) 我在App Delegate中设置了本地通知使用此方法:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"Watch the Latest Episode of CCA-TV"];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序然后退出它时,我收到一条错误消息:
2014-06-07 11:14:16.663 CCA-TV [735:149070] 试图安排本地通知 {开火日期= 2014年6月7日星期六太平洋夏令时间11:14:21,时区= America/Los_Angeles (PDT)偏移-25200(日光),重复间隔= 0,重复计数= UILocalNotificationInfiniteRepeatCount,下一个开火日期= 2014年6月7日星期六太平洋夏令时间11:14:21,用户信息=(null)} 带警报但尚未收到用户显示警报的许可
如何获得显示警报的必要权限?
我有一个服务正在运行,并希望发送通知.太糟糕了,通知对象需要一个Context,就像一个Activity,而不是一个Service.
你知道通过哪种方式吗?我试图Activity为每个通知创建一个,但它看起来很难看,我找不到一种方法来启动Activity没有任何通知View.
我需要一个在android上添加通知的程序.当有人点击通知时,它应该引导他们进行第二次活动.
我已经建立了一个代码.通知应该有效,但由于某种原因它无法正常工作.在Notification没有显示的.不知道我错过了什么.
这些文件的代码:
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setContentIntent(pIntent).setAutoCancel(true)
.setStyle(new Notification.BigTextStyle().bigText(longText))
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after it's selected
notificationManager.notify(0, n);
Run Code Online (Sandbox Code Playgroud) 我发现我使用了一种不赞成使用的方法(notification.setLatestEventInfo())
它说使用Notification.Builder.
当我尝试创建一个新实例时,它告诉我:
Notification.Builder cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud) notifications ×10
android ×9
service ×2
api ×1
cocoa-touch ×1
deprecated ×1
eclipse ×1
foreground ×1
icons ×1
ios ×1
ios8 ×1
uri ×1