在一个apk中调用另外一个apk中的activity

一、生成一个要被调用的APK。在其Manifest.xml设置中,与一般的写法大致相同,唯一区别的地方在于,如下:

<activity
        android:name="com.example.test.TestActivity"
        android:label="@string/app_name" >

    <!--<intent-filter>
             <action android:name="android.intent.action.MAIN" />

             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter> 
    -->
         <intent-filter >
              <action android:name="testApp"/>
              <category android:name="android.intent.category.DEFAULT"/>
         </intent-filter>
</activity>

二、安装这个要被调用的APK。

        安装完毕之后,你会发现,系统中找不到这个程序。别急,它确实安装在手机里面了,但是因为他不是main的,所以系统不会把他当做Application的入口程序。而要想打开这个activity,只有知道它名字的人才可以。跟系统的intent一样使用。它的名字定义为"testApp",所以,这里用这个字符串就可以调用它了:

三、在另一个项目中调用上述APK。代码如下:

Intent intent = new Intent("testApp");
startActivity(intent);

四、启动另外一个apk

Intent mIntent = new Intent( );   
ComponentName comp = new ComponentName(packageName, activityName);  
mIntent.setComponent(comp);   
mIntent.setAction("android.intent.action.VIEW");   
startActivity(mIntent);


转载于:https://my.oschina.net/u/1251149/blog/221444

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值