Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

Disable Home Button in Android ICS (4.0)

I am making a proprietary app for a company which will never release it to the Android Market (or Play Store I guess now) in Ice Cream Sandwich (Android 4.0).

I need to disable the Home so the users cannot maliciously uninstall software or delete the data that the app captures. This latest version is the first to be written in 4.0, the previous versions were written in 2.2 and 3.2.

For disabling the Home button in 2.2, I associated the app as a home replacement, so the button just reopened the app, but I can no longer use this method, as that somewhat prevents us from doing our updates to the app (we don't want to give the user the option of reselecting a Home default, as that would lead to data deletion.

The code I have for disableing the Home button in 3.2 is:

@Override
public void onAttachedToWindow() {
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
     super.onAttachedToWindow();
}

and, under onCreate:

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

But when I run the same code that worked on my 3.2 tablet, it does not work on my 4.0 tablet.

I was wondering if there is a new API or method that 4.0 has that will accomplish the same effect as I currently have in my 3.2 implementation.

Thanks for any help or direction.

Adam

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How about a workaround..

Write a second app that implements the home screen, when the home screen button is pressed this app will come to the foreground. From this app you then need to push your main app back to the foreground. The only catch is that your Home screen app must never need an update, but you should be able to update the main app freely without the tab asking to set the home launcher.

Hope that makes sense..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...