2013-07-18 46 views
0

我寫一個應用程序,它處理一些特定的意圖過濾器,這裏是應用程序的清單打開第二個應用程序:無法使用自定義意向行動的Android

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.company.sampleapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="15" 
     android:targetSdkVersion="17" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name"> 
     <activity 
      android:name="com.company.sampleapp.MainActivity" 
      android:enabled="true" 
      android:exported="true" 
      android:label="@string/app_name" > 

      <!-- 1 filter --> 
      <intent-filter> 
       <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_1" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 

      <!-- 2 filter --> 
      <intent-filter> 
       <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_2" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 

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

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.company.sampleapp.Seconf=dActivity" 
      /> 
    </application> 
</manifest> 

我打電話從第二個應用程序這個應用程序使用下面的代碼:

Intent i = new Intent("com.company.sampleapp.ACTION_DO_SOMETHING_1"); 
startActivityForResult(i, 100); 

我也曾嘗試:

Intent i = new Intent(); 
i.setAction("com.company.sampleapp.ACTION_DO_SOMETHING_1"); 
startActivityForResult(i, 100); 

但每當我收到以下例外:

07-18 14:22:56.234: E/AndroidRuntime(12051): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.company.sampleapp.ACTION_DO_SOMETHING_1 } 

請幫忙。

回答

1

我想你是失蹤<data android:mimeType="..."/><intent-filter>

<intent-filter> 
    <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_1" /> 
    <data android:mimeType="*/*"/> 
    <category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 

閱讀嘗試更多關於Allowing Other Apps to Start Your Activity

0

創建只能從當前應用程序運行活動的意圖。
您可以用午餐

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); 
startActivity(LaunchIntent); 

檢查這個question形式更多信息

另一個應用程序
相關問題