创建在状态栏上一个永久通知和prevent通知 [英] Create a persistent notification and prevent notification in status bar
本文介绍了创建在状态栏上一个永久通知和prevent通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我使用了一个Android应用程序下面的code:
I have the following code which I am using for an android app:
package com.authorwjf.e_notifications;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bm = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.avatar),
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height),
true);
Intent intent = new Intent(this, Main.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 01, intent, Intent.FLAG_ACTIVITY_CLEAR_TASK);
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentTitle("This is the title");
builder.setContentText("This is the text");
builder.setSubText("Some sub text");
builder.setNumber(101);
builder.setContentIntent(pendingIntent);
builder.setTicker("Fancy Notification");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setLargeIcon(bm);
builder.setAutoCancel(true);
builder.setPriority(0);
Notification notification = builder.build();
NotificationManager notificationManger =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManger.notify(01, notification);
}
}
基本上当启动该应用程序创建了一个通知,现在我有几个问题:
Basically the app when launched creates a notification, now I have a few questions:
- 是否有可能时,应用程序启动的通知显示在下拉通知列表,但没有在状态栏上的图标。 IE浏览器。请参阅
可以红圈中的图标不显示?最后,我想创建,只是坐在拉下通知的服务。
can the icon circled in red not be displayed? Ultimately I would like to create a service that just sits in the pull down notification.
- 有没有去使下拉通知仍然存在,即。如果图标为蓝色圆圈(http://imagebin.org/226494)是pressed,该通知依然?
我是新来的Android开发人员,只是试图去掌握什么我可以做的通知
I am new to android dev and just trying to get to grips with what I can do with notifications.
感谢
推荐答案
-
A1:要删除的状态栏图标,用这一招:
A1: To remove the status bar icon, use this trick:
builder.setSmallIcon(android.R.color.transparent); //Tested and worked in API 14
-
A2:为了让presistant通知,加入这一行:
A2: To make presistant Notification, add this line:
builder.setOngoing(true)
这篇关于创建在状态栏上一个永久通知和prevent通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文