This is a contentious issue:
There are apps that do this. See How to customize Android's LockScreen? e.g. WidgetLocker - so it is not entirely impossible.
However, Google does not recommend playing around with Android Lock Screens. Google has removed functionality for interacting with their OS lock screens (particularly as 2.2). More info on that here.
But some useful effects can be managed. There are tricks involved.
One trick is to replace the Android lock screen with a custom lock screen - essentially a Home Screen app that implements its own locking. I think that's how WidgetLocker works, but I'm not sure. There is a Home Screen demo app shipping with the Android SDK.
Another trick is to use the ACTION_SCREEN_ON
and ACTION_SCREEN_OFF
Intent actions, coupled with WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
permission on your app. You can use these to change what is shown BEHIND or instead of the lock screen - which is very close to what the question asks (they need to view some info when the lock screen is in place).
I have an app that displays information to the user when the lock screen is shown, using the above techniques. Strictly speaking, it is not a custom Android lock screen, however, it creates the effect of customising the information shown when the phone is locked.
It shows info behind the actual stock lock screen. But you can also replace the screen that normally shows when the phone is locked.
Below is a (minimal) demo app that shows how to display information when the phone is locked. I forget where I got most of the code from, but its a mess of some demo ideas. I present it just to show what can be done - I am by no means saying this is anything like "good" production code.
When you run the app, and lock the phone, the app carries on playing the video. This screen replaces the lock screen.
It will take some work to turn this code into production code, but it may help readers.
YouTubeActivity.java:
The important part is the last 2 lines that enable this activity to be visible when the phone is locked.
package com.youtube.demo;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.VideoView;
public class YouTubeActivity extends Activity
{
String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView) findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.requestFocus();
myVideoView.start();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
}
main.xml:
Nothing special here - just places a VideoView
on the screen...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
AndroidManifest.xml:
Absolutely stock manifest file - nothing interesting here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.youtube.demo" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".YouTubeActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So there are 3 ways I can think of to accomplish what the poster is looking for, or workarounds that might be useful to him:
- Do what WidgetLocker does - I don't know how exactly, and the developer is not telling.
- Change the background behind the stock lock screen.
- Overlay an activity instead of the stock lock screen (demo code provided).