Notifications won't push to real device - android

I was following along to TheNewBoston Android App Development for Beginners - 63 - Styles video for pushing notifications.
The app works perfectly in Android Studio's emulator, but when I run the app on my phone, the notifications won't show up.
Is there a reason notifications work on the emulator, but not an actual device?

in some devices like Huawei you need to make your app as protected app to use notification feature. you can use below code to detect Device Model and make decision to go to the protected app setting.
String PhoneModel = android.os.Build.MANUFACTURER;
if ("huawei".equalsIgnoreCase(PhoneModel)) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
}

Shortly after I posted the question I figured out what the problem was. I updated my phone to Oreo recently and was trying to use the old way (the way thenewboston did it inside his videos). Apparently for android Oreo you have to code notifications with channels, the old way for notifications is not compatible with Oreo.

Related

Android Wear is not opening dial pad via intent

I am working on an android wear project, I am facing an issue while opening the dialing activity via intent. The problem is that Intent is opening the call history instead of the dial pad.
Code snippet
val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:0526722293")
context.startActivity(callIntent)
I have checked different stack-overflow post but still facing the same issue.
Can we make calls to any number in Android Wear 2.0?
How to make a phone call using intent in Android wear?
Is there anything that, I have to do more for android wear
If you are testing the app one an emulator, try the same on a physical watch. If the issue still persists, you might want to check the following:
Do the app have required permissions
Is this specific to a device/OS version
Ref:
https://developer.android.com/guide/topics/connectivity/telecom/selfManaged#constraints
https://developer.android.com/wear/releases?hl=ko

Why the service doesn't start

I'm starting to develop for android, and I'm having an issue about services. I did a lot of research about this, but couldn't find a solution.
I'm doing an app that collects RFID tags information. For that, I'm using a third-party middleware that handles the bluetooth connection to the RFID reader and other events (like connecting, reading, errors etc). So, my app creates a broadcast receiver that handles all the message and data intents sent by the middleware. For this part, everything's fine.
The problem is that I'm trying to start middleware service using the code below (provided by the middleware documentation), but it doesn't work.
Intent intent = new Intent("com.supplier.middleware.runner");
intent.setPackage("com.supplier.middleware");
startService(intent);
I'm currently using an Asus Zenfone MAX M1 (ASUS_X00HD) with Android 8.1.0. The documentation also describes a way to stop the service (which I must use when I close the app), and the stop service intent works. So, if I start the middleware manually and try to close programatically, it works fine.
After some days trying - unsuccessfully - to solve this, I tested my app with a Motorola Moto Maxx (which is Android 6, I think) and with a Samsung J1 (which is Android 5.1.1) and both smartphones worked fine: when I call the startService, a notification item appears; when I call stopService, the notification item goes away.
I also tried to use "startForegroundService" because of the Android 8, but no success either.
Is there a way to "monitor" the startService calls, so maybe I could track any error? Am I doing something wrong - or rather, am I not doing something that is important?
In Android 8.0 background service limitation.
https://developer.android.com/about/versions/oreo/background.html
You can use JobIntentService instead of intent service. It can work.

When app clear from recent apps list, background service stopped in android nougat and oreo

When I clear my app from recent apps list, my app background service killed. I tried with android nougat and oreo. But it's working in Android 6.0. After searched about the issue. Lot of people navigated the answer to Background Execution Limits.
Any one have solution for this issue?
Android Nougat should not have those issues ideally. I've spend weeks on NotificationListenerService which runs perfectly fine in background in Nougat.
It also works great in Samsung S9 (Android Oreo) but I have some issues in Google devices and emulators.
I've raised a similar issue few weeks back.
Just to make sure, enable background services for your app through console.
Also, specify which service you are using?
try this
#TargetApi(Build.VERSION_CODES.O)
private void moveToStartedState() {
Intent intent = new MyIntentBuilder(this)
.setCommand(Command.START).build();
if (isPreAndroidO()) {
Log.d(TAG, "Running on Android N or lower");
startService(intent);
} else {
Log.d(TAG, "Running on Android O");
startForegroundService(intent);
}
}
Example
https://proandroiddev.com/deep-dive-into-android-services-4830b8c9a09
Simple answer:
Use foreground services instead of background services.
Why?
Because of changes in how latest Android SDKs treat background services and Doze mode.
Good luck :)

Expo Push Notifications not popping in Android phones (Floating Notifications)

EDIT: I discovered these are known as FLOATING NOTIFICATIONS. Anyone knows how to enable them by default from the app (through a permission etc) on an Android device?
I am currently testing push notifications on an Android device and noticed that although I get the push notifications, they are not popped up on the screen but stay in the background (I need to drag down the top status bar as per picture). I see this as rather useless as the user is not really notified if he's using the phone:
On iPhone, the pop up displays correctly with no issues whatsoever.
I've finally made it work using Expo.Notifications.createChannelAsync using priority: "max" and when sending a message add channelId: "mychannel".
To show a so called floating notification, app must have the permission SYSTEM_ALERT_WINDOW.
A permission is something given by the user. So, there is no way to enable them by default from the app. What you can do is to take user to the settings page.
Check if you already have the permission
The recommended way to do this is using Settings#canDrawOverlays(Context).This permission is introduced only in API level 23. Therefore as per doc, it there is no need to check the permission in older devices.
However it is seen that this won't work well as expected in some pre-Marshmallow devices like Xiaomi Mi 2. So is better to do it as shown in this post.
Take user to the settings page if there is no permission
If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action Settings.ACTION_MANAGE_OVERLAY_PERMISSION.
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);

How to get know when application's background services got block by other super-access application in android

My application performs data synchronization in background service which is critical task for application in order to work properly. now, application works fine & expected in some of devices having pure Android or near to pure Android ROM. e.g. Google Nexus, Android One & Motorola devices. but, some devices like Redmi having MIUI has inbuilt options for blocking application's background processes. which causes my application working not properly. So, I want to know "is there any way to find out my background processes are blocked? so that I can notify user to unblock it."
here's a somewhat related question
here's some screenshot related to this.
Any suggestions or help are welcome.
Thanks in advance
as i know, apps cannot get the info about whether or not in whitelist, but you can notify the user any more by :
Intent intent = new Intent(); intent.setAction("miui.intent.action.OP_AUTO_START"); intent.addCategory(Intent.CATEGORY_DEFAULT);

Categories

Resources