打开选择手机中的应用对话框

public class MainActivity extends AppCompatActivity {

    public static final int MY_REQUEST_ALL_APPLICATION = 1;

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

    public void selectAllApp(View v) {
        //重新发送一个Action为Pick_Activity的Intent,获取所有应用程序信息
        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        Intent mainIntent = new Intent();
        mainIntent.setAction(Intent.ACTION_MAIN);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
        //设置界面title
        pickIntent.putExtra(Intent.EXTRA_TITLE, "选择应用程序");

        //继续选择所有应用程序
        startActivityForResult(pickIntent, MY_REQUEST_ALL_APPLICATION);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == MY_REQUEST_ALL_APPLICATION) {
            if (data != null) {
                Toast.makeText(this, "packageName=" + data.getDataString(), Toast.LENGTH_LONG).show();
            }
        }
    }
}

布局文件:




    
示意图.jpg

你可能感兴趣的:(打开选择手机中的应用对话框)