启动其他APP的Activity

[java]  view plain copy
  1. // 这个是另外一个应用程序的包名, 这个参数是要启动的Activity  
  2. ComponentName componetName = new ComponentName("com.example.testtask""com.example.testtask.Main2Activity");  
  3. try {  
  4.     Intent intent = new Intent();  
  5.     intent.setComponent(componetName);  
  6.     startActivity(intent);  
  7. catch (Exception e) {  
  8.     Toast.makeText(getApplicationContext(), "可以在这里提示用户没有找到应用程序,或者是做其他的操作!"0).show();  
  9. }  

以上代码只能在启动某个应用的主Activity或带有

[html]  view plain copy
  1. <intent-filter>  
  2.     <category android:name="android.intent.category.DEFAULT" />  
  3. </intent-filter>  
的Activity
方法二:
在别调用的activity中加入
[html]  view plain copy
  1. <intent-filter>    
  2.         <action android:name="chroya.foo"/>    
  3.         <category android:name="android.intent.category.DEFAULT"/>    
  4. </intent-filter>    
启动activity
[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);    
  2. intent.putExtra(SearchManager.QUERY,"searchString")    
  3. startActivity(intent);    




//---------------------分割-------------------
//---------------------分割-------------------
试过第一种方法了,但是会报一个错误,

<span style="background-color: rgb(255, 255, 255);">I/ActivityManager(  518): START {cmp=com.example.testandroid/.TestActivity2 u=0}
 from pid 25894
W/ActivityManager(  518): Permission denied: checkComponentPermission() owningUid=10103
W/ActivityManager(  518): Permission Denial: starting Intent { cmp=com.example.testandroid/.TestActivity2 } from ProcessRecord{42186510 25894:com.robot.sample/u
0a139} (pid=25894, uid=10139) not exported from uid 10103
D/WifiStateMachine(  518): ConnectedState{ what=131155 when=-3ms arg1=63 }
D/WifiStateMachine(  518): L2ConnectedState{ what=131155 when=-4ms arg1=63 }
D/wpa_supplicant(  767): wpa_s 0x41b31380 cmd SIGNAL_POLL
D/wpa_supplicant(  767): nl80211: survey data missing!
D/WifiStateMachine(  518): ConnectedState{ what=131155 when=-3ms arg1=63 }
D/WifiStateMachine(  518): L2ConnectedState{ what=131155 when=-5ms arg1=63 }
D/wpa_supplicant(  767): wpa_s 0x41b31380 cmd SIGNAL_POLL
D/wpa_supplicant(  767): nl80211: survey data missing!</span>


设置成android:exported="ture"才行:
<span style="background-color: rgb(255, 255, 255);"><activity
            android:name=".TestActivity2"
            android:exported="true" >
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
</activity></span>





你可能感兴趣的:(启动其他APP的Activity)