当前位置: 首页>>代码示例>>Java>>正文


Java ContentResolver.delete方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:25,代码来源:AbstractCalendarAccessor.java

示例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});
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:19,代码来源:AddressBookDBUtils.java

示例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;
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:19,代码来源:MediaStoreHack.java

示例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);
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:29,代码来源:LauncherModel.java

示例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);
        }
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:17,代码来源:SipProfileJson.java

示例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();
}
 
开发者ID:danlls,项目名称:Todule-android,代码行数:17,代码来源:ToduleListFragment.java

示例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;
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:13,代码来源:AbstractCalendarAccessor.java

示例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;
    }
}
 
开发者ID:paozhuanyinyu,项目名称:XPermission,代码行数:43,代码来源:PermissionsChecker.java

示例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;
}
 
开发者ID:jokermonn,项目名称:permissions4m,代码行数:21,代码来源:PermissionsChecker.java

示例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);
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:14,代码来源:PlaylistHelper.java

示例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);

}
 
开发者ID:mdnafiskhan,项目名称:Mp3Player,代码行数:11,代码来源:songDetailloader.java

示例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)
    });
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:9,代码来源:TimberUtils.java

示例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();
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:20,代码来源:MusicUtils.java

示例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 });
    }
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:16,代码来源:UserDictionarySettings.java

示例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;

}
 
开发者ID:kartik2112,项目名称:TDList,代码行数:32,代码来源:RealCalendarModule.java


注:本文中的android.content.ContentResolver.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。