How can I create a notification channel for Android API level < 26 (before Android Oreo)? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am currently working with an Android service:
https://developer.android.com/guide/components/services
I am creating a service that has to be a foreground service.
But looking at the documentation, a foreground service requires a notification channel.
But a notification channel is only on api 26 or higher. How can i create a notification channel for < 26?
I am stuck with this code
if (VERSION.SDK_INT >= 26) {
getSystemService(NotificationManager.class).createNotificationChannel(new NotificationChannel("ServiceWorker", "ServiceWorker", NotificationManager.IMPORTANCE_DEFAULT));
}

There is no way to create notification channels for API level < 26, because notification channels were added in API 26.
Fortunately, that means that your code is already correct. You're already doing the right thing by only creating the channel on API level >= 26.
When you create the notification with NotificationCompat.Builder, you can simply call setChannelId with your string unconditionally, and it will ignore it for you on Android versions where channels are not supported ("No-op on versions prior to Build.VERSION_CODES.O").
You can then pass the returned notification to startForeground, as described in the guide you linked.

Related

Android lollipop not displaying the keyboard input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am totally new to android. I have created one simple sign up and login page using visual studio. this app is running on all the android version except android lollipop. In android lollipop, app is opening the login page and we navigated to signup page. Here some of the xamarin.entry fields will be there to get input from user. User able to click the entry box and keyboard also appearing, but entered letters not displaying anything in the entry box. But input is reading from the keyboard. When we navigating to login page, that time entered values are displaying in the entry box.
We are using xamarin.forms and Entry box to get the input.
Please guide me to resolve this strange issue?
You can send async request in akka like this
final Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
final Future<Object> future = Patterns.ask(actor, msg, timeout);
final String result = (String) Await.result(future, timeout.duration());
And inside actor in onReceive method you can return output like this
getSender().tell(result, getSender());
This articles contains nice described examples http://doc.akka.io/docs/akka/snapshot/java/futures.html#Use_with_Actors
http://alvinalexander.com/scala/scala-akka-actors-ask-examples-future-await-timeout-result
End example from Akka vendor:
https://github.com/write2munish/Akka-Essentials/blob/master/ActorMessagingExample/src/main/java/org/akka/essentials/java/future/example/ProcessOrderActor.java

File Security in Android and iOS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to make a file device dependent, such that it works only on the device it's directly downloaded unto but becomes corrupt and rendered useless if same file is copied to another phone or device. Is this possible?
For files like (photos, videos, documents .. etc) it is not possible,,
But it can be applied for applications,, the app can get devices IMEI number, which is a unique and unchangeable number for each device then store in a strings, each time the app is run, it matches the stored IMEI withe devices IMEI..
This method can be used to get devices IMEI in Android
public String getIMEI(Context context){
TelephonyManager mngr = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
String imei = mngr.getDeviceId();
return imei;
}

How do i make a validation about the missing flash camera on android? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Im making a flash aplication for a school proyect but my phone doesn't have an flashlight so.. i have a idea to make the validation if my phone dont have a flashlight so light up the screen.
can someone help me ? :D
I think this post may halp you to implement your idea:
If you are planing to use it inside any function like onUpdate or
onEnabled etc of Appwidgetprovider, then all those functions have
context as a input parameter. You can use that context for using
PackageManager as you are doing here.
Also in your question you mention flashlight. So just check if you
need FEATURE_CAMERA_FLASH or FEATURE_CAMERA.
Context context = this;
PackageManager packageManager = context.getPackageManager();
// if device support flash?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH))
{
//yes
Log.i("camera", "This device has flash supported!");
}else{
//no
Log.i("camera", "This device has no flash support!");
}
FROM: Check if a device has flashlight
Check also:
how to check if device has flash light led android
Android: how to check the flash light is available on device?
[VUFORIA FORUM] check if flash light is present in device
Hope it help

How to: When application updates, automatically clear previous application' s data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have code which is running with preference data. I have very simple boolean control store in preference. When I update my application, I'm seeing that it doesn't clear data and is running with previous data. I have to fix that problem tonight, what is your suggestion about this? Thank you
Make your application read a "version" value from the preferences. If that version is not there, or is not the same as the current version, then you can clear/update/migrate the preferences to the new version.
I'm writing from iPad, so I can't write more code. I did something that U want to do a longtime ago )))To clear all data use this. And then in loading activity use something like this:
if (BuildConfig.VERSION_CODE < #version code from preferences#) {
// clear data
// save new version code to preferences
}
Always when user updates his app, this code will clear data if the application's preferences have no >= version code.

How to make custom digital clock in android [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm creating an app, which can show the times of different cities. I have an api which takes coordinates and gives me something like - America/Chicago. But I want to show this on a Digital Clock. Can someone please tell me how to change the timezone of a DigitalClock, or make a custom one. I have no clue! Thanks for the help!
Android: DigitalClock remove seconds
customized digital clock in android
I assume you can then work out how much time to add/subtract from the system's time to show the destination's time.
Do you mean by like a digital clock as in a widget? You're going to need to give more information about it.
You can try doing a textview in an activity and set it to change every minute or hour by getting the time from this class
from Android API.

Categories

Resources