您的位置:首页 > 移动开发

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

2017-04-01 09:43 537 查看
老板临时让我做一个demo ,实现一个app打开另一个app  

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

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

    父程序核心代码

              public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent 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>
        
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