I'm trying to change notification icons and in emulator it is OK :
This is what I want (tested on emulator API level 22 (android 5.1.1)) BUT, when i'm running this APP in my real phone (Xiaomi Redmi 3 prime with MIUI 8.0.1) also android 5.1.1 - the notifications looks very very very differant. This notification icons does not showing (just a default application icon).
But... why? What can i do now?
Here is my code:
NotificationCompat.Builder b = new NotificationCompat.Builder(compat);
b.setSmallIcon((state == STATE_STOPPED) ? R.drawable.ic_stat_remove : R.drawable.check);
b.setContentText(content);
b.setContentTitle(BASE_NOTIFICATION_TITLE);
b.setOngoing(true);
b.setAutoCancel(true);
b.setColor((state == STATE_STOPPED) ? Color.RED : Color.rgb(22, 219, 28));
NotificationManager m = (NotificationManager) compat.getSystemService(NOTIFICATION_SERVICE);
m.notify(0, b.build());
Just a very simple notification... can someone tell me, what's wrong? Or just MIUI turns off all notification icons and set it to default app launch icons?
Thanks!
EDIT: notification in my phone looks like this...
I had the same problem, but Juan Pablo (in comment Java Android - Redmi 3 (MIUI) - Notification icons cannot be changed?) gave me a clue and now I have a solution:
//notification is an object of class android.app.Notification
try {
Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
Object miuiNotification = miuiNotificationClass.newInstance();
Field field = miuiNotification.getClass().getDeclaredField("customizedIcon");
field.setAccessible(true);
field.set(miuiNotification, true);
field = notification.getClass().getField("extraNotification");
field.setAccessible(true);
field.set(notification, miuiNotification);
} catch (Exception e) {
}
Now it works as it is expected.
This is behavior of MIUI system. You can not display different icons in notification, by default it takes app icon as notification icon.
Related
I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}
I would like my Android app to launch another app on a dedicated area of the screen, i.e. set the screen bounds within which the other app will be displayed. Below is a screenshot with an example of how this could look, where I have launched Google Maps overlaid on my app:
This is achieved by the following code:
final String packageName = "advanced.scientific.calculator.calc991.plus";
new Handler().postDelayed(() -> {
final int[] location = new int[2];
containerLayout.getLocationOnScreen(location);
final Rect appBounds = new Rect(location[0], location[1],
location[0] + containerLayout.getWidth(),
location[1] + containerLayout.getHeight());
final ActivityOptions launchOpts = ActivityOptions.makeBasic();
launchOpts.setLaunchBounds(appBounds);
final Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent, launchOpts.toBundle());
}, 5000);
The above result would be satisfactory, however this is run on a Samsung Galaxy S10 device running Android 10. Now, I need to be able to achieve a similar result using Android 9. I have looked into the picture-in-picture and freeform modes, but I have not managed to use the former for this purpose, and the latter unfortunately only seems to be available from Android 10 and up. I am open to any solution for this, including creating a launcher app, etc. I am also looking to maximize compatibility with third-party apps.
What are the possible ways to achieve this on Android 9?
**What I have done so far : **
I have implement it for Android SDK 29
RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
startActivityForResult(intent, REQUEST_ID1);
**What I am looking for ? : **
I want to implement Call Screening Service for devices < SDK 29.
Kindly help me if anyone have done it before.
Unfortunately, you can't.
It is impossible to access the RoleManager class on Android versions < 29 because this class was introduced on Android 29. Therefore, you can only use this class on devices running Android 29 and up.
For Android <= 28, to bind the CallScreeningService the app must be set as the default dialer app. On runtime, a dialog can be displayed asking the user to set your app as the default dialer app as follows:
if (getSystemService(TelecomManager.class).getDefaultDialerPackage() != getPackageName()) {
Intent changedDialer= new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
changedDialer.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
startActivity(ChangeDialer);
}
I need a badge counter on my application launcher icon.
I know the solution to get Badge counter inside the app, using TextView, But I need a solution to get the badge counter external to the app on the launcher icon.
In iOS we get the badge number count by
UIApplication.sharedApplication().applicationIconBadgeNumber
I am wondering why Android has not included anything like this with their SDK which every developer need.
Try 1 : Working only on sony mobiiles :
Intent badgeIntent = new Intent();
badgeIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", this.getPackageName());
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", this.getClass().getName());
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", ShwMsgBulVar);
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "10");
context.sendBroadcast(badgeIntent);
Try 2 :
I tried the library :
https://github.com/leolin310148/ShortcutBadger
It works only for few manufacturers and not common for all android mobiles.
ShortCutBadger is not working on OPPO, VIVO, Xiomi, Reliance LYF default launchers.
After couple of research, I came to know that, badge number depends on launcher manufacturer and listed as below :
ShortCutBadger Suported :
Samsung : "com.sec.android.app.launcher"
Sony : "com.sonyericsson.home"
HTC : "com.htc.launcher"
Asus : "com.asus.launcher"
ShortCutBadger not Suported :
Oppo :"com.oppo.launcher"
Xiomi : "com.miui.home"
Vivo : "com.bbk.launcher2"
Lyf : "com.android.launcher3"
Go Launcher : "com.gau.go.launcherex"
So is there any other general method which can work on all manufacturer mobiles?
Read so many posts and did lot of search but Many tell there is no such generic solution which is applicable for all launchers.
But I feel there is a solution because whatsapp and facebook app display the badge number in all the above mentioned launcher.
There is no such function in Android as badge numbers are not a part of the platform.
A few libraries exist that try to achieve this such as https://github.com/leolin310148/ShortcutBadger but you should understand that it does not work for every manufacturer's device. Also as far as I understand the badges only appear over the icon when it is on a home screen and not in the app drawer.
I know there are several Qs here that ask if its possible to add badges to an android app and they all end up with a NO answer...
But somehow the latest Facebook beta version for Android seems to do something which at least look like a badge even if it is not technically exactly that.
In that post one of the commenters says that it is somehow related to TouchWiz.
And also here they mention it as a feature of the "S3 TouchWiz Jelly Bean Addon".
I still would appreciate information on how does this can be done and if there is some API for this that I can use in my own app (when running in an appropriate environment - i.e. the same device where FB demonstrates this behavior) ?
Hi you can use this lib simply.
Support : Sony,Samsung,LG,HTC,Xiaomi,ASUS,ADW,APEX,NOVA,Huawei,ZUK,OPPO
ShortcutBadger
Add :
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
Remove :
ShortcutBadger.applyCount(context, 0);
I have figured out how this is done for Sony devices.
I've blogged about it here. I've also posted a seperate SO question about this here.
Sony devices use a class named BadgeReciever.
Declare the com.sonyericsson.home.permission.BROADCAST_BADGE permission in your manifest file:
Broadcast an Intent to the BadgeReceiver:
Intent intent = new Intent();
intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");
sendBroadcast(intent);
Done. Once this Intent is broadcast the launcher should show a badge on your application icon.
To remove the badge again, simply send a new broadcast, this time with SHOW_MESSAGE set to false:
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
I've excluded details on how I found this to keep the answer short, but it's all available in the blog. Might be an interesting read for someone.
There is not a standard way to achieve this; Many makers such as Sony or Samsung have implemented it in their own Android customization.
For example in Samsung, you have to broadcast an intent with BADGE_COUNT_UPDATE action, let MainActivity be your main activity class and count be the number you want to display in your app icon, note that 0 will hide the badge:
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", MainActivity.class.getName());
context.sendBroadcast(intent);
Sony devices uses "com.sonyericsson.home.action.UPDATE_BADGE" action with their custom extras as #Marcus Answered, so you have to add "com.sonyericsson.home.permission.BROADCAST_BADGE" permission to your app manifest and:
Intent intent = new Intent("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", MainActivity.class.getName());
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(count));
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(intent);
Note: it's desirable to query your app's data (context.getPackageName(), MainActivity.class.getName()) rather than hardcode it just in case you do some refactoring in the future.
But somehow the latest Facebook beta version for android does just that...
Not according to the forum thread that contains the screenshot that you linked to. Quoting vakama94:
Well, that's actually TouchWiz and not just the app. I have a Galaxy S II running JellyBean 4.1.2 and it makes the same thing but with some other applications
Whether Samsung has a public API to allow apps to publish numbers to be used as badges, I cannot say. This could be something that they did privately with a few firms.
You are welcome to provide evidence of seeing these badges on a stock Android home screen, such as one of the Nexus series devices.
I answer to this assuming that some flutter dev can search this...
In Flutter, you can achieve this by using
Flutter app badger library.
It is as simple as
FlutterAppBadger.updateBadgeCount(1); // show
FlutterAppBadger.removeBadge(); // hide