一个app打开另一个子app+子app安装不在手机桌面显示

来源:互联网 发布:吉诺比利底线传球 知乎 编辑:程序博客网 时间:2024/04/28 09:37

老板临时让我做一个demo ,实现一个app打开另一个app  

            要求:点击打开按钮,已安装过的话 打开,没有安装显示安装

                       子程序不能再手机页面显示图标

    父程序核心代码

             

                       public void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();//com.example.demo2 :子程序包名               com.example.demo2.MainActivity:子程序打开页面        ComponentName cn = new ComponentName("com.example.demo2","com.example.demo2.MainActivity");        intent.setComponent(cn);        intent.setAction("android.intent.action.MAIN");        try {            startActivityForResult(intent, RESULT_OK);        } catch (Exception e) {            Toast.makeText(MainActivity.this, "没有子APP,请下载安装",Toast.LENGTH_SHORT).show();        }}
 

子程序 只需要在manifest文件下 设置一行代码

                   

<application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.demo2.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <!-- <category android:name="android.intent.category.LAUNCHER" /> -->//注释掉这一行            </intent-filter>        </activity>    </application>

        

0 0