我通过以下代码在BroadcastReceiver中创建通知:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = R.drawable.ic_stat_notification;
CharSequence tickerText = "New Notification";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_VIBRATE;
long[] vibrate = {0,100,200,200,200,200};
notification.vibrate = vibrate;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(context, NotificationActivity.class);
notificationIntent.putExtra(Global.INTENT_EXTRA_FOO_ID, foo_id);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
int mynotification_id = 1;
mNotificationManager.notify(mynotification_id, notification);
Run Code Online (Sandbox Code Playgroud)
当我点击通知时,它会打开NotificationActivity,在Activity中我可以从Intent-Bundle中检索foo_id(例如1)
但是,如果触发另一个通知并再次单击它,则活动仍会从Intent-Bundle接收"旧"值(1).我试图用clear()清除包,但收到的效果相同.我觉得我的代码错了......
android android-notifications android-notification-bar android-pendingintent
Android 4.1为用户提供了一个复选框,用于禁用特定应用程序的通知.
但是,作为开发人员,我们无法知道对通知的调用是否有效.
我真的需要检查当前应用程序是否禁用了通知,但我在API中找不到任何设置.
有没有办法在代码中检查此设置?
我有这个代码:
Notification notif;
// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIntent(pendingIntent);
notifBuilder.setContentTitle(title);
notifBuilder.setSmallIcon(icon_resId);
notifBuilder.setContentText(ne.getCaption());
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
notifBuilder.setAutoCancel(autocancel);
notifBuilder.setWhen(System.currentTimeMillis());
notif = notifBuilder.build();
Run Code Online (Sandbox Code Playgroud)
在Android 4.4中运行良好.
但是,在Android 5.0中,状态栏中显示的图标是白色方块.设备锁定时显示的新"通知正文"中显示的图标是正确的.
在http://developer.android.com/reference/android/app/Notification.Builder.html中,我没有看到有关API级别21的通知图标的任何新内容
notifications android android-notification-bar android-5.0-lollipop
我需要创建一个简单的通知,如果可能的话,它会与声音和图标一起显示在通知栏中?我还需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API.如果有更好的解决方案,请随意提及.
notifications android android-notifications android-notification-bar
在我的Android应用程序中,我想动态设置将从URL加载的通知图标.为此,我使用setLargeIcon了NotificationBuilder的属性receiver.我提到了许多链接并尝试了各种解决方案,但无法获得所需的输出.虽然我从url下载了该图像并在通知中设置了该位图,但它并未显示.相反,它将setSmallIcon图像显示为大图标.我不知道我哪里错了.我在这里发布我的代码.请帮我解决这个问题.谢谢.
码:
@SuppressLint("NewApi")
public class C2DMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.e("C2DM", "received message");
final String fullName = intent.getStringExtra("message");
final String payload1 = intent.getStringExtra("message1");
final String payload2 = intent.getStringExtra("message2");
final String userImage = intent.getStringExtra("userImage");
Log.e("userImage Url :", userImage); //it shows correct url
new sendNotification(context)
.execute(fullName, payload1, userImage);
}
}
private class sendNotification extends AsyncTask<String, Void, Bitmap> {
Context ctx;
String message; …Run Code Online (Sandbox Code Playgroud) android bitmap android-notifications android-notification-bar google-cloud-messaging
我到处搜索,但在SDK或Google上找不到任何关于如何执行此操作的内容.我知道这是可能的,因为所有自定义发射器都可以通过按钮按下(LauncherPro,ADW等)来完成.
谢谢.
我正在开发一个基于通知的应用程序,我需要收听传入的通知.我已经能够收听来电,短信,邮件等.我不知道如何通过代码在Whatsapp上听朋友的ping或消息.这可以实际完成吗?如果是这样,怎么样?可以使用Accessibility Service,使用Package Name作为"com.whatsapp"吗?
android android-intent android-notifications android-notification-bar android-broadcast
如图所示......
我收到了通知图标(左侧是红色).
但我需要显示黑色箭头所示的应用程序图标
public void notify(View view){
notification.setSmallIcon(R.drawable.ic_stat_name);
notification.setTicker("Welcome to ****");
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle("abcd");
notification.setContentText("abcd");
Intent intent = new Intent(this, home.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueID, notification.build());
}
Run Code Online (Sandbox Code Playgroud) notifications android android-notifications android-notification-bar android-studio
我在GCMIntentservice中编写了一个代码,用于向许多用户发送推送通知.我使用NotificationManager,在单击通知时将调用DescriptionActivity类.我还将event_id格式的GCMIntentService发送到DescriptionActivity
protected void onMessage(Context ctx, Intent intent) {
message = intent.getStringExtra("message");
String tempmsg=message;
if(message.contains("You"))
{
String temparray[]=tempmsg.split("=");
event_id=temparray[1];
}
nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
intent = new Intent(this, DescriptionActivity.class);
Log.i("the event id in the service is",event_id+"");
intent.putExtra("event_id", event_id);
intent.putExtra("gcmevent",true);
PendingIntent pi = PendingIntent.getActivity(this,0, intent, 0);
String title="Event Notifier";
Notification n = new Notification(R.drawable.defaultimage,message,System.currentTimeMillis());
n.setLatestEventInfo(this, title, message, pi);
n.defaults= Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
sendGCMIntent(ctx, message);
}
Run Code Online (Sandbox Code Playgroud)
这里我在上面的方法中得到的event_id是正确的,即我总是得到更新的.但是在下面的代码中(DescriptionActivity.java):
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
Run Code Online (Sandbox Code Playgroud)
这里的event_id总是"5".无论我把什么放在GCMIntentService类中,我得到的event_id总是5.有人可以指出问题吗?是因为未决意图?如果是,那我该怎么处理呢?
push-notification android-notifications android-notification-bar android-pendingintent
我正在尝试将通知放在通知区域之上.
解决方案是将参数"when"设置为我的通知对象,其未来时间如下:
notification.when = System.currentTimeMills()*2;
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码:
long timeNotification = System.currentTimeMillis()*2;
Notification notification = new Notification(statusIcon,c.getResources().getString(R.string.app_name),timeNotification);
notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
notification.when = timeNotification;
notification.priority = Notification.PRIORITY_MAX;
Run Code Online (Sandbox Code Playgroud)
但是有些应用程序(比如Facebook)可以用他们当前的时间对我进行简单的通知.
如果我刷新我的通知,它仍然在这些通知之下.
我需要设置哪些参数才能将我Notification置于通知区域的顶部?
notifications android notification-bar android-notification-bar