How can I interact with the Lockscreen layout to display text into it, like this app:
Asked Answered
T

6

8

I just discovered this application : https://market.android.com/details?id=de.j4velin.lockscreenCalendar

It seem that is now possible to write some text inside the lockscreen in the place where the alarm is usually written.

I would like to display custom text on this place, but have totally no idea on how to achieve that.

This guy succeed to write calendar events at this place.

Thank a lot for any clue//snippet that would help me.

enter image description here

Taxable answered 27/9, 2011 at 13:19 Comment(0)
S
9

This is astonishingly easy to achieve and astonishingly badly documented. All you need to do is set the alarm string in the system settings, as follows:

    String message = "This is a test";
    Settings.System.putString(context.getContentResolver(),
            Settings.System.NEXT_ALARM_FORMATTED, message);
Sympathy answered 27/9, 2011 at 14:23 Comment(1)
Ok, so I can only customize the text, but not the font size, etc... Thank a lot for this great answer, short and efficient!Taxable
F
1

It is not the exact thing you asked for,but the code for custom lockscreen can be found here.It might help you.

http://code.google.com/p/contactowner/

Finical answered 27/9, 2011 at 13:37 Comment(0)
K
1

I've never come accross any legit way within the public android APIs to affect the lock screen. Without playing with that app at all I wouldn't know for sure, but my guess is he created that activity that allows him to show whatever text he wants. Then uses a receiver to listen for SCREEN_OFF, or SCREEN_ON events and starts his "lock" activity at that time.

It is worth noting: If you choose to do something like this to achieve the affect you're after, it is not going to behave the exact same as the lock screen. The differences may be fairly slight, and could end up being fine for your purposes but be aware that they are there. Also assuming you go this route it wouldn't work if the user has a "pattern" lock as the KeyguardManager is unable to disable that screen programmatically

Kane answered 27/9, 2011 at 13:46 Comment(0)
C
1

you also need to add

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

in androidmanifest.xml

Carioca answered 28/8, 2013 at 11:10 Comment(1)
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>Carioca
H
0

The voted answer will work only if no one else is using the same to display their message. If two receivers are registered for SCREEN_ON/OFF intent action, the latest receiver's message will be displayed.

Hocuspocus answered 29/8, 2013 at 7:19 Comment(0)
O
0

With marc1s' solution there are 2 problems, 1. it doesn't look good & you can't change its look&fill e.g. text font or color etc 2. any other application can replace it

So its better if you show a view using window manager from a service. So you can show whatever view you want to show.

e.g. my code below in onStartCommand of my Service

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);
Orly answered 21/5, 2014 at 10:32 Comment(2)
I am trying to use this code in my event receiver class (BroadcastReceiver extends BroadcastReceiver) Whsat should I be using for mInflater pls?Gilly
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); And in onReceive () method you get second parameter of type context, assign it to mContextOrly

© 2022 - 2024 — McMap. All rights reserved.