I've written a custom Launcher and it works pretty nice. The Launcher has some pages filled with applications. I want to implement, that the variable that represents the page number is set to 0, if the homebutton is pressed. So if you are on a different page of the launcher and press the homebutton, you enter the starting page.
I've searched a lot, but couldn't find an answer that worked for me.
I've set the app as an launcher in the manifest.
<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>
Is it possible to achieve this? Just change the value of one variable, if the home button is pressed and leave the rest of the home button, as it is.
For everybody who want to do the same thing. that's the way i solved it:
I added the following to the manifest:
<activity
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true">
and wrote this into the java activity:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
final boolean alreadyOnHome =
((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
if (alreadyOnHome) {
Log.d("whatever", "Home pressed");
}
}
}
I got it from here: CyanogenMod trebuchet
Related
I want to intercept home button click of Android device in lollipop version.
I think this can be done in another style if suits your requirement. By
creating your activity as home activity. If you want to disable home button
and show your custom application activity as launcher when home button is
pressed. Just add these lines in manifest for that activity for which you want your launcher.
<activity
android:name="com.example.TempActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="landscape"
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>
if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.
if you want fully disable the user, so that he cant move to another screen
then set theme to fullscreen with NoTilebar.
Use this method:
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
};
Im playing with a lockscreen and selcted my second activity as home launcher now.
So the home key is locked on lockscreen.
How do i start now the nova launcher (or another custom launcher) instead of my empty layout from second activity when I press the home key outside from lockscreen?
I'm a bit confused on this topic.
EDIT:
I have currently that configurations for my lockscreen activity in my manifest:
<activity
android:name=".LockscreenActivity"
android:excludeFromRecents="true"
android:screenOrientation="portrait"
android:launchMode="singleInstance"
android:clearTaskOnLaunch="true"
android:label="Lockscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- The following two intent-filters are the key to set homescreen -->
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Any i found out that i can use the onNewIntent. But it dont work :/
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("debug", "actions: " + intent.getAction());
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Log.e("debug", "ACTION MAIN");
Intent i = getPackageManager().getLaunchIntentForPackage("com.teslacoilsw.launcher");
startActivity(i);
}
}
Every time the lockscreenactivity will open when i press the home button.
I am working on a launcher application. It is being show along with the default launcher on pressing the back button. However, wherever I am in my custom launcher or whether in the starting page of my launcher it self, when I press the back button, the screen navigates back to the default android launcher. I need help.
This is the code I used to set my app as a launcher
<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.MONKEY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
thank you in advance
This seemed to work for me
Kotlin
override fun onBackPressed() {}
Java
#Override
public void onBackPressed() {}
Those are categories for intents, android.intent.category.LAUNCHER just means when you run the application it will launch the specified class
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?
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?
I want to achieve the goal that after installing an application, two icons appear in the Launcher. Clicking on either one of them will launch the corresponding activity. With the XML and JAVA code at the bottom, everything seems to work fine, except one case:
BUG:
Step 1. Click icon 1 to start activity 1
Step 2. Click Home icon to swtich to Launcher
Step 3. From Launcher, click icon 2
Expected result: Activity 2 gets started.Actual result: Activity 1 gets resumed.
Notice that in step 2, if I click the Back button instead of the Home button to get back to he launcher, then step 3 would succeed. But if I used the Home button, then the bug happens. Could someone please tell me what did I mess? Much appreciate!
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity
android:name=".TestActivity1"
android:label="Test 1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TestActivity2"
android:label="Test 2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
// The first activity
public class TestActivity1 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
// The second activity, it uses a different content view
public class TestActivity2 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
}
Give your activities different task affinities, so they are independent.