Activity with a certain height in front of a locked screen

I want to show Activity before Lockscreen. I tried using this code in my onCreate medthod:

super.onCreate(savedInstanceState); Window window = getWindow(); window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.test); 

This works great for Activities that are displayed on the whole screen, but I want to create an Activity that is only 200 pixels. I thought I could match it with this code:

 super.onCreate(savedInstanceState); Window window = getWindow(); LayoutParams layout = new WindowManager.LayoutParams(); layout.copyFrom(window.getAttributes()); layout.height = 200; window.setAttributes(layout); window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.test); 

But then the activity is not visible in front of the lock screen. If I unlock the phone, activity is displayed directly. Any ideas why and how I can fix this?

EDIT: I think this has something to do with the floating FLAG window. If this flag is set (and I think that when resizing) the activity will not be displayed on the lock screen. But this is only a presumption. Any ideas or workaround to fix this?

+4
source share
4 answers

I had a similar requirement when developing my music player. What I am finally doing for the lock screen widget:

  • Had a transparent background for my lock screen widget.
  • Added a button “Click to lock screen” at the bottom of the layout.
  • To feel the box, a white border around the buttons is added.

You can watch it by downloading my music player "Fusion Music Player" from Google Play.

0
source

First of all, save the Keyguard instanse settings.

After that - disable the default screen lock on your phone.

It then implements Service , which is caught when the phone goes into a locked state.

When SCREEN_ON checks the action on the stack, if it exists, show it, NO - run singleTask .

This is the only way to implement Activity on Lockscreen. Because Google rejects screen locks and any manipulation of it is a hack.

You can make a widget and place it on the lock screen or below the spelling.

FYI: google it is my lock for android (source on code.google.com)

0
source

Finally, I have achieved the same. Do not go for activity, because Android will not display a lock screen for your activity for security reasons, therefore, for maintenance.

Below is my code in my service's onStartCommand

 WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); View mView = mInflater.inflate(R.layout.score, null); WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON /* | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON */, PixelFormat.RGBA_8888); mWindowManager.addView(mView, mLayoutParams); 
0
source

It’s best to create a View that fills the screen, but has a transparent background everywhere except for the part you want.

This can be done by specifying a custom theme in the res/values/styles.xml (initially shown on How to create transparent activity on Android? ):

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:backgroundDimEnabled">false</item> </style> </resources> 

Then by adding this theme to your Activity manifest manifest:

 android:theme="@style/Theme.Transparent" 

You can then create a layout ( R.layout.lockscreen ) for this action by adding this XML file. Here you specify the height in pixels:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <FrameLayout android:layout_width="match_parent" android:layout_height="200px" android:centerInParent="true" > <include layout="@layout/test" /> <!-- This points to your R.layout.test layout. --> </FrameLayout> </RelativeLayout> 

Finally, just use the first method shown above to show the Activity:

 super.onCreate(savedInstanceState); Window window = getWindow(); window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.lockscreen); 
-one
source

Source: https://habr.com/ru/post/1496261/


All Articles