Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dos #1

Open
alipetarian opened this issue Aug 23, 2019 · 10 comments
Open

Update Dos #1

alipetarian opened this issue Aug 23, 2019 · 10 comments

Comments

@alipetarian
Copy link

Hi, Please update docs. The correct command to install library is:

npm i react-native-unlock-device
and for linking
react-native link react-native-unlock-device

@alipetarian
Copy link
Author

Also it does not work withe the following commands.
// TODO: What to do with the module?
RNUnlockDevice.unlock()
.then(() => console.log('Success'))
.catch(error => console.log('Error', error));

It works with RNUnlockDevice.unlock()

@DrSchmurge
Copy link

Also it does not work withe the following commands.
// TODO: What to do with the module?
RNUnlockDevice.unlock()
.then(() => console.log('Success'))
.catch(error => console.log('Error', error));

It works with RNUnlockDevice.unlock()

Hi alipetarian ,
Could you please share a snippet of your code? My code is not working, neiher with

RNUnlockDevice.unlock()
.then(() => console.log('Success'))
.catch(error => console.log('Error', error));

nor with

RNUnlockDevice.unlock()

@DrSchmurge
Copy link

finally made it work after changing source:

+++ node_modules/react-native-invoke-app/android/src/main/java/com/codegulp/invokeapp/RNInvokeApp.java	2020-04-24 15:23:14.000000000 +0300
@@ -52,6 +52,7 @@
             Intent activityIntent = new Intent(reactContext, activityClass);

             activityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             reactContext.startActivity(activityIntent);
         } catch(Exception e) {
             Log.e(LOG_TAG, "Class not found", e);

@alipetarian
Copy link
Author

Great to know that you got it working.

@lazynewt
Copy link

lazynewt commented May 12, 2021

Hi does this still work? i have just tested and it does not seem to currently work. I can not find any alternative either.

@lazynewt
Copy link

@DrSchmurge could you please clarify your post. You reference react-native-invoke-app not this lib ?

@DrSchmurge
Copy link

DrSchmurge commented May 12, 2021

@DrSchmurge could you please clarify your post. You reference react-native-invoke-app not this lib ?

Yes, sorry for that. wrong issue thread. I use unlock-device and invoke-app together to invoke app from background and show it on locked screen also

@DrSchmurge
Copy link

DrSchmurge commented May 12, 2021

Hi does this still work? i have just tested and it does not seem to currently work. I can not find any alternative either.

by the way, I use react-native-unlock-device in my project, and it seems to work. But it needs special permissions in AndroidManifest, check you have them there:

<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

I moved the code to NativeModule, it consists of just few lines, and works fine:

public class UnlockDevice extends ReactContextBaseJavaModule {

  private final ReactApplicationContext reactContext;
  private static final String TAG = "RNUnlockDevice";

  public UnlockDevice(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Override
  public String getName() {
    return "UnlockDevice";
  }

  @ReactMethod
  public void unlock() {
    Log.d(TAG, "manualTurnScreenOn()");
    UiThreadUtil.runOnUiThread(new Runnable() {
        public void run() {
            Activity mCurrentActivity = getCurrentActivity();
            if (mCurrentActivity == null) {
                Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
                return;
            }

            Window window = mCurrentActivity.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        }
    });
  }
}

And in JS code, I call it by unlock() only, no need of .then

NativeModules.UnlockDevice.unlock()

@lazynewt
Copy link

@DrSchmurge you are awesome. Unlock device works perfectly with the standard docs (minus the naming issue) and your suggestion of adding to the android manifest. I will look at your native module also but am somewhat new to react-native. I am now at the stage of being able to unlock but like you have run into the issue of the app not unlocking when in the background. Could you possibly advise/share your work around ? I am attempting to run react-native-background-timer and call invokeApp() which is not working out for me. I beieve this may be due to me needing to run this from within a headless function ? thanks again you have really helped me out.

@DrSchmurge
Copy link

@DrSchmurge you are awesome. Unlock device works perfectly with the standard docs (minus the naming issue) and your suggestion of adding to the android manifest. I will look at your native module also but am somewhat new to react-native. I am now at the stage of being able to unlock but like you have run into the issue of the app not unlocking when in the background. Could you possibly advise/share your work around ? I am attempting to run react-native-background-timer and call invokeApp() which is not working out for me. I beieve this may be due to me needing to run this from within a headless function ? thanks again you have really helped me out.

Hi, you are welcome. I will try to share my work, but in a while, not really much free time now(

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

No branches or pull requests

3 participants