Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Fail to build running this app in flutter. #14

Closed
jja08111 opened this issue Oct 16, 2020 · 6 comments
Closed

Fail to build running this app in flutter. #14

jja08111 opened this issue Oct 16, 2020 · 6 comments

Comments

@jja08111
Copy link
Contributor

I want to make alarm app that is my first app, so I would like to refer to your application.

But build failed..
I've changed the AlarmBroadcastReceiver.java.

The error code is here.

C:\flutter\.pub-cache\hosted\pub.dartlang.org\android_alarm_manager-0.4.5+15\android\src\main\java\io\flutter\plugins\androidalarmmanager\AlarmBroadcastReceiver.java:20: warning: [deprecation] SCREEN_DIM_WAKE_LOCK in PowerManager has been deprecated
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
                                                    ^
error: warnings found and -Werror specified
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':android_alarm_manager:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Exception: Gradle task assembleDebug failed with exit code 1

How to debug this error?

@jja08111
Copy link
Contributor Author

jja08111 commented Oct 16, 2020

I find a solution by searching the PowerManger.java file.

Solution is change PowerManager.SCREEN_DIM_WAKE_LOCK to 0x00000006 in AlarmBroadcastReceiver.java.
Because SCREEN_DIM_WAKE_LOCK is @Deprecated.

@geisterfurz007
Copy link
Owner

Hey there! Thanks for letting me know! I will see if I can make use of the API suggested in the deprecation notice and comment on the original issue the file was taken from 👍

@jja08111 jja08111 changed the title Fail to build when running this app in flutter. Fail to build running this app in flutter. Oct 22, 2020
@jja08111
Copy link
Contributor Author

Use WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON instead of 0x00000006

@geisterfurz007
Copy link
Owner

Good to know, thanks!

@KodPlanet
Copy link

Use WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON instead of 0x00000006

Hi Minseong,
I am also trying to build an alarm app and trying to implement AlarmManager for days. I saw your questions on stackoverflow and finally find this repo ( thanks also to geisterfurz :) for this contribution ).

android_alarm_manager package is updated to 2.0.0 and I can not modify AlarmBroadcastReceiver.java as mentioned above.

I downloaded your BedTime app and looks like you somehow managed to run app from background service.
Which version of android_alarm_manager are you using?

Moreover,
Is it possible reach you to discuss latest solutions you are using, and about your experience ?

@jja08111
Copy link
Contributor Author

Hi @KodPlanet

I'm using the ^2.0.0 version in my app.
I don't know why you can not modify the AlarmBroadcastReceiver.java.
In my case, open the project and find the android_alarm_manager-2.0.0 in the External Libraries/Flutter Plugins. And find AlarmBroadcastReceiver.java, copy-paste!

Here is the code that I used.

AlarmBroadcastReceiver.java
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
     
package io.flutter.plugins.androidalarmmanager;
     
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.content.pm.PackageManager;
import android.view.WindowManager;
     
public class AlarmBroadcastReceiver extends BroadcastReceiver {
  private static PowerManager.WakeLock wakeLock;
     
  @Override
  public void onReceive(Context context, Intent intent) {
    PowerManager powerManager = (PowerManager)
            context.getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            PowerManager.ACQUIRE_CAUSES_WAKEUP |
            PowerManager.ON_AFTER_RELEASE, "My wakelock");
     
    Intent startIntent = context
            .getPackageManager()
            .getLaunchIntentForPackage(context.getPackageName());
     
    startIntent.setFlags(
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
                    Intent.FLAG_ACTIVITY_NEW_TASK |
                    Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
    );
     
    wakeLock.acquire();
    context.startActivity(startIntent);
    AlarmService.enqueueAlarmProcessing(context, intent);
  wakeLock.release();
  }
}

There is a need for permissions (#18) to fire the alarm from the background.

And I'm using geisterfurz007's alarm app system.
To describe it a bit,

  1. alarm fired and callback function called
  2. write the flag file(in my case, using shared_preference)
  3. run polling worker that finds flag file
    • if exist flag file change the state to alarm on, else don't change the state.

I had a hard time building an alarm system with Flutter. I hope this helps you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants