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

时间:2014-09-20 11:32:06

标签: android

当我点击Home按钮并two options设置为家庭应用时,我正在获取应用启动器对话框 - 首先是default手机应用,第二个mine app,这样:

活动:

public class DefaultLaunchActivity extends Activity {

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

的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>

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

btn.setOnClickListener(new OnClickListener() {

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

1 个答案:

答案 0 :(得分:1)

您需要自定义以下内容:

  

首先:点击按钮定义:

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

其次在清单中定义:

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

将AndroidHomeActivity活动写为:

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

} 
}