gpt4 book ai didi

android - 点击按钮时如何显示应用程序启动器对话框

转载 作者:行者123 更新时间:2023-11-29 01:39:07 24 4
gpt4 key购买 nike

当我使用两个选项点击Home按钮设置为家庭应用程序时,我会收到应用程序启动器对话框 - 首先,默认手机应用程序和第二个我的应用程序,使用这个:

Activity :

public class DefaultLaunchActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
}
}

list .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>

但是,如果我必须在用户点击按钮时显示Application Launcher Dialog

btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// what to put here to show app launcher dialog
}
});

最佳答案

你需要像下面这样自定义一些东西:

First : on click of button define this :

Intent intent = new Intent("com.mtetno.MYACTION"); 
startActivity(intent);

Second define this in manifest :

<activity 
android:name=".AndroidHomeActivity" >
<intent-filter>
<action android:name="com.mtetno.MYACTION" /
</intent-filter>
</activity>


<activity
android:name=".MyActivity" >
<intent-filter>
<action android:name="com.mtetno.MYACTION" />
</intent-filter>
</activity>

Write AndroidHomeActivity activity as :

public class AndroidHomeActivity extends Activity { 
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

}
}

关于android - 点击按钮时如何显示应用程序启动器对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25948292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com