应用之间进行跳转,ComponentName的方式

从应用A跳转到应用B,  

关键代码如下:  

有以下几个注意点:

1.ComponentName cn = new ComponentName("com.terry", "com.terry.musicActivity");

android. content. ComponentName.ComponentName( String pkg, String cls)

 

Create a new component identifier.

Parameters:
pkg The name of the package that the component exists in. Can not be null.
cls The name of the class inside of pkg that implements the component. Can not be null.
第一个参数:应用B的包名,是String型的;
第二个参数:应用B的类名,要包含包名,即类名的全称,也是String类型的,否则系统会报错。

注意点2:

应用B的12行一定要写上:

1  android:exported="true"

这个属性,即暴露出本应用,是其他应用可以访问。

case R.id.btn_main4_2:
				// TODO Auto-generated method stub
				ComponentName cn = new ComponentName("com.terry", "com.terry.musicActivity");
				Intent intent2 = new Intent();
				intent2.setComponent(cn);
				Toast.makeText(TestAction.this, "跨应用跳转", Toast.LENGTH_SHORT).show();
				startActivity(intent2);
				break;

  B的清单文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.terry"
 4     android:versionCode="1"
 5     android:versionName="1.0" >
 6 
 7     <application
 8         android:icon="@drawable/icon"
 9         android:label="@string/app_name" >
10         <activity
11             android:name=".musicActivity"
12             android:exported="true"
13             android:label="@string/app_name" >
14             <intent-filter>
15                 <action android:name="android.intent.action.MAIN" />
16 
17                 <category android:name="android.intent.category.LAUNCHER" />
18             </intent-filter>
19         </activity>
20         <activity
21             android:exported="true"
22             android:name="com.terry.myActivity2"
23             android:label="musicPlayer" >
24             <intent-filter>
25                 <action android:name="android.intent.action.VIEW" />
26                 <action android:name="android.intent.action.GET_CONTENT" />
27 
28                 <category android:name="android.intent.category.DEFAULT" />
29                 <!--
30                      audio/x-mpeg 
31                     <data android:mimeType="*/*" />
32                 -->
33                 <!-- 注册可以打开音乐 -->
34                 <data android:mimeType="audio/mpeg" />
35             </intent-filter>
36             
37         </activity>
38     </application>
39 
40 </manifest>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值