Flutter: Wake up phone screen for alarm - android

I'm implementing an alarm application for Android with Flutter. With the android_alarm_manager package, I'm able to create and receive alarms. Furthermore, the package bringtoforeground is useful to bring the application to foreground when using another app. However, I haven't found a way to wake up the phone screen, yet. Does anybody knows how to do that? Also, It should be possible to have the application open without entering a password or something comparable.
Thank you in advance!

I've found an answer to my question. Additionally to the two packages said, there is a modification to be made in the AndroidManifest.xml file. Two more properties are needed in the activity tag as follows:
<activity
android:showWhenLocked="true"
android:turnScreenOn="true">

Related

do i have to use any foreground service type in manifest if it has no need?

I am working on scheduling app in which i am using foreground service , in below code i am using dataSync but there is no need of it on my project , i saw many developers are using at least 1 foreground service type thats why i have mentioned it , my question is if i removed it would it effect my app or it is ok
Here is my code in manifest
<service android:name=".service.CountdownService"
android:foregroundServiceType="dataSync"
/>
If your service is not using anything like camera, microphone and location then attribute foregroundServiceType has no usage.
You can check this documentation.
https://developer.android.com/guide/components/foreground-services#loc-camera

What's "AutomaticZenRule" ? What is it used for?

Background
I just noticed some functions of NotificationManager that handle a class that's called AutomaticZenRule :
https://developer.android.com/reference/android/app/NotificationManager.html#addAutomaticZenRule(android.app.AutomaticZenRule)
and others...
The problem
Looking at the docs of AutomaticZenRule, it still doesn't tell much about what it is, and what can it be used for:
Rule instance information for zen mode.
What I tried
Searching the Internet, I can see just in a Commonsware blog post, that they wonder what it is:
It is unclear what AutomaticZenRule is ...
There is practically nothing more that I've found about it. Not "zen mode" and not "AutomaticZenRule".
The questions
What is "zen mode" ?
What is "AutomaticZenRule" , and what can I do with it? How is it related to notifications?
Is there anything special on Android N, that this API was added on this version?
Is there a sample for using it?
Zen Mode is just another name for Do Not Disturb (DND) mode. Android can activate DND mode based on rules. These rules can be provided either by the system, or by a third-party app.
In the following screenshot you can see two system-provided rules, together with a "Driving" rule provided by the third-party app "Pixel Ambient Services":
AutomaticZenRule is there to integrate your own rules into the Android system. To integrate your own rules, you have to follow these rough steps:
Make sure that you have sufficient permissions to access the DND policy (android.permission.ACCESS_NOTIFICATION_POLICY). See NotificationManager.isNotificationPolicyAccessGranted() for details.
Add an activity for your rule:
<activity android:name="MyRuleConfigurationActivity">
<meta-data android:name="android.service.zen.automatic.ruleType" android:value="My Rule" />
<intent-filter>
<action android:name="android.app.action.AUTOMATIC_ZEN_RULE"/>
</intent-filter>
</activity>
Android will show your activity whenever the user wants to create or edit a rule of the specified rule type. In the latter case, Android will supply the ID of the existing rule in NotificationManager#EXTRA_AUTOMATIC_RULE_ID. To propagate changes in your activity back to android, you need to construct an AutomaticZenRuleinstance and call NotificationManager.addAutomaticZenRule / updateAutomaticZenRule.
After that, you can tell Android that the conditions for your rule are currently satisfied / not satisfied by calling NotificationManager.setAutomaticZenRuleState.
From digging in into the other documents available, i was able to understand ZenMode to some extent(although it can be my own version and not the correct one).
What my understanding is as follows -
Zen Mode is the Do not Disturb mode which now in latest updates can be enabled automatically which depends on factors such as late time of the day, etc. AutomaticZenrule can be used by applications who want their notifications to not be masked or suppressed when in do not disturb mode.
For this your application should make request to policy access by sending the user to the activity that matches the system intent action ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS.
If user has granted access to notification policy for your app, then you will be able to set a priority notification even in do not disturb mode. AutomaticZenrule thus plays a vital role to state the system that the application's notifications not be suppressed.
Although, i dont have a running sample code for it, i guess it should be on similar lines like the enabling device admin code or requesting a permission use case.
Thanks to you i got to read something new :)

Do I actually need to export SyncAdapter service?

onPerformSync(...) {
// building status bar notification here
}
<service android:name=".SyncService" android:exported="false"> ...
This works for me (4.4.2 SGN3). Notifications appear. Both requestSync() and addPeriodicSync().
Do anybody has some thoughts about?
Is there need for exporting SyncAdapter service?
What am I actually wanna know is whether any other (enemy) application can start my exported service or not. If they can, I don't need to export the service hoping Android isn't so liberal.
I haven't find any clarifications in the Android dev guide/api. I'm pretty novice and I hope my question is correct and understandable enough :)
I suppose you need to export SyncService for using it from other applications. This is what documentation says:
The attribute android:exported="true" allows processes other than your app (including the system) to access the Service.
If you don't need to share your sync service to other apps, probably you can leave it not exported. But you need to test it on old versions of android, it's logic might has changed.

Service cannot be resolved to a type

This is driving me nuts because the answer is probably staring me in the face. I'm trying to learn to make a simple service in Android using the example in http://marakana.com/forums/android/examples/60.html
But where I try to start my service
startService(new Intent(this, MyService.class));
I get "MyService cannot be resolved to a type" at build-time.
The example has this line in the Manifest just after the close of activity and before the close of application . . .
<service android:enabled="true" android:name=".MyService" />
... but I've also tried it without the "." and with a fully qualified package name, i.e., test.bg.MyService, with no improvement.
Any idea why it can't resolve it?
If you are getting "MyService cannot be resolved to a type" during the compile, or as an error from Eclipse, then there is no such class in your project.
It has nothing to do with your manifest -- problems stemming from that will not show up until runtime with the current crop of developer tools.
I'd suggest you read the documentation on Intents and Intent Filters especially the parts about Explicit and Implicit Intents.
What you are trying to do is use an Explicit Intent to start a Service using a class name which doesn't exist in the project that is attempting to start it (as CommonsWare points out).
As for your belief that...
a service is built as a separate project
...that may be possible but very often that isn't the case and even your link in your comment to CommonsWare actually demonstrates the use of a Local Service and to quote from the opening paragraph of that section...
One of the most common uses of a Service is as a secondary component running alongside other parts of an application, in the same process as the rest of the components. All components of an .apk run in the same process unless explicitly stated otherwise, so this is a typical situation.
So basically that's saying that a typical situation is that your Service will be a component of an application containing other components which will make use of that Service.
Sure, you can use a Service in another application but you need to register it in your manifest with an <intent-filter> entry and an action such as test.bg.ACTION_DO_SOMETHING and then have an external application start it using an Implicit Intent.
Using the example code you linked in your question isn't going to work.

How to send Intent to: <service android:name="com.some.example.SomeService" android:exported="true" />

Hello and thanks very much in advance for any help.
I'm trying to figure out how to send an Intent to an exported service that resides in another application. The service has no intent-filters or other attributes. Just a name and exported="true".
I know how to do this when the service specifies a unique action. But, in this case, I have nothing but the service name. I know it sounds a bit strange. Why would I want to do this. But, I'm trying to launch the service before launching the main app so that I can observe behavior. I've tried everything I can think of and googled for several days now to now avail.
Thanks very much again for the help.

Categories

Resources