【发布时间】: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);
}
});
}
}
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>
【问题讨论】:
-
你找到了解决方案,你能告诉我我也有同样的问题,无法显示设备的主屏幕