Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 30346

Activity is very slow to show when screen is locked and app crash when call requestDismissKeyguard()

$
0
0

I need for my call video app a screen to show even when screen is locked. I used this very good tutorial to achieve this and it's working, screen wake when user receives a call.

But my problem is that this screen is very slow, it takes 4-5 seconds to turn screen on, it takes 5 seconds to respond when I press a button...

Also I want the Keyguard to be dismissed when I press imageView button(bring up the UI so the user can enter their credentials: PIN, password, pattern...) so I used requestDismissKeyguard but the app crashes when I call it.

I read that in my case it's better to use a service instead of activity but I don't know how to convert My activity into a service. I'm not very familiar with android development so I don't know where the problem came from.

ReactMethod in ActivityStarterModule.java

@ReactMethodvoid showActivity(String text) {Intent myIntent = new Intent((Application)reactContext.getApplicationContext(), BackgroundCallActivity.class);        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        Bundle b = new Bundle();        b.putString("text", text);        myIntent.putExtras(b);        ((Application)reactContext.getApplicationContext()).startActivity(myIntent);    }

My activity in AndroidManifest

...<uses-permission android:name="android.permission.WAKE_LOCK" /><uses-permission android:name="android.permission.DISABLE_KEYGUARD"/><activity        android:name="BackgroundCallActivity"        android:showOnLockScreen="true"        android:screenOrientation="sensorPortrait"/>...

Here's my activity code

package com.my_project;import android.app.Activity;import android.os.Bundle;import androidx.annotation.CallSuper;import androidx.annotation.Nullable;import android.view.View;import android.view.WindowManager;import android.os.Build;import android.app.KeyguardManager;import android.content.Context;import android.widget.TextView;import android.view.MotionEvent;import android.view.View;import android.widget.ImageView;public class BackgroundCallActivity extends Activity {    TextView textView;    @Override    @CallSuper    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.background_call_activity);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1){            setShowWhenLocked(true);            setTurnScreenOn(true);        } else {            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);        }        Bundle b = getIntent().getExtras();        String value = b.getString("text");        textView = (TextView)findViewById(R.id.textView);        textView.setText(value);        ImageView imageView = (ImageView)findViewById(R.id.answer);        final TextView mCustomToast = (TextView)findViewById(R.id.textView2);                mCustomToast.setVisibility(View.INVISIBLE);                imageView.setOnTouchListener(new View.OnTouchListener() {                    @Override                    public boolean onTouch(View v, MotionEvent event) {                    KeyguardManager keyguardManager = (KeyguardManager)                    getSystemService(Context.KEYGUARD_SERVICE);                    if( keyguardManager.isKeyguardLocked()) {                        keyguardManager.requestDismissKeyguard(BackgroundCallActivity.this, null);                      } else {                        ActivityStarterModule.triggerAlert("answer");                        finish();                    }                        return false;                    }                });        ImageView imageView1 = (ImageView)findViewById(R.id.hangup);                imageView1.setOnTouchListener(new View.OnTouchListener() {                    @Override                    public boolean onTouch(View v, MotionEvent event) {                        ActivityStarterModule.triggerAlert("reject");                        finish();                        return false;                    }                });    }}

Have you any suggestion to remove this delay and to make requestDismissKeyguard work it will be great.


Viewing all articles
Browse latest Browse all 30346

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>