• android调用其他apk的activity


    <img src="https://img-blog.csdn.net/20160322114625025" alt="" />启动另一个apk的工程
    
    public class MainActivity extends Activity{
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    
    		super.onCreate(savedInstanceState);
    
    		Log.e("nafio","start load1");
    
    		ComponentName componetName = new ComponentName(
    				//这个是另外一个应用程序的包名
    				"com.example.t2",
    				//这个参数是要启动的Activity
    				"com.a.cc.TActivity");
    
    		try {
    			
    			Intent intent = new Intent();
    			
    			intent.setComponent(componetName);
    			
    			startActivity(intent);
    			
    		} catch (Exception e) {
    			
    			Toast.makeText(getApplicationContext(), "可以在这里提示用户没有找到应用程序,或者是做其他的操作!", 0).show();
    
    			Log.e("nafio",e.getMessage());
    		}
    
    		Log.e("nafio","end load");
    	}
    
    }


    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.n.tlaunchotherapk"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            
            <activity
                android:name=".MainActivity"
                android:configChanges="keyboardHidden|navigation"
                android:label="@string/app_name"
                android:screenOrientation="portrait">
                
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>


    被启动的工程,包名为com.example.t2 ,因为TActivity为非Action.Main,要想外部访问,要加android:exported="true"



    package com.example.t2;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    
    
    public class MainActivity extends Activity{
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    
    		super.onCreate(savedInstanceState);
    
    		Log.e("nafio","T2---------------");
    
    		
    
    	}
    
    }


    package com.a.cc;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    
    public class TActivity  extends Activity{
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    
    		super.onCreate(savedInstanceState);
    
    		Log.e("nafio","TActivity!!!!!---------------");
    
    		
    
    	}
    
    }

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.t2"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            
            <activity
                android:name=".MainActivity"
                android:configChanges="keyboardHidden|navigation"
                android:label="@string/app_name"
                android:screenOrientation="portrait">
                
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            
            <activity
                android:name="com.a.cc.TActivity"
                android:configChanges="keyboardHidden|navigation"
                android:label="@string/app_name"
                <span style="color:#ff0000;">android:exported="true"</span>
                android:screenOrientation="portrait">
            </activity>
            
            
        </application>
    
    </manifest>
    



  • 相关阅读:
    POJ 1721 CARDS(置换群)
    HDU 4609 3-idiots(FFT)
    BZOJ 4259 残缺的字符串(FFT)
    HDU 5763 Another Meaning(FFT)
    BZOJ 4503 两个串(FFT)
    hihoCoder 1388 Periodic Signal(FFT)
    HDU 5823 color II(FWT)
    HDU 5768 Lucky7(CRT+容斥原理)
    HDU 5446 Unknown Treasure(Lucas定理+CRT)
    HDU 5741 Helter Skelter(构造法)
  • 原文地址:https://www.cnblogs.com/nafio/p/9137401.html
Copyright © 2020-2023  润新知