本文整理汇总了Java中android.content.ContentResolver.delete方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.delete方法的具体用法?Java ContentResolver.delete怎么用?Java ContentResolver.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteCalendar
import android.content.ContentResolver; //导入方法依赖的package包/类
@SuppressWarnings("MissingPermission") // already requested in calling method
public void deleteCalendar(String calendarName) {
try {
Uri evuri = CalendarContract.Calendars.CONTENT_URI;
final ContentResolver contentResolver = cordova.getActivity().getContentResolver();
Cursor result = contentResolver.query(evuri, new String[]{CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}, null, null, null);
if (result != null) {
while (result.moveToNext()) {
if (result.getString(1).equals(calendarName) || result.getString(2).equals(calendarName)) {
long calid = result.getLong(0);
Uri deleteUri = ContentUris.withAppendedId(evuri, calid);
contentResolver.delete(deleteUri, null, null);
}
}
result.close();
}
// also delete previously crashing calendars, see https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/issues/241
deleteCrashingCalendars(contentResolver);
} catch (Throwable t) {
System.err.println(t.getMessage());
t.printStackTrace();
}
}
示例2: deleteAddress
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* 删除pid的通讯录
*
* @param resolver
* @param openId
* @param pid
*/
public static void deleteAddress(ContentResolver resolver, String openId, String pid)
{
Uri uri = AddressInfoTable.CONTENT_URI;
if (pid == null || pid.equals(""))
{
pid = "root";
}
resolver.delete(uri, AddressInfoTable.OPENID + "=? and " + AddressInfoTable.MPID + " =?", new String[] {openId,
pid});
}
示例3: getInputStream
import android.content.ContentResolver; //导入方法依赖的package包/类
public InputStream getInputStream(final Context context, final File file, final long size) {
try {
final String where = MediaStore.MediaColumns.DATA + "=?";
final String[] selectionArgs = new String[]{
file.getAbsolutePath()
};
final ContentResolver contentResolver = context.getContentResolver();
final Uri filesUri = MediaStore.Files.getContentUri("external");
contentResolver.delete(filesUri, where, selectionArgs);
final ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(MediaStore.MediaColumns.SIZE, size);
final Uri uri = contentResolver.insert(filesUri, values);
return contentResolver.openInputStream(uri);
} catch (final Throwable t) {
return null;
}
}
示例4: deleteFolderAndContentsFromDatabase
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Remove the specified folder and all its contents from the database.
*/
public static void deleteFolderAndContentsFromDatabase(Context context, final FolderInfo info) {
final ContentResolver cr = context.getContentResolver();
Runnable r = new Runnable() {
public void run() {
cr.delete(LauncherSettings.Favorites.getContentUri(info.id), null, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
sBgItemsIdMap.remove(info.id);
sBgFolders.remove(info.id);
sBgWorkspaceItems.remove(info);
}
cr.delete(LauncherSettings.Favorites.CONTENT_URI,
LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
for (ItemInfo childInfo : info.contents) {
sBgItemsIdMap.remove(childInfo.id);
}
}
}
};
runOnWorkerThread(r);
}
示例5: restoreSipAccounts
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void restoreSipAccounts(Context ctxt, JSONArray accounts) {
ContentResolver cr = ctxt.getContentResolver();
// Clear old existing accounts
cr.delete(SipProfile.ACCOUNT_URI, "1", null);
cr.delete(SipManager.FILTER_URI, "1", null);
// Add each accounts
for (int i = 0; i < accounts.length(); i++) {
try {
JSONObject account = accounts.getJSONObject(i);
restoreSipProfile(account, cr);
} catch (JSONException e) {
Log.e(THIS_FILE, "Unable to parse item " + i, e);
}
}
}
示例6: deleteSelectedItems
import android.content.ContentResolver; //导入方法依赖的package包/类
private void deleteSelectedItems(){
ContentResolver resolver = getContext().getContentResolver();
int size = selectedIds.size();
Long[] mArray = new Long[size];
for (int i = 0; i < size; i++) {
long id = selectedIds.keyAt(i);
mArray[i] = id;
}
final String select = TodoEntry._ID + " IN(" + constructPlaceholders(mArray.length)+ ")";
final String[] selectionArgs = new String[mArray.length];
for (int i =0; i< mArray.length; i++){
selectionArgs[i] = String.valueOf(mArray[i]);
}
int count = resolver.delete(TodoEntry.CONTENT_URI , select, selectionArgs);
Toast.makeText(myActivity, count + " " + getString(R.string.entry_deleted), Toast.LENGTH_SHORT).show();
}
示例7: deleteEvent
import android.content.ContentResolver; //导入方法依赖的package包/类
public boolean deleteEvent(Uri eventsUri, long startFrom, long startTo, String title, String location) {
ContentResolver resolver = this.cordova.getActivity().getApplicationContext().getContentResolver();
Event[] events = fetchEventInstances(null, title, location, "", startFrom, startTo);
int nrDeletedRecords = 0;
if (events != null) {
for (Event event : events) {
Uri eventUri = ContentUris.withAppendedId(eventsUri, Integer.parseInt(event.eventId));
nrDeletedRecords = resolver.delete(eventUri, null, null);
}
}
return nrDeletedRecords > 0;
}
示例8: checkWriteContacts
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* write and delete contacts info, {@link Manifest.permission#WRITE_CONTACTS}
* and we should get read contacts permission first.
*
* @param activity
* @return true if success
* @throws Exception
*/
private static boolean checkWriteContacts(Context activity) throws Exception {
if (checkReadContacts(activity)) {
// write some info
ContentValues values = new ContentValues();
ContentResolver contentResolver = activity.getContentResolver();
Uri rawContactUri = contentResolver.insert(ContactsContract.RawContacts
.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds
.StructuredName.CONTENT_ITEM_TYPE);
values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, TAG);
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, TAG_NUMBER);
contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);
// delete info
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = activity.getContentResolver();
Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Contacts.Data._ID},
"display_name=?", new String[]{TAG}, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(0);
resolver.delete(uri, "display_name=?", new String[]{TAG});
uri = Uri.parse("content://com.android.contacts/data");
resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""});
}
cursor.close();
}
return true;
} else {
return false;
}
}
示例9: checkWriteCallLog
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* write or delete call log, {@link android.Manifest.permission#WRITE_CALL_LOG}
*
* @param activity
* @return true if success
*/
private static boolean checkWriteCallLog(Activity activity) throws Exception {
ContentResolver contentResolver = activity.getContentResolver();
ContentValues content = new ContentValues();
content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
content.put(CallLog.Calls.NUMBER, TAG_NUMBER);
content.put(CallLog.Calls.DATE, 20140808);
content.put(CallLog.Calls.NEW, "0");
contentResolver.insert(Uri.parse("content://call_log/calls"), content);
contentResolver.delete(Uri.parse("content://call_log/calls"), "number = ?", new
String[]{TAG_NUMBER});
return true;
}
示例10: deletePlaylist
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Delete playlist
*
* @param context
* @param selectedplaylist
*/
public static void deletePlaylist(Context context, String selectedplaylist) {
String playlistid = getPlayListId(context, selectedplaylist);
ContentResolver resolver = context.getContentResolver();
String where = MediaStore.Audio.Playlists._ID + "=?";
String[] whereVal = {playlistid};
resolver.delete(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, where, whereVal);
}
示例11: deleteSong
import android.content.ContentResolver; //导入方法依赖的package包/类
public void deleteSong(Context context, int position) {
cursor.moveToPosition(position);
Log.d("delteing song",""+cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)));
int _id =cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
Uri uri;
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
ContentResolver resolver = context.getContentResolver();
resolver.delete(uri, MediaStore.Audio.Media._ID + " = " + _id, null);
}
示例12: removeFromPlaylist
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void removeFromPlaylist(final Context context, final long id,
final long playlistId) {
final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
final ContentResolver resolver = context.getContentResolver();
resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + " = ? ", new String[]{
Long.toString(id)
});
}
示例13: removeFromPlaylist
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Removes a single track from a given playlist
*
* @param context The {@link Context} to use.
* @param id The id of the song to remove.
* @param playlistId The id of the playlist being removed from.
*/
public static void removeFromPlaylist(final Context context, final long id,
final long playlistId) {
final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
final ContentResolver resolver = context.getContentResolver();
resolver.delete(uri, Playlists.Members.AUDIO_ID + " = ? ", new String[]{
Long.toString(id)
});
final String message = context.getResources().getQuantityString(
R.plurals.num_tracksfromplaylist, 1, 1);
Toast.makeText((Activity) context, message, Toast.LENGTH_SHORT).show();
playlistChanged();
}
示例14: deleteWord
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void deleteWord(final String word, final String shortcut,
final ContentResolver resolver) {
if (!IS_SHORTCUT_API_SUPPORTED) {
resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_SHORTCUT_UNSUPPORTED,
new String[] { word });
} else if (TextUtils.isEmpty(shortcut)) {
resolver.delete(
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT,
new String[] { word });
} else {
resolver.delete(
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT,
new String[] { word, shortcut });
}
}
示例15: deleteEvent
import android.content.ContentResolver; //导入方法依赖的package包/类
public static int deleteEvent(ContentResolver resolver,String eventTitle){
Uri eventsUri;
Cursor cursor;
int noOfEventsDeleted=0;
/**
* Following are the columns that can be used in the selection part
* String[] COLS={"calendar_id", "title", "description", "dtstart", "dtend","eventTimezone", "eventLocation"};
*/
int osVersion = android.os.Build.VERSION.SDK_INT;
if (osVersion <= 7) { //up-to Android 2.1
eventsUri = Uri.parse("content://calendar/events");
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars._id=" + CALENDAR_ID + " and Calendars.title='"+eventTitle+"' and description='"+description+"'" , null, null);
} else { //8 is Android 2.2 (Froyo) (http://developer.android.com/reference/android/os/Build.VERSION_CODES.html)
eventsUri = Uri.parse("content://com.android.calendar/events");
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + CALENDAR_ID + " and title='"+eventTitle+"' and description='"+description+"'" , null, null);
}
while(cursor.moveToNext()) {
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
noOfEventsDeleted+=resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
Log.d("RealCalendarModule","title="+eventTitle+", eventId"+eventId);
}
cursor.close();
return noOfEventsDeleted;
}