Disable Home button by making my app a homeScreen App









up vote
1
down vote

favorite












I am trying to develop a lock application, I disabled the home button click but only in the phone where the button is hard clicked, but in the latest versions where there is no hard home button, the home button is not disabled. So After search I discovered that the only way to handle this problem is to make my app like the HomeScreen, I added this to my manifest:



 <activity
android:name=".HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<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>


When running this app, it shows me to choose between my app and android screen, when i choose my app, everytime i click the home button it opens my app!



My questions are:



1- Is that the only way to handle the home button in all android versions? by making my app a HomeScreen app?



2- Is there any other way to disable the home button only when my app is opened?



3- How Can I switch to TouchWiz default home screen programatically and remove my app as homeScreen when the lock is opened successfully ?



Thank you










share|improve this question























  • do you have another activity to be started on application launch?
    – gratien asimbahwe
    yesterday











  • Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
    – Mr.Geek
    yesterday















up vote
1
down vote

favorite












I am trying to develop a lock application, I disabled the home button click but only in the phone where the button is hard clicked, but in the latest versions where there is no hard home button, the home button is not disabled. So After search I discovered that the only way to handle this problem is to make my app like the HomeScreen, I added this to my manifest:



 <activity
android:name=".HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<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>


When running this app, it shows me to choose between my app and android screen, when i choose my app, everytime i click the home button it opens my app!



My questions are:



1- Is that the only way to handle the home button in all android versions? by making my app a HomeScreen app?



2- Is there any other way to disable the home button only when my app is opened?



3- How Can I switch to TouchWiz default home screen programatically and remove my app as homeScreen when the lock is opened successfully ?



Thank you










share|improve this question























  • do you have another activity to be started on application launch?
    – gratien asimbahwe
    yesterday











  • Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
    – Mr.Geek
    yesterday













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to develop a lock application, I disabled the home button click but only in the phone where the button is hard clicked, but in the latest versions where there is no hard home button, the home button is not disabled. So After search I discovered that the only way to handle this problem is to make my app like the HomeScreen, I added this to my manifest:



 <activity
android:name=".HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<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>


When running this app, it shows me to choose between my app and android screen, when i choose my app, everytime i click the home button it opens my app!



My questions are:



1- Is that the only way to handle the home button in all android versions? by making my app a HomeScreen app?



2- Is there any other way to disable the home button only when my app is opened?



3- How Can I switch to TouchWiz default home screen programatically and remove my app as homeScreen when the lock is opened successfully ?



Thank you










share|improve this question















I am trying to develop a lock application, I disabled the home button click but only in the phone where the button is hard clicked, but in the latest versions where there is no hard home button, the home button is not disabled. So After search I discovered that the only way to handle this problem is to make my app like the HomeScreen, I added this to my manifest:



 <activity
android:name=".HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<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>


When running this app, it shows me to choose between my app and android screen, when i choose my app, everytime i click the home button it opens my app!



My questions are:



1- Is that the only way to handle the home button in all android versions? by making my app a HomeScreen app?



2- Is there any other way to disable the home button only when my app is opened?



3- How Can I switch to TouchWiz default home screen programatically and remove my app as homeScreen when the lock is opened successfully ?



Thank you







android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









Mr.Geek

105




105











  • do you have another activity to be started on application launch?
    – gratien asimbahwe
    yesterday











  • Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
    – Mr.Geek
    yesterday

















  • do you have another activity to be started on application launch?
    – gratien asimbahwe
    yesterday











  • Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
    – Mr.Geek
    yesterday
















do you have another activity to be started on application launch?
– gratien asimbahwe
yesterday





do you have another activity to be started on application launch?
– gratien asimbahwe
yesterday













Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
– Mr.Geek
yesterday





Yes I did, but the problem is that everytime you click on the home button it opens the application, and also there is no way to uninstall it from your phone!
– Mr.Geek
yesterday













1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try removing the other activity and proceed this way:



 <activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>


Every time someone hits the home button, it will be opening your activity which is a home screen and this time it will not have to open the home activity first.



EDIT:



If then you want to comeback to your default launcher after home button pressed, you can override these methods:






 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;








