I've developed and app that is a slide show of pictures which each play a sound when you tap them. It's like a picture book for ages 2-4.
The problem is, since android won't let you capture a home button press and essentially disable it, when parents give the phone to their child to play with unattended (brave parent), the child can inadvertenly exit the app and then make calls or otherwise tweak the phone.
There are two other apps that currently have a psuedo fix for this issue. The apps are Toddler Lock and ToddlePhone. I've tried contacting the developers of these apps for some guidance but they haven't been willing to disclose anything, which if fine, but does anyone here have any suggestions?
It looks like both of those other apps are acting like a home screen replacement app. When you enable the "childproof mode" on those apps the user is prompted to chose and app for the action and the choices are "Launcher, LauncherPro, etc." plus the toddler app. You then have to make the toddler app the default and voila, the phone is "locked" and can only be "unlocked" using a key combination or touching the four corners of the screen, etc. when you "unlock" the phone. your normal home screen app default restored. You don't even have to make the toddler app the default the next time you enable the "childproof mode".
I have read that these two apps have problems with Samsung phones and they can cause an an infinite crash-and-restart-loop that requires a factory reset to fix. Obviously this is not the ideal solution to the problem but it looks like the only one availiable at this point.
Does anyone have any ideas on how to implement a "childproof mode"?
I needed to have toddler lock in a new app, and did not want to use a launcher.
Here is what I did, you can see the app at https://play.google.com/store/apps/details?id=com.justforkids.animalsounds
When lock is activated, start a service, and stop it when lock is deactivated
The service checks the top running app, and if it is not my activity, the service launches my activity
There was still an issue that when the user clicks "home", it takes about 6 seconds before my activity is launched again. I assume this is a security feature in Android but not sure. To bypass this, when the service detects that another app is visible, it adds a top view (as an alert window) that covers the home screen for the few seconds it takes the app to re-launch.
For step 3, here are more details:
Create the overlay layout, for example file locked_overlay.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d0000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="#string/app_name"
android:textColor="#fff"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Locked mode is on"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</FrameLayout>
In your service to show or hide the overlay use:
private View lockedOverlay = null;
private void hideLockedOverlay() {
if (lockedOverlay != null) {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.removeView(lockedOverlay);
lockedOverlay = null;
}
}
private void showLockedOverlay() {
if (lockedOverlay != null) {
return;
}
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams viewLayoutParams = new WindowManager.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
viewLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
LayoutInflater inflater = LayoutInflater.from(this);
lockedOverlay = inflater.inflate(R.layout.locked_overlay, null);
windowManager.addView(lockedOverlay, viewLayoutParams);
}
You will need the permission
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
I think you're right regarding the home screen replacement. Toddler Lock I know doesn't override the home button, because (at least on my LG GW620) while in Toddle Lock holding the home button brings up the ALT-TAB type menu - which then tends to crash the phone.
There is a home screen replacement app available, with source code, on the android dev site:
http://developer.android.com/resources/samples/Home/index.html
EDIT: also, ADW.Launcher:
http://code.google.com/p/adw-launcher-android/
Add in to your Main Activity
#Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
And Override Key down event
#Override
public boolean onKeyDown(int iKeyCode, KeyEvent event)
{
if(iKeyCode == KeyEvent.KEYCODE_BACK || iKeyCode == KeyEvent.KEYCODE_HOME)
{
return true;
}
}
Edit:
This works in all older version of android. But will not work in ICS and jelly bean and will give you crash in app
For versions 4.0 and above you can avoid Android security restrictions and set your app as a launcher. Add this to your manifest file:
<uses-permission android:name="android.permission.GET_TASKS" />
<activity
android:launchMode="singleInstance"
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
I replaced the Default Home launcher using the following code:
Intent selector = new Intent("android.intent.action.MAIN");
selector.addCategory("android.intent.category.HOME");
selector.setComponent(new ComponentName("android","com.android.internal.app.ResolverActivity"));
startActivity(selector);
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am developing custom lockscreen app.its working fine in below 4.0 but above 4.0,when we press home button the app stops.is there any solution for this no apps will stop when pressing home button untill unlocking the screen.(like go locker app)
Another way to develop a LockScreen App is by using Views, let me explain it.
First of all you can "disable" in some devices the System lock screen by disabling the KEYGUARD:
((KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE)).newKeyguardLock("IN").disableKeyguard();
You should put this line of code in your Service.
After that you can launch an activity every time the screen goes off:
public class AutoStart extends BroadcastReceiver {
public void onReceive(Context arg0, Intent arg1) {
if(arg1.getAction().equals("android.intent.action.SCREEN_OFF")) {
Intent localIntent = new Intent(arg0, LockScreen.class);
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent.addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
arg0.startActivity(localIntent);
}
}
}
If you read the documentation for WindowManager.LayoutParams.TYPE_SYSTEM_ERROR it explains that is a type of internal system error windows, appear on top of everything they can. In multiuser systems shows only on the owning user's window.
So now you have an activity on top of everything, but a press in HOME button will exit the activity.
Here is where the Views make their appearance. You can inflate a view from a layout resource and add it to the WindowManager as a TYPE_SYSTEM_ERROR, so will be on top of everything. And since you can control when to remove this View, the best place is in onDestroy of your Activity, because pressing the HOME button will only pause your activity, and the view will still be visible.
public WindowManager winManager;
public RelativeLayout wrapperView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
this.winManager = ((WindowManager)getApplicationContext().getSystemService(WINDOW_SERVICE));
this.wrapperView = new RelativeLayout(getBaseContext());
getWindow().setAttributes(localLayoutParams);
View.inflate(this, R.layout.lock_screen, this.wrapperView);
this.winManager.addView(this.wrapperView, localLayoutParams);
}
public void onDestroy()
{
this.winManager.removeView(this.wrapperView);
this.wrapperView.removeAllViews();
super.onDestroy();
}
To avoid the notification bar of showing I added the flags FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_IN_SCREEN to consume all pointer events.
Not forget to add these two lines to your manifest:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
From here you just need to add the logic of your Lock Screen app to let the user use his smartphone :)
A custom launcher is basically an app (you can make it behave like a grid, list, implement your own drag and drop etc) then, you only need to add these lines to the intent filter of the main activity, with this done, after you install your app and press the home button your app will appear in the list of available homescreens.
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
What i cant find is a way to replace the lock screen, and hacks like disabling the lock screen on the phone and using an activity in a custom launcher isn't actually replacing the lockscreen ^^
You can use the below method to disable the Home key in android :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
I am developing on a Samsung Galaxy S4 5.0 and what worked for me was simply changing getWindow().setFlags(..) to getWindow().addFlags(..)
I think first of all you should ask yourself if you really want to hijack the home key. Sometimes you may want it. But I think placing the app on the Android lock screen, letting the home key act normally and letting the underlying Android lock screen take care of password-protecting the device is what you actually want in a lot of cases (unless you want to change the way this is done by default).
Bottom line, letting an app be displayed on the Android lock screen comes pretty close to writing your own custom lock screen. And is decidedly easier since you don't have to manage passwords yourself. Not to mention it's safer and more reliable since you don't hijack the home key.
I did it like this and it works very well. You can see the details here:
show web site on Android lock screen
The question is about displaying a website on the lock screen, since that's what I was interested in, but the answer is more general, it works with any app.
You can see here an app that's on Google Play and has been written like this:
https://play.google.com/store/apps/details?id=com.a50webs.intelnav.worldtime
I am building an app that will form part of an exhibition. It will be displayed on a Nexus 7 which will be securely mounted. The app has touchscreen functionality and will display interactive content.
I need to be able to disable as many features as possible whilst on display as I do not want the public to be able to get to anything other than the app.
The main thing I am struggling with is the back/home/recent app list button. I have found some examples of disabling home button (child lock Android - Is It possible to disable the click of home button
) but ideally I need the buttons to be invisible, so to turn off the 'glow' (black would be fine).
Is the bottom section on a Nexus 7 protected in some way, is there another version of Android that would allow me to do this? The Nexus device will only be used for displaying this app, no other functionality is needed.
Any suggestions would be great and very much appreciated.
Your best solution without creating your own custom Android rom to remove the bottom buttons, will be to make the app full screen, override the back button, and make your app a launcher in order to override the home button.
AFAIK, there is no way of overriding the recent apps button.
Edit: One other option would to have a fullscreen app and then use a mount that will cover the buttons. (Thanks to MaciejGórski for the idea).
To make your app full screen, put the following in your activity's onCreate():
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Or you can make the app full screen from within the manifest as well, thanks to #Niels:
<application android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
To override the back button, add this method:
#Override
public void onBackPressed() {
return;
}
Now the home button is trickier, add the following to your manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
and this to your manifest under the <activity>:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
and this to your manifest under the <application>, make sure that the <receiver name> is the full package name path you define:
<receiver android:name="com.example.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And lastly, create a java class file called BootCompleteReceiver, and use this code:
public class BootCompleteReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startActivityIntent = new Intent(context, YourActivityName.class);
startActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(parentActivityIntent);
}
}
To later disable your app as a home screen launcher, press the recent app button, swipe down from the right side, tap settings, go to apps, then tap the upper right three dots (vertically aligned), press "Reset app preferences", and then finally press "Reset apps".
I think that should just about cover it all.
EDIT 2 I just realized/tested and you do NOT necessarily need the BOOT_COMPLETED intent if you make your application a launcher. This means that the <uses-permission>, <receiver>, and BootComplete.java are not needed. You can just use the <intent-filter> that includes the MAIN, HOME, and DEFAULT attributes.
EDIT 3 More/different information available here: Home Launcher issue with Fragments after reboot
Further to the above, which all worked great, and to make sure a comprehensive answer is out there.....
AFAIK, there is no way of overriding the recent apps button.
I got around this by change onPause app behavior to start an alarmmanager. There may be a more elegant solution, but this works.
First, create repeating alarmmanager setupAlarm(seconds)( full details here and here, note I used repeating alarm rather than one off, think both will work though) that starts your activity
then change onPause to set a 2 second alarm, so whenever someone selects the recent apps button on the nav bar, a 2 second 'alarm' to start mainActivity is set.
#Override
public void onPause() {
setupAlarm(2);
finish(); //optional
super.onPause();
}
So with this and the above, any attempt to use the navigation buttons or restart the app results in app starting. So until I get round to investigating the 'kiosk' style roms this is a very good compromise.
I may be a bit late.
But i've found the, in my opinion, best solution for the Recent Apps Button Problem:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (&& !hasFocus) {
// Close every kind of system dialog
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
// send task back to front
ActivityManager activityManager =
(ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
activityManager.moveTaskToFront(getTaskId(), 0);
}
}
The "send task back to front" part will prevent the pull down of the Notification bar by simply sending it back up instantly and will close the Recent Apps View.
The other one is to close the "Shutdown/Restart" View when he tries to shut down his phone.
Now Excuse my English and have a nice Day.
Greetings
Jimmy
I'm trying to develop an application for an android tablet.
This tablet will be shown to the public and they can touch it.
I want to block all means to close the app except for a button/preference menu that requires a password.
But after some research I am not sure if this is possible.
Long press on power button still works, home button too and return button.
Will this work? if so how?
you can find all the answers in already asked questions in stackoverflow
Home Button
Return Button
Power Button
I'm pretty sure this can't be done without root access to the device, in order to avoid a troll application to take control of your Android Device if you happen to run it.
At first you need to add your application as home from your manifest
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.settings.SETTINGS" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
after add flag
getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); //(dont forget to add flag before `setContentView`)
Disable device lock
private void disableLock() {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(MainActivity.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
}
Disable home Long click
#Override
protected void onUserLeaveHint() {
startActivity(new Intent(MainActivity.this,MainActivity.class));
finish();
super.onUserLeaveHint();
}
After run you need to set your app to home application !!!
I have finally found a way to do this
No doc about this
getWindow().getDecorView().setSystemUiVisibility(8);
But the 8 is a hidden flag to completly disable system UI with this your app is permanly in full screen(Be carefull if you use this keep a way to close app)
The 8 flag is completly undocumented so i can't tell you since with version this work i dev for 4.0 and 4.1 it work for both.
Dunno for 3.0 but haven't any device to try it.
And don't forget android.permission.EXPAND_STATUS_BAR in your manifest
this is not perfect because if you use some alert dialogue the systemUi become visible but if you don't use any you can't quit
Long press power make a powerpopup who make system ui visible too
But you can kill it fast wit the following method
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(!hasFocus) {
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
}
}
If you do this you can't quit your app anymore(or i have forgot a way to close it?) so keep in mind before to make something like SureLock(app avaible on playstore), 3touch in 2 s launch an activity who ask a pass to quit it
Hope this can help and is complete
And a last question is still unanwsered
Can we custom an alert view to call setSystemUiVisibility(8); because if the battery make an alert or if you think you really need an alert, this will show system UI while you alert is visible
Simply you can't do this , you can't stop user to pressing Home Button
you can block Back press event .
You can stop user from pressing home Button using onAttachedToWindow() but this may not work from android 3.2
Background Information: I want to create a child lock application. Therefore I need to disable all the keys (including the Home key) when the user is in the application. I basically want a similar application to this one.
Problem: If I have set another application as the default home launcher (ie. in HTC the Home Sense UI, or something similar in Samsung phones) and then set my application as the default home launcher, then pressing the Home key takes me back to the home screen (even though I set my application as the default home launcher!). Now, if I don't set any other applications as the default home launcher, only my own application, then there is no problem, and when I'm inside my application and press the Home key I stay in the application.
Why is it that when I set a default home application before I set my application as the default, the Home key doesn't work (ie. leaves my app)? But when I only set my application as the default, the Home key works (ie. stays in my app).
Below is sample code for my test application:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testspinner"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testspinner.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
public class MainActivity extends Activity {
private PackageManager pm;
#Override
protected void onCreate(Bundle savedInstanceState) {
this.pm = getPackageManager();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean isHomeActivity() {
final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
List<IntentFilter> filters = new ArrayList<IntentFilter>();
filters.add(filter);
final String myPackageName = getPackageName();
List<ComponentName> activities = new ArrayList<ComponentName>();
final PackageManager packageManager = (PackageManager) getPackageManager();
packageManager.getPreferredActivities(filters, activities, null);
for (ComponentName activity : activities) {
if (myPackageName.equals(activity.getPackageName())) {
return true;
}
}
return false;
}
protected void onResume() {
super.onResume();
if (!isHomeActivity()) {
Intent localIntent = new Intent(Intent.ACTION_MAIN);
localIntent.addCategory(Intent.CATEGORY_HOME);
localIntent.setComponent(new ComponentName("android",
"com.android.internal.app.ResolverActivity"));
startActivity(localIntent);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK: {
finish();
}
}
return false;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
You can check this project on Github: https://github.com/Neamar/Summon
It's an alternative Home Application that works properly.
I don't see what can create your described behavior. It's perhaps a device-specific issue.
Did you try a reboot after setting up your app?
If you are using certain versions of Android, you actually have to clear the defaults of the app that has been set as default. I was having the same problem as you. Then I checked out the app called Home Switcher for Froyo on the app market. In that app, if a default has been set, Home Switcher brings up the default launcher's app settings screen and tells the user to select the button "clear defaults." This is the only way that I know of.
So in your app, you have to check a few different things.
If no default launcher is set, set yours (like you said above that it works already)
If a default is set, launch its app settings, prompt user to select "clear defaults", then have them press the home button and select your app
I hope this helps, I don't know if I am the best person to ask for code examples as my app is still a little buggy, but I can point you to some stack overflow answers:
https://stackoverflow.com/a/4772481/1817139
https://stackoverflow.com/a/10344985/1817139
Good luck, email me if you're stuck (lus u s_v [i] r at yahoo) - ignore brackets and spaces
Let me use an example for what I'm looking for. On my phone I have a music player widget, when active and the phone times out, the player continues working (iPod style I get that).
BUT when you turn the phone back on, the player is visible and active above the unlocking slide bar.
Is this easy to do in java? giving the user access to the application above the unlock slider (before password).
Now I know we can easily put code to avoid sleep mode. But the app that I'm working on only needs to be viewed/modified every 10 or 20 minutes and keeping the phone on is a waste of battery.
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).
There is no API for drawing on lock screen, nor can you replace lock screen with a custom one. SO you can not write an app for stock android phones that does this.
In order to do this you'd need to create a custom firmware or use non-standard features in rooted phones.