问题
I am making a children's app and I would like to add a child lock to it, just like the one on the app called "Toddler lock". Toddler lock asks you to set the default launcher when the lock is turned on which allows the home button to be disabled. How would I do this?
回答1:
Ok so ive got a rough working example here:
Create two activities and two layouts, in the main layout place a normal button. The other layout can just have a blank
<LinearLayout>
.This is what my manifest looks like:
<activity android:name=".MainActivity" android:label="@string/title_activity_main" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".secondact" android:label="@string/secondtitle"> <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> </activity>
Notice <category android:name="android.intent.category.HOME" />
in second activity.
Here is the code from my main activity:
@Override public void onResume() { super.onResume(); Button btn = (Button)findViewById(R.id.startBtn); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent startMain = new Intent(Intent.ACTION_MAIN, null); startMain.addCategory(Intent.CATEGORY_HOME); startActivity(startMain); } }); }
And in my second activity i have:
@Override public void startActivity(Intent intent) { super.startActivity(intent); }
When i click the startbtn i get the dialog that you are talking about and you get to chooose launcher or the secondactivity, and select always use. The back button still gets you home, but hopefully this helps. This question might help you further: Disable home button in android toddler app?
来源:https://stackoverflow.com/questions/12048135/android-custom-launcher-like-toddler-lock