android-notifications
startForeground fail after upgrade to Android 8.1
After some tinkering for a while with different solutions i found out that one must create a notification channel in Android 8.1 and above. private fun startForeground() { val channelId = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel(“my_service”, “My Background Service”) } else { // If earlier version channel ID is not used // https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context) “” … Read more
Android 4.1: How to check notifications are disabled for the application?
You can’t 100% can’t. It is asked in this Google I/O 2012 video and the Project lead for the new notifications declares that you can’t. Edit 2016 update: Now you can check it, as said in this Google I/O 2016 video. Use NotificationManagerCompat.areNotificationsEnabled(), from support library, to check if notifications are blocked on API 19+. … Read more
Custom notification layouts and text colors
The solution is to use built-in styles. The style you need is called TextAppearance.StatusBar.EventContent in Android 2.3 and Android 4.x. In Android 5.x material notifications use several other styles: TextAppearance.Material.Notification, TextAppearance.Material.Notification.Title, and TextAppearance.Material.Notification.Line2. Just set the appropriate text appearance for the text view, and you will get the necessary colors. If you are interested how … Read more
Change Notification Layout
First create an xml for your notification. custom_notification.xml: <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/layout” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:padding=”10dp” > <ImageView android:id=”@+id/image” android:layout_width=”wrap_content” android:layout_height=”fill_parent” android:layout_alignParentLeft=”true” android:layout_marginRight=”10dp” /> <TextView android:id=”@+id/title” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_toRightOf=”@id/image” style=”Custom Notification Title” /> <TextView android:id=”@+id/text” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_toRightOf=”@id/image” android:layout_below=”@id/title” style=”Custom Notification Text” /> </RelativeLayout> Now the java code: public class MainActivity extends Activity { @SuppressWarnings(“deprecation”) @Override public … Read more
Notification bar icon turns white in Android 5 Lollipop
The accepted answer is not (entirely) correct. Sure, it makes notification icons show in color, but does so with a BIG drawback – by setting the target SDK to lower than Android Lollipop! If you solve your white icon problem by setting your target SDK to 20, as suggested, your app will not target Android … Read more
Notification not showing in Oreo
In Android O it’s a must to use a channel with your Notification Builder below is a sample code : // Sets an ID for the notification, so it can be updated. int notifyID = 1; String CHANNEL_ID = “my_channel_01”;// The id of the channel. CharSequence name = getString(R.string.channel_name);// The user-visible name of the channel. … Read more
Create a notification
I think you want to implement firebase to your app to show notifications. use push-notifications. steps: add firebase to your android project . you can see the step by step here. https://firebase.google.com/docs/android/setup the next step is to read and write data to firebase. https://firebase.google.com/docs/database/android/read-and-write here when you read the data you can push notification. if … Read more