【问题标题】:How to Show Device's Home Launcher from my own Launcher如何从我自己的 Launcher 显示设备的 Home Launcher
【发布时间】:2014-11-16 02:30:07
【问题描述】:

我正在编写一个应用程序,当用户单击按钮时,我必须在其中显示设备的 Home Launcher(我已将其放置在我自己的启动器上),我尝试使用此代码,但它显示了我设备上安装的所有应用程序,但是如果我只想在按钮单击时显示设备的主页启动器怎么办

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);
            }
        });
     }
}

ma​​nifest.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>

【问题讨论】:

  • 你找到了解决方案,你能告诉我我也有同样的问题,无法显示设备的主屏幕

标签: android android-launcher


【解决方案1】:

首先,启动器应用程序也由Intent 启动。因此,如果您编写自己的启动器应用程序并将该应用程序设置为默认启动器应用程序,那么下次启动器应用程序出现 Intent 时,将启动您自己的应用程序,而不是以前的启动器,因为Intent 用于启动器应用程序,而您的应用程序现在的启动器应用程序。

因此,如果您希望从启动器内部启动原始启动器应用程序(尽管我认为它看起来与实际启动器不同),您必须使用包名称手动启动它此处描述:start application knowing package name

要获取实际启动器应用程序的包名,请参考:How can I get the package name of the current launcher in android 2.3 and above?

【讨论】:

    猜你喜欢
    • 2012-04-20
    • 2014-12-28
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 2016-08-02
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多