在安卓程序中启动另一个程序

从一个应用程序中启动令一个应用程序
 启动程序的代码:
     Intent intent = new Intent();   
               intent.setAction("com.netvista.bj.entry");   
               startActivity(intent); 
被启动程序的Androidmanifest.xml文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.netvista.bj"
    android:versionCode="33"
    android:sharedUserId="com.vixtel.netvista"
    android:versionName="2.0.1.33" >
<application android:name=".app.MobileIqApplication" 
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true"
        android:theme="@android:style/Theme.NoTitleBar">
        <activity android:name=".app.NetDiagMainActivity" 
            android:launchMode="singleTask"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
            <intent-filter>
              <action android:name="com.netvista.bj.entry" />
             <action android:name="android.intent.action.MAIN" />   
             <category android:name="android.intent.category.DEFAULT" /> 

            </intent-filter>
        </activity>
        <activity android:name=".app.WifiDiagnosisActivity" 
            android:launchMode="singleTask"
            android:screenOrientation="portrait">
        </activity>
        <activity android:name=".app.SettingActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> 
         <service android:enabled="true" android:name=".testagent.TestAgentService"/>
    </application>
</manifest>
2 安装apk方法(apk文件已存在SD根目录下)
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath()+
 "/SpeedClient-Bj.apk"),"application/vnd.android.package-archive");
    mContext.startActivity(intent);//mContext= this;
3将assets文件提取出来并放到SD根目录下:
 public boolean copyApkFromAssets(Context context, String fileName, String path) {
         boolean copyIsFinish = false;
         try {              
             InputStream is = context.getAssets().open(fileName);
             Toast.makeText(this, path,0).show();
             File file = new File(path);
             file.createNewFile();
             Toast.makeText(this, fileName,0).show();
             FileOutputStream fos = new FileOutputStream(file);
             byte[] temp = new byte[1024];
             int i = 0;
             while ((i = is.read(temp)) > 0) {
                 fos.write(temp, 0, i);
             }             
             fos.close();
             is.close();
             copyIsFinish = true;
         } catch (IOException e) {
             e.printStackTrace();
         }
         return copyIsFinish;
     }
调用copyApkFromAssets(this, "SpeedBj.apk", Environment.getExternalStorageDirectory().getAbsolutePath()+"/SpeedBj.apk"));// 将SpeedBj.apk复制到SD根目录,当然得有写SD卡的权限:    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值