0

I am writing an app in which i have to show device's Home Launcher when user do click on button (which i have placed on my own launcher), I tried using this code, but its showing all the apps installed on my device, but what if i want to show Device's Home Launcher only on button click

public class DefaultLaunchActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        btnDeviceLauncher = (Button) findViewById(R.id.button1);
        btnDeviceLauncher.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_LAUNCHER);
                startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(startMain);
            }
        });
     }
}

manifest.xml

<activity
    android:name="com.def.launc.DefaultLaunchActivity"
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
    android:launchMode="singleTask"
    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>
Sun
  • 6,768
  • 25
  • 76
  • 131
  • u found solution can u pls tell me i also have same issues failed to show home screen of device – Erum May 11 '15 at 04:54

1 Answers1

1

First of all, a launcher application is also launched by an Intent. So if you write your own launcher application and set that application as your default launcher application, the next time there is an Intent for the launcher application, your own application is going to be launched, not the previous launcher because the Intent is for the launcher application and your application is the launcher application right now.

So if you want the original launcher application to be launched from inside your launcher (although I don't think it will look the same as when it was actually the launcher) you will have to launch it manually using the package name as described here: start application knowing package name.

To get the package name of the actual launcher application refer: How can I get the package name of the current launcher in android 2.3 and above?

Community
  • 1
  • 1
shyam
  • 1,348
  • 4
  • 19
  • 37