zoukankan      html  css  js  c++  java
  • 应用之间进行跳转,ComponentName的方式

    从应用A跳转到应用B,  

    关键代码如下:  

    有以下几个注意点:

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

    Open Declaration 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>
  • 相关阅读:
    kingbase8d常见问题
    kibana-7.9.1安装
    ElasticSearch-7.9.1
    在线分析-jstack
    Wireshark常用过滤条件
    shiro登录认证过程
    查看mysql库中所有表的大小和记录数
    linux设置定时任务crontab
    POI 使用常见问题
    Java源码之String-构造方法
  • 原文地址:https://www.cnblogs.com/Sunnor/p/4845939.html
Copyright © 2011-2022 走看看