2012-01-15 57 views
1

我有點困惑,爲什麼隱式意圖調用失敗。當試圖啓動的意圖我不斷收到以下錯誤:未能以隱式意圖啓動活動

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://org.chrisolsen.crossfit.providers.WorkoutProvider/workouts typ=vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout } 

AndroidManifest

<activity android:name=".activities.WorkoutsActivity" 
     android:label="@string/title_workouts" > 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <data android:mimeType="vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout"/> 
     </intent-filter> 
    </activity> 

    <provider 
     android:name=".providers.WorkoutProvider" 
     android:authorities="org.chrisolsen.crossfit.providers.WorkoutProvider" />  

調用活動板(dashboard)

Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(WorkoutProvider.CONTENT_URI, "vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout"); 
    startActivity(intent); 

調用活動(訓練)。它不會讓它在這裏

Uri uri = getIntent().getData(); 
    ... 

它似乎應該很簡單,但我很困惑,爲什麼它說沒有找到活動。

任何想法?

+0

你有申報清單中的您的供應商WorkoutProvider? – Bourbon 2012-01-15 21:46:01

+0

是的,我願意。我已經更新了這個問題。儘管提供者需要調用一個意圖? – chris 2012-01-15 22:01:27

回答

4

爲了與隱含的意圖開始,一個活動必須申報

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

此外,請確保您使用startActivity代替sendBroadcast。這些方法有區別。活動的意向過濾器不會收到廣播。您必須使用BroadcastReceiver

Note that, although the Intent class is used for sending and receiving these broadcasts, the Intent broadcast mechanism here is completely separate from Intents that are used to start Activities with Context.startActivity(). There is no way for a BroadcastReceiver to see or capture Intents used with startActivity(); likewise, when you broadcast an Intent, you will never find or start an Activity. These two operations are semantically very different: starting an Activity with an Intent is a foreground operation that modifies what the user is currently interacting with; broadcasting an Intent is a background operation that the user is not normally aware of.

來源:http://developer.android.com/reference/android/content/BroadcastReceiver.html

Android docs: sendBroadcast

Android docs: startActivity