我正在编写Twitter应用程序,并且已经按照Android-developers(http://android-deve..linkify-your-text.html)的Linkify指南来使用户名(例如@ brk3)可点击。
然后我创建了一个内容提供程序实现来获取在单击这些内容时触发的意图。我的问题是,意图似乎没有找到我的提供者,所以在点击其中一个链接时我得到以下异常:(例如,当点击用户名'Arubin'时)
E/AndroidRuntime( 5228): android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.intent.action.VIEW dat=content://com.bourke.test/screenname/Arubin (has extras) }
E/AndroidRuntime( 5228): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.j
ava:1512)
E/AndroidRuntime( 5228): at android.app.Instrumentation.execStartActivity(Instrumentation.java:138
4)
...
以下是我的AndroidManifest.xml的相关内容:
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:name="TestApplication"
android:uiOptions="splitActionBarWhenNarrow">
<provider
android:name="com.bourke.test.provider.TestProvider"
android:authorities="com.bourke.test.provider" />
<activity android:name="TestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType=
"vnd.android.cursor.item/vnd.test.screenname" />;
</intent-filter>
</activity>
...
提供者:
package com.bourke.test.provider;
public class TestProvider extends ContentProvider {
/* The root authority for this provider */
public static final String AUTHORITY = "com.bourke.test.provider";
private static final String BASE_PATH = "screenname";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/" + BASE_PATH);
public static final int SCREEN_NAMES = 0;
public static final int SCREEN_NAME = 1;
private static final UriMatcher mUriMatcher = new UriMatcher(
UriMatcher.NO_MATCH);
static {
mUriMatcher.addURI(AUTHORITY, BASE_PATH, SCREEN_NAMES);
mUriMatcher.addURI(AUTHORITY, BASE_PATH+"/*", SCREEN_NAME);
}
@Override
public boolean onCreate() {
Log.d(TAG, "XXX: onCreate()");
/* The provider was successfully loaded */
return true;
}
@Override
public int update(Uri uri, ContentValues values, String where,
String[] whereArgs) {
throw new UnsupportedOperationException();
}
@Override
public int delete(Uri uri, String where, String[] whereArgs) {
throw new UnsupportedOperationException();
}
@Override
public Uri insert(Uri uri, ContentValues initialValues) {
throw new UnsupportedOperationException();
}
@Override
public String getType(Uri uri) {
Log.d(TAG, "XXX: getType()");
switch (mUriMatcher.match(uri)) {
case SCREEN_NAMES:
Log.d(TAG, "XXX1: SCREEN_NAMES");
return "vnd.android.cursor.dir/vnd.test.screenname";
case SCREEN_NAME:
Log.d(TAG, "XXX2: SCREEN_NAME");
return "vnd.android.cursor.item/vnd.test.screenname";
default:
// any other kind of URL is illegal
throw new IllegalArgumentException("Unknown URL " + uri);
}
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sort) {
throw new UnsupportedOperationException();
}
}
正如您所看到的,我并不真正关心使用数据库后端,尽管在不久的将来添加可能会很有用。现在我只想要能够获取内容://com.bourke.test/screenname/ style URI,所以我的活动可以调用Twitter API来显示相应用户的信息。
任何有关崩溃原因的反馈或信息都会非常有用。
答案 0 :(得分:0)
从错误中我们可以假设您调用content://com.bourke.test/screenname/Arubin
,但是从您的代码看起来应该是content://com.bourke.test.provider/screenname/Arubin
...所以您应该在调用此ContentUri时添加.provider
或删除它来自public static final String AUTHORITY="...";