下面列出了android.content.ContentProviderClient#getType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets the content URI builder for a specified type.
*
* Supported types include QUERY_PATH_DICT_INFO, which takes the locale as
* the extraPath argument, and QUERY_PATH_DATAFILE, which needs a wordlist ID
* as the extraPath argument.
*
* @param clientId the clientId to use
* @param contentProviderClient the instance of content provider client
* @param queryPathType the path element encoding the type
* @param extraPath optional extra argument for this type (typically word list id)
* @return a builder that can build the URI for the best supported protocol version
* @throws RemoteException if the client can't be contacted
*/
private static Uri.Builder getContentUriBuilderForType(final String clientId,
final ContentProviderClient contentProviderClient, final String queryPathType,
final String extraPath) throws RemoteException {
// Check whether protocol v2 is supported by building a v2 URI and calling getType()
// on it. If this returns null, v2 is not supported.
final Uri.Builder uriV2Builder = getProviderUriBuilder(clientId);
uriV2Builder.appendPath(queryPathType);
uriV2Builder.appendPath(extraPath);
uriV2Builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL,
QUERY_PARAMETER_PROTOCOL_VALUE);
if (null != contentProviderClient.getType(uriV2Builder.build())) return uriV2Builder;
// Protocol v2 is not supported, so create and return the protocol v1 uri.
return getProviderUriBuilder(extraPath);
}
/**
* Gets the content URI builder for a specified type.
*
* Supported types include QUERY_PATH_DICT_INFO, which takes the locale as
* the extraPath argument, and QUERY_PATH_DATAFILE, which needs a wordlist ID
* as the extraPath argument.
*
* @param clientId the clientId to use
* @param contentProviderClient the instance of content provider client
* @param queryPathType the path element encoding the type
* @param extraPath optional extra argument for this type (typically word list id)
* @return a builder that can build the URI for the best supported protocol version
* @throws RemoteException if the client can't be contacted
*/
private static Uri.Builder getContentUriBuilderForType(final String clientId,
final ContentProviderClient contentProviderClient, final String queryPathType,
final String extraPath) throws RemoteException {
// Check whether protocol v2 is supported by building a v2 URI and calling getType()
// on it. If this returns null, v2 is not supported.
final Uri.Builder uriV2Builder = getProviderUriBuilder(clientId);
uriV2Builder.appendPath(queryPathType);
uriV2Builder.appendPath(extraPath);
uriV2Builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL,
QUERY_PARAMETER_PROTOCOL_VALUE);
if (null != contentProviderClient.getType(uriV2Builder.build())) return uriV2Builder;
// Protocol v2 is not supported, so create and return the protocol v1 uri.
return getProviderUriBuilder(extraPath);
}
/**
* Gets the content URI builder for a specified type.
*
* Supported types include QUERY_PATH_DICT_INFO, which takes the locale as
* the extraPath argument, and QUERY_PATH_DATAFILE, which needs a wordlist ID
* as the extraPath argument.
*
* @param clientId the clientId to use
* @param contentProviderClient the instance of content provider client
* @param queryPathType the path element encoding the type
* @param extraPath optional extra argument for this type (typically word list id)
* @return a builder that can build the URI for the best supported protocol version
* @throws RemoteException if the client can't be contacted
*/
private static Uri.Builder getContentUriBuilderForType(final Context context, final String clientId,
final ContentProviderClient contentProviderClient, final String queryPathType,
final String extraPath) throws RemoteException {
// Check whether protocol v2 is supported by building a v2 URI and calling getType()
// on it. If this returns null, v2 is not supported.
final Uri.Builder uriV2Builder = getProviderUriBuilder(context, clientId);
uriV2Builder.appendPath(queryPathType);
uriV2Builder.appendPath(extraPath);
uriV2Builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL,
QUERY_PARAMETER_PROTOCOL_VALUE);
if (null != contentProviderClient.getType(uriV2Builder.build())) return uriV2Builder;
// Protocol v2 is not supported, so create and return the protocol v1 uri.
return getProviderUriBuilder(context, extraPath);
}
@Override
public String getType(Uri uri) {
String targetAuthority = uri.getQueryParameter(Env.EXTRA_TARGET_AUTHORITY);
if (!TextUtils.isEmpty(targetAuthority) && !TextUtils.equals(targetAuthority, uri.getAuthority())) {
ContentProviderClient client = getContentProviderClient(targetAuthority);
try {
return client.getType(buildNewUri(uri, targetAuthority));
} catch (RemoteException e) {
handleExpcetion(e);
}
}
return null;
}
/**
* Gets the content URI builder for a specified type.
*
* Supported types include QUERY_PATH_DICT_INFO, which takes the locale as
* the extraPath argument, and QUERY_PATH_DATAFILE, which needs a wordlist ID
* as the extraPath argument.
*
* @param clientId the clientId to use
* @param contentProviderClient the instance of content provider client
* @param queryPathType the path element encoding the type
* @param extraPath optional extra argument for this type (typically word list id)
* @return a builder that can build the URI for the best supported protocol version
* @throws RemoteException if the client can't be contacted
*/
private static Uri.Builder getContentUriBuilderForType(final String clientId,
final ContentProviderClient contentProviderClient, final String queryPathType,
final String extraPath) throws RemoteException {
// Check whether protocol v2 is supported by building a v2 URI and calling getType()
// on it. If this returns null, v2 is not supported.
final Uri.Builder uriV2Builder = getProviderUriBuilder(clientId);
uriV2Builder.appendPath(queryPathType);
uriV2Builder.appendPath(extraPath);
uriV2Builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL,
QUERY_PARAMETER_PROTOCOL_VALUE);
if (null != contentProviderClient.getType(uriV2Builder.build())) return uriV2Builder;
// Protocol v2 is not supported, so create and return the protocol v1 uri.
return getProviderUriBuilder(extraPath);
}