share|improve this answer






















  • Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
    – Mr.Geek
    yesterday










  • I have edited my answer, please check
    – gratien asimbahwe
    yesterday










  • It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
    – Mr.Geek
    yesterday










  • I have updated my answer, please check. if it works come back and mention it works to help future readers.
    – gratien asimbahwe
    yesterday










  • App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
    – Mr.Geek
    yesterday










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224482%2fdisable-home-button-by-making-my-app-a-homescreen-app%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Try removing the other activity and proceed this way:



 <activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>


Every time someone hits the home button, it will be opening your activity which is a home screen and this time it will not have to open the home activity first.



EDIT:



If then you want to comeback to your default launcher after home button pressed, you can override these methods:






 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;








share|improve this answer






















  • Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
    – Mr.Geek
    yesterday










  • I have edited my answer, please check
    – gratien asimbahwe
    yesterday










  • It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
    – Mr.Geek
    yesterday










  • I have updated my answer, please check. if it works come back and mention it works to help future readers.
    – gratien asimbahwe
    yesterday










  • App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
    – Mr.Geek
    yesterday














up vote
0
down vote













Try removing the other activity and proceed this way:



 <activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>


Every time someone hits the home button, it will be opening your activity which is a home screen and this time it will not have to open the home activity first.



EDIT:



If then you want to comeback to your default launcher after home button pressed, you can override these methods:






 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;








share|improve this answer






















  • Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
    – Mr.Geek
    yesterday










  • I have edited my answer, please check
    – gratien asimbahwe
    yesterday










  • It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
    – Mr.Geek
    yesterday










  • I have updated my answer, please check. if it works come back and mention it works to help future readers.
    – gratien asimbahwe
    yesterday










  • App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
    – Mr.Geek
    yesterday












up vote
0
down vote










up vote
0
down vote









Try removing the other activity and proceed this way:



 <activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>


Every time someone hits the home button, it will be opening your activity which is a home screen and this time it will not have to open the home activity first.



EDIT:



If then you want to comeback to your default launcher after home button pressed, you can override these methods:






 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;








share|improve this answer














Try removing the other activity and proceed this way:



 <activity android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>


Every time someone hits the home button, it will be opening your activity which is a home screen and this time it will not have to open the home activity first.



EDIT:



If then you want to comeback to your default launcher after home button pressed, you can override these methods:






 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;








 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;





 
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)

Intent intent=null;
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY))

if(!getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)

intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
startActivity(intent);
break;



if(keyCode==KeyEvent.KEYCODE_BACK)

finish();

return false;






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









gratien asimbahwe

6671421




6671421











  • Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
    – Mr.Geek
    yesterday










  • I have edited my answer, please check
    – gratien asimbahwe
    yesterday










  • It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
    – Mr.Geek
    yesterday










  • I have updated my answer, please check. if it works come back and mention it works to help future readers.
    – gratien asimbahwe
    yesterday










  • App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
    – Mr.Geek
    yesterday
















  • Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
    – Mr.Geek
    yesterday










  • I have edited my answer, please check
    – gratien asimbahwe
    yesterday










  • It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
    – Mr.Geek
    yesterday










  • I have updated my answer, please check. if it works come back and mention it works to help future readers.
    – gratien asimbahwe
    yesterday










  • App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
    – Mr.Geek
    yesterday















Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
– Mr.Geek
yesterday




Yes, but my application is only a phone lock app, that means when the user enters the code successfuly, i want the default home screen to be the normal one : TouchWiz and not my app! is there any way to do it programatically?
– Mr.Geek
yesterday












I have edited my answer, please check
– gratien asimbahwe
yesterday




I have edited my answer, please check
– gratien asimbahwe
yesterday












It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
– Mr.Geek
yesterday




It's exactly what i needed! what is the code to launch default launcher or to open the chooser of home screens?
– Mr.Geek
yesterday












I have updated my answer, please check. if it works come back and mention it works to help future readers.
– gratien asimbahwe
yesterday




I have updated my answer, please check. if it works come back and mention it works to help future readers.
– gratien asimbahwe
yesterday












App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
– Mr.Geek
yesterday




App crashes! it shows me this exception: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
– Mr.Geek
yesterday

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224482%2fdisable-home-button-by-making-my-app-a-homescreen-app%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo