Android: system notification icon - android

I'm developing an Android application that implements a vpn service.
During the lifetime of a VPN connection, a system-managed notification is shown, as is reported on the documentation: http://developer.android.com/reference/android/net/VpnService.html
This notification actually seems to show the icon I provided as application icon, but I noticed that the icon is resized on some devices and its ratio is modified. I made the various launcher icons (ldpi,mdpi...xxxhdpi) according to the size here: http://developer.android.com/design/style/iconography.html
Where am I wrong? Where does that system notification icon is taken by the system?

By default, a VpnService, like any Service inherits the icon from your application unless you specify one in your manifest via android:icon. You should create an icon per the notification icon specifications (tools like Android Asset Studio can help) and set that as the android:icon for your service:
<service android:name=".ExampleVpnService"
android:icon="#drawable/notification_icon"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
</service>

I'm afraid that's not possible.
Pre-Lollipo, look at Vpn.java:504 - it loads the launcher icon specifically. It seems quite deliberate - probably due to security concerns to prevent misleading the user.
Post Lollipop they moved it into Quick Settings UI, so I'm not sure there's an icon, but if there is, its probably hardcoded to use the launcher icon as well, for the same reasons.

Related

My app shows different icon on phone app setting

Apps shows different icon on phone app settings and icons are normal anywhere else I tried different icons and restart emulator but nothing happened help me please.
App on menu:
App on settings:
App on task:
Possibly, your app has an icon in both the <application> and <activity> elements in the AndroidManifest.xml. If these icons are different, you will see the <activity> icon on the home screen (because it starts the activity), and the <application> icon in the settings (because it represents the app).

How to change Android Oreo launcher icon daily? [duplicate]

