本文整理汇总了Java中android.content.ContentValues.getAsString方法的典型用法代码示例。如果您正苦于以下问题:Java ContentValues.getAsString方法的具体用法?Java ContentValues.getAsString怎么用?Java ContentValues.getAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentValues
的用法示例。
在下文中一共展示了ContentValues.getAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: install
import android.content.ContentValues; //导入方法依赖的package包/类
private int install(ContentValues cv) {
if (cv == null) {
return 0;
}
String pit = cv.getAsString(KEY_PLUGIN_INFO);
if (TextUtils.isEmpty(pit)) {
return 0;
}
PluginInfo pi = PluginInfo.parseFromJsonText(pit);
// 开始加载ClassLoader
ClassLoader cl = PluginMgrFacade.getLocal().loadPluginClassLoader(pi);
if (cl != null) {
return 1;
} else {
return 0;
}
}
示例2: checkFileUriDestination
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Check that the file URI provided for DESTINATION_FILE_URI is valid.
*/
private void checkFileUriDestination(ContentValues values) {
String fileUri = values.getAsString(Downloads.Impl.COLUMN_FILE_NAME_HINT);
if (fileUri == null) {
throw new IllegalArgumentException(
"DESTINATION_FILE_URI must include a file URI under COLUMN_FILE_NAME_HINT");
}
Uri uri = Uri.parse(fileUri);
String scheme = uri.getScheme();
if (scheme == null || !scheme.equals("file")) {
throw new IllegalArgumentException("Not a file URI: " + uri);
}
final String path = uri.getPath();
if (path == null) {
throw new IllegalArgumentException("Invalid file URI: " + uri);
}
final File file = new File(path);
/* if (!PermissionChecker.writeExternalStoragePermission(getContext())) {
throw new SecurityException("Unsupported path " + file);
}*/
}
示例3: insertBus
import android.content.ContentValues; //导入方法依赖的package包/类
private Uri insertBus(Uri uri, ContentValues values) {
// Check that the name is not null.
String number = values.getAsString(BusContract.BusEntry.COLUMN_BUS_STOP_NUMBER);
if (number == null) {
throw new IllegalArgumentException("Bus requires a number");
}
SQLiteDatabase database = mDbHelper.getWritableDatabase();
// Insert the new bus with the give values.
long id = database.insert(BusContract.BusEntry.TABLE_NAME, null, values);
// If the ID is -1, then the insertion failed. Log an error and return null.
if (id == -1) {
Log.e(LOG_TAG, "Failed to insert row for " + uri);
return null;
}
// Notify all listeners that the data has changed for the bus content URI.
getContext().getContentResolver().notifyChange(uri, null);
// Return the new URI with the ID (of the newly inserted row) appended at the end.
return ContentUris.withAppendedId(uri, id);
}
示例4: insertCurrentRook
import android.content.ContentValues; //导入方法依赖的package包/类
private Uri insertCurrentRook(SQLiteDatabase db, Uri uri, ContentValues contentValues) {
String repoUrl = contentValues.getAsString(ProviderContract.CurrentRooks.Param.REPO_URL);
String rookUrl = contentValues.getAsString(ProviderContract.CurrentRooks.Param.ROOK_URL);
String revision = contentValues.getAsString(ProviderContract.CurrentRooks.Param.ROOK_REVISION);
long mtime = contentValues.getAsLong(ProviderContract.CurrentRooks.Param.ROOK_MTIME);
long repoUrlId = getOrInsertRepoUrl(db, repoUrl);
long rookUrlId = DbRookUrl.getOrInsert(db, rookUrl);
long rookId = getOrInsertRook(db, rookUrlId, repoUrlId);
long versionedRookId = getOrInsertVersionedRook(db, rookId, revision, mtime);
ContentValues values = new ContentValues();
values.put(DbCurrentVersionedRook.VERSIONED_ROOK_ID, versionedRookId);
long id = db.insert(DbCurrentVersionedRook.TABLE, null, values);
return ContentUris.withAppendedId(uri, id);
}
示例5: insert
import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
boolean saveAntiFeatures = false;
String[] antiFeatures = null;
if (values.containsKey(Cols.AntiFeatures.ANTI_FEATURES)) {
saveAntiFeatures = true;
String antiFeaturesString = values.getAsString(Cols.AntiFeatures.ANTI_FEATURES);
antiFeatures = Utils.parseCommaSeparatedString(antiFeaturesString);
values.remove(Cols.AntiFeatures.ANTI_FEATURES);
}
removeFieldsFromOtherTables(values);
validateFields(Cols.ALL, values);
long newId = db().insertOrThrow(getTableName(), null, values);
if (saveAntiFeatures) {
ensureAntiFeatures(antiFeatures, newId);
}
if (!isApplyingBatch()) {
getContext().getContentResolver().notifyChange(uri, null);
}
return getApkUri(newId);
}
示例6: bookSavedToRepo
import android.content.ContentValues; //导入方法依赖的package包/类
private Uri bookSavedToRepo(SQLiteDatabase db, Uri uri, ContentValues values) {
long bookId = Long.parseLong(uri.getPathSegments().get(1));
String repoUrl = values.getAsString(ProviderContract.BooksIdSaved.Param.REPO_URL);
String rookUrl = values.getAsString(ProviderContract.BooksIdSaved.Param.ROOK_URL);
String rookRevision = values.getAsString(ProviderContract.BooksIdSaved.Param.ROOK_REVISION);
long rookMtime = values.getAsLong(ProviderContract.BooksIdSaved.Param.ROOK_MTIME);
long repoId = getOrInsertRepoUrl(db, repoUrl);
long rookUrlId = DbRookUrl.getOrInsert(db, rookUrl);
long rookId = getOrInsertRook(db, rookUrlId, repoId);
long versionedRookId = getOrInsertVersionedRook(db, rookId, rookRevision, rookMtime);
updateOrInsertBookLink(db, bookId, repoUrl, rookUrl);
updateOrInsertBookSync(db, bookId, repoUrl, rookUrl, rookRevision, rookMtime);
db.rawQuery(DELETE_CURRENT_VERSIONED_ROOKS_FOR_ROOK_ID, new String[] { String.valueOf(rookId) });
ContentValues v = new ContentValues();
v.put(DbCurrentVersionedRook.VERSIONED_ROOK_ID, versionedRookId);
db.insert(DbCurrentVersionedRook.TABLE, null, v);
return ContentUris.withAppendedId(ProviderContract.Books.ContentUri.books(), bookId);
}
示例7: addCallLog
import android.content.ContentValues; //导入方法依赖的package包/类
public static void addCallLog(Context context, ContentValues values, ContentValues extraValues) {
ContentResolver contentResolver = context.getContentResolver();
Uri result = null;
try {
result = contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
}catch(IllegalArgumentException e) {
Log.w(THIS_FILE, "Cannot insert call log entry. Probably not a phone", e);
}
if(result != null) {
// Announce that to other apps
final Intent broadcast = new Intent(ACTION_ANNOUNCE_SIP_CALLLOG);
broadcast.putExtra(EXTRA_CALL_LOG_URI, result.toString());
String provider = extraValues.getAsString(EXTRA_SIP_PROVIDER);
if(provider != null) {
broadcast.putExtra(EXTRA_SIP_PROVIDER, provider);
}
context.sendBroadcast(broadcast);
}
}
示例8: checkFileUriDestination
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Check that the file URI provided for DESTINATION_FILE_URI is valid.
*/
private void checkFileUriDestination(ContentValues values) {
String fileUri = values.getAsString(Downloads.Impl.COLUMN_FILE_NAME_HINT);
if (fileUri == null) {
throw new IllegalArgumentException(
"DESTINATION_FILE_URI must include a file URI under COLUMN_FILE_NAME_HINT");
}
Uri uri = Uri.parse(fileUri);
String scheme = uri.getScheme();
if (scheme == null || !scheme.equals("file")) {
throw new IllegalArgumentException("Not a file URI: " + uri);
}
final String path = uri.getPath();
if (path == null) {
throw new IllegalArgumentException("Invalid file URI: " + uri);
}
final File file = new File(path);
if (!PermissionChecker.writeExternalStoragePermission(getContext())) {
throw new SecurityException("Unsupported path " + file);
}
}
示例9: handleTitle
import android.content.ContentValues; //导入方法依赖的package包/类
private static void handleTitle(ContentValues cv, String path) {
String title = cv.getAsString(MediaColumns.TITLE);
if (TextUtils.isEmpty(title)) {
title = new File (path).getName();
int idx = title.lastIndexOf('.');
if (idx > 0) {
title = title.substring(0, idx);
}
cv.put(MediaColumns.TITLE, title);
}
String titleKey = Audio.keyFor(title);
cv.put(AudioColumns.TITLE_KEY, titleKey);
}
示例10: insert
import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
// Don't let people specify arbitrary priorities. Instead, we are responsible
// for making sure that newly created repositories by default have the highest priority.
values.put(Cols.PRIORITY, getMaxPriority() + 1);
if (!values.containsKey(Cols.ADDRESS)) {
throw new UnsupportedOperationException("Cannot add repo without an address.");
}
// The following fields have NOT NULL constraints in the DB, so need
// to be present.
if (!values.containsKey(Cols.IN_USE)) {
values.put(Cols.IN_USE, 1);
}
if (!values.containsKey(Cols.MAX_AGE)) {
values.put(Cols.MAX_AGE, 0);
}
if (!values.containsKey(Cols.VERSION)) {
values.put(Cols.VERSION, 0);
}
if (!values.containsKey(Cols.NAME) || values.get(Cols.NAME) == null) {
final String address = values.getAsString(Cols.ADDRESS);
values.put(Cols.NAME, Repo.addressToName(address));
}
long id = db().insertOrThrow(getTableName(), null, values);
Utils.debugLog(TAG, "Inserted repo. Notifying provider change: '" + uri + "'.");
getContext().getContentResolver().notifyChange(uri, null);
return getContentUri(id);
}
示例11: insertPet
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Helper method to add Pet to the database.
* This method is called inside the INSERT method
*
* @param uri
* @param values
* @return
*/
private Uri insertPet(Uri uri, ContentValues values) {
// sanity check the values
String name = values.getAsString(PetEntry.COLUMN_NAME);
Integer gender = values.getAsInteger(PetEntry.COLUMN_GENDER);
Integer weight = values.getAsInteger(PetEntry.COLUMN_WEIGHT);
// check name
if (name.isEmpty()) {
throw new IllegalArgumentException("Pet requires a name");
}
// check gender
if (gender == null || !isValidGender(gender)) {
throw new IllegalArgumentException("Pet requires valid gender");
}
// check weight
if ((weight != null) && (weight < 0)) {
throw new IllegalArgumentException("Pet requires valid weight");
}
// access the database in write mode
SQLiteDatabase database = mPetDbHelper.getWritableDatabase();
// insert the pet to database
long id = database.insert(PetEntry.TABLE_NAME, null, values);
if (id == -1) {
Log.e(LOG_TAG, "Failed to insert row for " + uri);
return null;
}
// Notify all listeners that the data changed
getContext().getContentResolver().notifyChange(uri, null);
return ContentUris.withAppendedId(uri, id);
}
示例12: performUpdate
import android.content.ContentValues; //导入方法依赖的package包/类
private void performUpdate(ContentValues values) {
StringBuilder where = new StringBuilder();
where.append(DatabaseContract.TableTransactions.COL_ID)
.append(" = ?");
String id = values.getAsString(DatabaseContract.TableTransactions.COL_ID);
values.remove(DatabaseContract.TableTransactions.COL_ID);
if (getContentResolver().update(DatabaseContract.CONTENT_URI, values, where.toString(), new String[]{id}) > 0) {
Log.d(TAG, "Updated new Transaction");
} else {
Log.w(TAG, "Error inserting new Transaction");
}
}
示例13: copyString
import android.content.ContentValues; //导入方法依赖的package包/类
private static final void copyString(String key, ContentValues from, ContentValues to) {
String s = from.getAsString(key);
if (s != null) {
to.put(key, s);
}
}
示例14: endFile
import android.content.ContentValues; //导入方法依赖的package包/类
private Uri endFile(FileCacheEntry entry) throws RemoteException {
Uri tableUri;
boolean isVideo = MediaFile.isVideoFileType(mFileType) && mWidth > 0 && mHeight > 0;
if (isVideo) {
tableUri = Video.Media.CONTENT_URI;
} else {
return null;
}
entry.mTableUri = tableUri;
ContentValues values = toValues();
String title = values.getAsString(MediaStore.MediaColumns.TITLE);
if (TextUtils.isEmpty(title)) {
title = values.getAsString(MediaStore.MediaColumns.DATA);
int lastSlash = title.lastIndexOf('/');
if (lastSlash >= 0) {
lastSlash++;
if (lastSlash < title.length())
title = title.substring(lastSlash);
}
int lastDot = title.lastIndexOf('.');
if (lastDot > 0)
title = title.substring(0, lastDot);
values.put(MediaStore.MediaColumns.TITLE, title);
}
long rowId = entry.mRowId;
Uri result = null;
if (rowId == 0) {
result = mProvider.insert(tableUri, values);
if (result != null) {
rowId = ContentUris.parseId(result);
entry.mRowId = rowId;
}
} else {
result = ContentUris.withAppendedId(tableUri, rowId);
mProvider.update(result, values, null, null);
}
return result;
}
示例15: showDictionaryAvailableNotification
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Shows the notification that informs the user a dictionary is available.
*
* When this notification is clicked, the dialog for downloading the dictionary
* over a metered connection is shown.
*/
private static void showDictionaryAvailableNotification(final Context context,
final String clientId, final ContentValues installCandidate) {
final String localeString = installCandidate.getAsString(MetadataDbHelper.LOCALE_COLUMN);
final Intent intent = new Intent();
intent.setClass(context, DownloadOverMeteredDialog.class);
intent.putExtra(DownloadOverMeteredDialog.CLIENT_ID_KEY, clientId);
intent.putExtra(DownloadOverMeteredDialog.WORDLIST_TO_DOWNLOAD_KEY,
installCandidate.getAsString(MetadataDbHelper.WORDLISTID_COLUMN));
intent.putExtra(DownloadOverMeteredDialog.SIZE_KEY,
installCandidate.getAsInteger(MetadataDbHelper.FILESIZE_COLUMN));
intent.putExtra(DownloadOverMeteredDialog.LOCALE_KEY, localeString);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
final PendingIntent notificationIntent = PendingIntent.getActivity(context,
0 /* requestCode */, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
final NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// None of those are expected to happen, but just in case...
if (null == notificationIntent || null == notificationManager) return;
final String language = (null == localeString) ? ""
: LocaleUtils.constructLocaleFromString(localeString).getDisplayLanguage();
final String titleFormat = context.getString(R.string.dict_available_notification_title);
final String notificationTitle = String.format(titleFormat, language);
final Notification.Builder builder = new Notification.Builder(context)
.setAutoCancel(true)
.setContentIntent(notificationIntent)
.setContentTitle(notificationTitle)
.setContentText(context.getString(R.string.dict_available_notification_description))
.setTicker(notificationTitle)
.setOngoing(false)
.setOnlyAlertOnce(true)
.setSmallIcon(R.drawable.ic_notify_dictionary);
NotificationCompatUtils.setColor(builder,
context.getResources().getColor(R.color.notification_accent_color));
NotificationCompatUtils.setPriorityToLow(builder);
NotificationCompatUtils.setVisibilityToSecret(builder);
NotificationCompatUtils.setCategoryToRecommendation(builder);
final Notification notification = NotificationCompatUtils.build(builder);
notificationManager.notify(DICT_AVAILABLE_NOTIFICATION_ID, notification);
}