I made an app and I implemented push notifications and it works but I've tried to change the default icon with a image.png but it's not working the way that I expected. This is how my notification looks:
And I want my icon to look like this:
I've added in my android manifest this:
<!-- Add custom icon to the notifications -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_notifications" />
<!-- Change the color of the icon -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorPrimary" />
I don't know what I've done wrong but can you help me?
The android:resource (#folder/name)in the meta-data tag refers to the notification icon should be located in android\app\src\main\res\ folder-size\ name.png.
For your exact scope, you need the drawable-size folder in the specific location with pngs named ic_notifications. I suggest you use this amazing tool to generate all the required icons with the correct layout (white on transparent).
Because you also have a color for your notification, you must add the colors.xml in android/app/src/main/res/values which will contain your colorPrimary:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFFFFF</color>
</resources>
Extra: The android:icon in the application tag refers to the app's icon. Just want to add this extra piece of information because it can be confusing at first when the example found are pretty similar.
Related
How would I implement a monochrome icon like other google apps so that it matches the dynamic colours picked by Material You?
Open your app icon and add the monochrome android:drawable attribute to the <adaptive-icon> element. For example, in res/mipmap-anydpi-v26/ic_launcher.xml:
<adaptive-icon >
<background android:drawable="..." />
<foreground android:drawable="..." />
<monochrome android:drawable="#drawable/mymonochromeicon" />
</adaptive-icon>
If your try this and it does not work then you need to remove the android:roundIcon element from your AndroidManifest.xml, or, alternatively, also add the <monochrome android:drawable="#drawable/mymonochromeicon"/> tag to your round icon.
Android Studio might give a warning saying Element monochrome is not allowed here however we can ignore this.
I have integrated splash screen into my app from android manifest I gave it a newly made SplashTheme and whenever the onActivityCreated called I change it to the one that is needed. Now , in splash.xml file which you can see below:
<item>
<color android:color="#color/colorPrimary" />
</item>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher" />
</item>
I put my launcher ic_launcher in the center but when the device in which the app is installed uses round icons the splash screen still shows the "original" icon. I know because I put here ic_launcher instead of ic_launcher_round but I would like to make this part dynamic, to recognize if the devices uses round icons put ic_launcher_round and the opposite.
Here is the part of my AndroidManifest.xml:
Afaik, you cannot achieve the behavior you expect, simply because there does not exist an API, that would provide you whether current launcher uses round icon or a default icon.
Instead, you should construct your splash screen in a way, that is not dependent on the default launcher implementation of the device. Normally, you should have the same image regardless launcher uses round or normal icons.
Leave launcher icons aside and create a resource specifically for splash screen.
I'm new with FCM. I cannot make FCM use my app icon as notification icon and the icon is always a white blank one.
I imported an icon to mipmap folders but nothing seems changed. As some dude say that this is because of lollipop notification as in this question
But the problem is, the FCM notification automatically pops up and I cannot get the Notification builder to override the icon. How can I change it?
This is the default behaviour of FCM. When app is in background it will take white icon.
Use this tag and put it in your Manifest. For me this worked. Hope it works for you too. Ensure meta-data is inside application like the example mentioned in quickstart
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<!-- [START fcm_default_icon] -->
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<!-- [END fcm_default_icon] -->
<!-- [START fcm_default_channel] -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id" />
<!-- [END fcm_default_channel] -->
<activity
android:name=".EntryChoiceActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".kotlin.MainActivity" />
<activity android:name=".java.MainActivity" />
If you are having this problem
See this link: Icon not displaying in notification: white square shown instead
I had the same problem. I solved by making transparent image from designer.
Make sure your logo should be 72*72 pixels.
NOTE: Don't time waste in googling this issue, you just need a transparent icon which should be 72*72 dimensions.
The only thing that worked for me was to generate a Notification icon image asset in Android studio.
To use the an image as the notification icon, just set Asset type to "Image" and select the file.
Tip #1: use an icon which is of white color, on transparent background!
Tip #2: if the preview on the right side of the window contains only white squares, your notification icon will look just like that - white squares!
Tip #3: the Name of the asset is what should be added into the meta-data tag in AndroidManifest
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/whatever_you_set_for_image_asset_name" />
Source: Taken from this answer
Keep your notification small as 72 x 72 and make it completely white. See the photo attached with this answer.
Then paste the codes below into your manifest.
<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_money" />
You can make a new icon from default icons pack of Android Studio.
For this right click on your drawable folder > New > Image Asset
I faced same problem and did everything suggested here and nothing worked.
Eventually, downgrading the firebase plugin from 11.8.0 to 11.6.0 resolves it with the help of this github issue.
This might also help someone.
When no icons are set for incoming notifications, firebase will take the default icon and shows notification.
To override the default icon add below code into your Android manifest file
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
For more information you can follow the link
I have tried both Theme.DeviceDefault and Theme.Black in my styles.xml, and both make my 2.1 emulator become black correctly, but on the 4.1 emulator it stays white...am I doing something wrong?
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
PS: I presume the drop-down for "Theme" at the top of the Graphical Layout is just showing me what it would look like, it's not some kind of setting that's going somewhere (for the app)?
The Android system always chooses the most special values folder that fits best to your device.
As example if you have a folder values and another folder values-v14 the Android system takes resources from the latter if the device is v14 or newer.
Please refer to the Android documentation for more information.
1.create new folder under res -> values-v13
2.create file style there and add this style :
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
in your manifast use this style for your application like this
<application
android:name=".MainApp"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
that way on ICS version you use the Holo.light theme and pre ICS use the default you already created
Setting it via styles doesn't actually work, but if you set it explicitly for application it works.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black" >
By default 4.0 and 4.1 give us white background but you can change it to black I face the same problem some days ago, if your project theme is set to be black then probably you change the Title while creating project to "Main" by default its "MainActivity" but if you change it to "Main" it will give you black backgrount/
I don't know my answer is relevant to your question or not but i think you talking about this if i am not wrong.
i would like to get rid of the defualt grey bar which apears at the top of my application.
I just can't seem to find the attribute or setting to do so.
how can this be achived?
thanks
Use android:theme="#android:style/Theme.NoTitleBar", either for this specific <activity> element in your manifest, or for the whole <application> element if you want it gone for all of them. Here's a FAQ entry about it.
I tried the manifest method but for some reason it wasn't working.
However using the .java method as described here worked.
requestWindowFeature(Window.FEATURE_NO_TITLE);
Open app/src/main/res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
A good article why you should avoid removing the title bar from an app by Googler Reto Meier:
http://blog.radioactiveyak.com/2010/07/how-to-display-android-status-bar-in.html
Read and rethink if you really need to remove the title bar from your app.