I wanna create an Android application, and I want to dynamically and automatically update the app icon similarly to how the calendar icon updates on a user's homescreen.
The calendar changes its icon for each day showing day of month's number. There is also an Alarm clock app which changes its icon setting the current time, in other words, changing every minute.
That isn't a widget, but a real app icon. Then it must have a way to do so. How can I do it in my app?
Whatever your home screen is has special hooks for whatever your calendar app is and whatever your alarm clock app is. In general, apps cannot update their icons.
What do you mean by hooks?
For example, Samsung can ship a Samsung calendar app on Samsung devices. Samsung's home screen on those same Samsung devices can have special rules for rendering an icon for Samsung's calendar app, rules that involve showing the day of the month. This is because Samsung wrote the home screen. If you install a third-party home screen, it may not do the same thing. After all, I can write a home screen in an hour or so, and I feel quite confident that I don't have to do anything special for Samsung's calendar app.
There's nothing stopping Samsung from exposing some sort of API to allow developers to hook into Samsung's home screen and notify it about this sort of thing. Whether Samsung intends for third parties to use that API, or whether it is somebody hacking into how Samsung does it for their own apps, I can't say.
(BTW, I am citing Samsung here as a possible example -- I don't know that they actually have this sort of feature, and if so on which devices they have it)
I seem to recall that somebody has a GitHub project that tries to wrap the proprietary APIs of various home screens. IIRC, some supported capabilities included either replacing the app icon or adding a badge (e.g., unread message count). However:
Only a small percentage of devices will support those proprietary APIs
Undocumented and unsupported APIs, discovered through reverse-engineering apps, are subject to change and may break in unexpected ways
I am quite certain that there is nothing in the Android SDK that supports dynamic app icons. The only thing that I know of, that people have tried, is using <activity-alias> to have N different "activities", all pointing to the same implementation, but having different icons. Using PackageManager and setComponentEnabledSetting(), the app disables the old launcher alias and enables a different one, in hopes that home screens will pick up on this and show the new icon. A few do. Others only would find out about the change on a reboot.
To flip the problem around, I can write a home screen. Perhaps I want to offer some way for apps to change their icons on the fly, even though there are no standards for it. Perhaps I don't. Perhaps I do not intend to use icons at all, as my home screen is optimized for the visually impaired, and so it is using text-to-speech and hardware key input. It's my home screen implementation, and I can do what I want.
Indeed even in the app drawer in Android O, the Clock app icon shows the current time and the Calendar app icon shows the current day-of-month.
This article explains:
Chris Lacy, the developer behind the well-known Action Launcher, has uncovered something in the APK file of the Clock app that comes in Android O: the manifest.xml mentions hours, minutes, and seconds as layers with default values, and the icon has separate images for the background and different elements.
That logically lead him to deduce that starting with Android O, the Clock app's icon will be animated to show the current time. That will happen both when the Clock is placed as a shortcut on the homescreen and when it's inside the app drawer.
It sounds like the Pixel launcher selects different icon image layer resources depending on time and date.
I'm a launcher developer.
I did nothing related to dynamic icon hooks. I just get the activities' icons by the standard way provided by Android API.
And I found that my launcher do show the current time in the Clock app icon and the current date in the Calendar icon.
The device is a Nubia X which runs Android 8.
The operating system should have done something with the two apps and changed their icons dynamically without the launcher beings aware of it.
These two apps are developed by the device manufacturer. You should not be able to do the same thing in a normal way as a third party developer.
you can define multiple activity-alias in your manifest file for each icon
<activity-alias
android:name="OneLauncherAlias"
android:enabled="true"
android:icon="#drawable/one"
android:label="One"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
Enable and disable the activity-alias based on your requirement.
packageManager.setComponentEnabledSetting(ComponentName(this#MainActivity, com.misles.dynamiclaunchericon.OneLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
packageManager.setComponentEnabledSetting(ComponentName(this#MainActivity, com.misles.dynamiclaunchericon.TwoLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
for details refer this article
https://medium.com/#simonmisles/dynamic-launcher-icon-and-name-for-android-e40bf0561715
I have the same question but the answer provided here does not aswer it.
I have Google Pixel 2 with raw Android Ore 8.1 on the board and there are two apps that are changing over time: Calendar and Clock. The hands on the clock of Clock app show current time and the number on the Calendar icon correspond to today date of month.
So taking into account that it is default launcher probably there is some API to do similar thing.
For instance it might be the planetary app that reflects planets' positions on the icon. Or memory cleaner that shows percentage of used memory...
The launcher handles the dynamic calendar by accessing an icon for each day from the calendar app. For example, with Google Calendar, a Launcher developer may do the following:
Resources res = activity.getPackageManager()
.getResourcesForApplication("com.google.android.calendar");
int resId = res.getIdentifier("logo_calendar_01_regular", "drawable"
, "com.google.android.calendar");
Drawable icon = res.getDrawable(resId);
This would access the calendar icon for Day 1 of the month. To access any other day, "logo_calendar_01_regular" would be changed for the current day. For example, day 7 would be "logo_calendar_07_regular". Also Google calendar has two styles, "logo_calendar_01_regular" and "logo_calendar_01_round".
Also Icon themes contain separate icons for each date as well.
Adding more context here to #commonsware's answer.
Did a bit more digging on how google does it with their calendar and clock app.
They seem to have special cases in the launcher code as seen here:
https://cs.android.com/android/platform/superproject/+/master:packages/apps/Launcher3/src/com/android/launcher3/icons/IconProvider.java;l=54;drc=337c81f6646e8d8351604ee2e1dd1884bc7d0452
and here:
https://cs.android.com/android/platform/superproject/+/master:packages/apps/Launcher3/src/com/android/launcher3/icons/IconProvider.java;l=74;drc=337c81f6646e8d8351604ee2e1dd1884bc7d0452
So only workaround at this time to do this is to have multiple
activity aliases with different icons and then switch between those aliases.
http://blog.jakelee.co.uk/programmatically-changing-app-icon/

Android/MIUI Setting small icon in notification bar not working? Default icon displayed

Tried every possibility to set small icon in status bar(which would get carried on by system as large icon in opened notification drawer) but nothing is working.
Tried using raw .png file as well as drawable .xml files and combination of both(xml's referring to png as source of bitmap).
Also, I did add resource using AndroidStudio New -> Image Asset -> Notification icon which gracefully converted it to required versions and stripped from all colors except white and alpha channel.
No matter what I do the default launcher icon is displayed instead of my own.
The answer is short and simple: Reboot your phone!
MIUI caches notification icons and after installing application they are not updated along with app updates(often during developing cycle). Also uninstalling and installing again does not resolve the problem. The only way in this case was to reboot the phone.
I also suspect MIUI theme manager which may be responsible for this as I saw some themes changing app icons system-wide, so it may probably bypass any settings made in Notification.Builder. On top of that, any of the tricks like changing resources in RemoteView of built notification also does not work. Beware of MIUI!

Use an application as only app on an android device

I'm going to write an application for a special device. The device's OS is android and it connects to a TV with HDMI cable and has a remote control as input hardware.(Like a video player) I need these to be done:
When the user works with it, it should not be clear that the OS is android.
User could not access to the OS system options like "Action bar" or "Setting menu" or etc.
My app be the default app of the system and it runs at start up before any other app even the launcher.
so,
How can I change the android boot logo ?
How can I set my app to be the default application? May I need to set it as launcher?
how can I disable all other android UI tools like launcher and action bar permanently? (even my application close they should not be shown)
May I need a rooted android ? and witch version has these possibilities ?
I've found my answers and share it to others.
How can I change the android boot logo ?
In some devices there is a file in system/media/bootanimation.zip
can be edited and replaced.(When creating zip file should choose
Store in compresstion type.)
In some devices there is a file in system/etc/bootvideo thats in
MP4 file format simply can be replaced.
How can I set my app to be the default application? May I need to set
it as launcher?
Yes, simply add android.intent.category.LAUNCHER to first activity category in the manifest like this:
<activity android:screenOrientation="landscape" android:name=".ActivityStarter">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How can I disable all other android UI tools like launcher and action bar permanently? (even my application close they should not be shown)
Uninstall all other launcher on the device. also for notification bar you can remove Android UI in system apps. Note that be sure your app is running correctly and does not crash, if not you will lose access to the device.(I installed ES Explore on the device and run it with a hidden button in my app to access my android system tools.)
May I need a rooted android ? and witch version has these possibilities ?
Yes. In this case I used Android 4.4.2 but think other versions would be so.
Android 5.0 supports pinning an app. There's also an app called AppLock that may be relevant.

Blocking a pull-down menu in Android

We have an industrial app running on stock Samsung Android devices. Because it's an industrial app we are trying to have it "take over" the device. We've got this pretty well working by setting in the manifest
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
and by intercepting the Android "back" key via onBackPressed and doing nothing.
Our one remaining conundrum is that Samsung's UI layer, 'Touch Wiz', has a pull-down menu that the user can pull down over the top of our app and access other features from. We're trying to disable that.
Is there anything we can intercept that the way we did the the back button to block that? Any other way to block it?
(if someone suggests "rooting" the device, what could I do as root that would help here?)
Thanks in advance!!
Which stock samsung device are you working with?
and by pull down menu are you speaking of the Notification Bar?
If so this is not a UI feature that is specific to TouchWiz, they may have modified what all can be accessed from the expanded notification bar. But this element exists in stock android as well.
If this is what you are referring to you can set a full_screen flag on your activity or application elements in your manifest. This will hide the notification bar while inside your application.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
If it does not work with fullscreen mode home app:
A stock Android has no way to do real kiosk mode and I guess it's not a goal of Android to allow this since you could do evil things with that like build apps that force you to pay money before you can leave them again.
Root will not help here too since that's about the underlying Linux which allows you to access internal files etc. That does not unlock some magically hidden APIs.
What you would need to do is build your own firmware for the device (there might exist something for the device - look in http://forum.xda-developers.com/). In that firmware you are free to change those internals that allow users to escape your app.

Categories

Resources