I am following this tutorial on notifications, however, my notification is greyed out.
I know there's remote views to style it, but this developers guide does not use it.
Here is an example of how my notification looks
In your builder, use .setColor()
it requires a minimum api
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setColor(Color.BLUE);
}
Related
As android google blog clearly mentioned that Android Nougat is not supporting setNumber and setContentInfo at all and even I have tested it on Android Nougat.
Line from Google blog:
In addition, the subtext now supersedes the role of content info and
number
So when I use setNumber for devices prior than Nougat and setSubText for Nougat then Nougat works perfectly only setSubText method works. But when I run it on Devices running prior versions they run both methods as setNumber and setSubText.
So how I can handle this?
Why android prefer setSubText?
In addition what is the difference between setNumber and setContentInfo ?
So how I can handle this?
Your desired result is to have your notification display whatever you pass to setSubText() on Nougat and above and whatever you pass to setNumber() on Marshmallow and below. You can accomplish this by checking the Build info at runtime:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// your setSubText() code here
} else {
// your setNumber() code here
}
Why android prefer setSubText?
I can only really quote the blog post you linked here. They say:
"Many of the fields that were spread around the notifications have been collapsed into a new header row with your app’s icon and name anchoring the notification."
It sounds to me like a design-based preference.
In addition what is the difference between setNumber and setContentInfo ?
Documentation for setContentInfo(): "Set the large text at the right-hand side of the notification."
Documentation for setNumber(): "Set the large number at the right-hand side of the notification. This is equivalent to setContentInfo, although it might show the number in a different font size for readability." (emphasis added)
I need help. I want to show a popup window over dialog.
On API 23 i did it. But on API >23 i can do this. See images.
API > 23
API < 23
Thanks for help.
#TuNguyen Not sure if you're still looking for an answer but for people who're still facing this: I resolved it using the (WindowLayoutType) for the popupWindow. Adding this works:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
popupWindow.windowLayoutType = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG
//Refer to the android's doc I attached above for the complete list of WindowLayouts
}
//I am using Kotlin
I am using notifications in my app. Each notification has its own specific icon-image. On my phone the notifications work just fine.
However, when I receive the notification on my wearable it always shows the ic_launcher, and not the specific icon-image for the notification.
For testing purposes I am trying to have the wearable show icon_wearable.png in the notification. I already tried putting the icon_wearable.png in different drawable folders (xhdpi hdpi etc.). Right now it is located in the drawable-hdpi folder.
Code used for setting notifications:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle(someString);
builder.setContentText(message);
builder.setWhen(time.getTimeInMillis());
builder.setSmallIcon(R.drawable.some_image);
builder.setAutoCancel(true);
builder.setContentIntent(pendingIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
builder.extend(new Notification.WearableExtender()
.setContentIcon(R.drawable.icon_wearable));
}
Can someone please tell me why the wearable is always showing the ic_launcher and not icon_wearable?
Thanks in advance!
First make sure you use v4 support library because it allows you to create notifications using the latest notification features such as action buttons and large icons.
Make sure you add this line to your build.gradle file.
compile "com.android.support:support-v4:20.0.+"
And this necessary classes from the support library:
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.WearableExtender;
For the guideline and sample code on how to use Notification on Wearables, check this link.
For more information, you are correct to place the icon on the drawable-hdpi directory. Because it is stated in the linked documentation that:
Place other non-bitmap resources for wearable notifications, such as
those used with the setContentIcon() method, in the res/drawable-hdpi directory.
How do I use a MediaSessionCompat? Can someone give a simple working example?
I've found some, but they use:
MediaSessionCompat _mediaSession = new MediaSessionCompat(context, "tag");
This gives me error:
The constructor MediaSessionCompat(Context, String) is undefined and wants me to use MediaSessionCompat(Context, String, ComponentName, PendingIntent)
I found a working example here, which I tested both on kitkat and marshmallow.
https://github.com/tutsplus/background-audio-in-android-with-mediasessioncompat/blob/master/app/src/main/java/com/tutsplus/backgroundaudio/BackgroundAudioService.java
But do take note, sometimes, sometimes lock screen control don't appear because of android settings(i.e Settings > Sounds & Notifications > Notification > While Locked > Hide Sensitive Content) See below:
https://community.spotify.com/t5/Android/Android-Lollipop-Lock-Screen-Controls-Not-Available/td-p/982463
SampleMediaRouterActivity.java in Support7Demos seems to be a good place to start.
https://android.googlesource.com/platform/development/+/master/samples/Support7Demos/src/com/example/android/supportv7/media/
MediaSessionCompat is in android.support.v4 and that is the Constructor it uses.. it is a backward compatibility for MediaSession introduced in api 21, and this is its Constructor;. However if you want to use the Constructor you are referring to you need to compile your project with api 21+;
In the bottom right corner of a standard Android notification is time (eg 12:00). Can I hide it without using custom notification layout?
For API level 17 and onward, the above accepted answer by Erwan is correct.
For historical purposes, the answer below remains
It is possible to do that.
Try setting when to 0.
For the few notifications that don't do that, it looks like thats what they do.
Here's the general API reference.
Here's a link to the ADB notification and search for private void updateAdbNotification()...
From API Level 17 onwards, you can use setShowWhen(false)
public Notification.Builder setShowWhen (boolean show)
Added in API level 17 Control whether the timestamp set with setWhen
is shown in the content view.
http://developer.android.com/reference/android/app/Notification.Builder.html#setShowWhen(boolean)
For API level 17 and onward,
mBuilder.setShowWhen(boolen);
1.Use Hide Notification Time
mBuilder.setShowWhen(false);
2.Use Show Notification Time
mBuilder.setShowWhen(true);