`

【Andorid】关于android.provider.CallLog-通话记录

阅读更多
Since: API Level 1

TAG: 通过addCall方法中的removeExpiredEntries()去限定CallLog最大信息量为500
private static void removeExpiredEntries(Context context) {
            final ContentResolver resolver = context.getContentResolver();
            resolver.delete(CONTENT_URI, "_id IN " +
                    "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER 
                    + " LIMIT -1 OFFSET 500)", null);
        }


新增:
TAG: 查询最后一次拨出的号码
Since: API Level 8
        /**
         * Query the call log database for the last dialed number.
         * @param context Used to get the content resolver.
         * @return The last phone number dialed (outgoing) or an empty
         * string if none exist yet.
         */
        public static String getLastOutgoingCall(Context context) {
            final ContentResolver resolver = context.getContentResolver();
            Cursor c = null;
            try {
                c = resolver.query(
                    CONTENT_URI,
                    new String[] {NUMBER},
                    TYPE + " = " + OUTGOING_TYPE,
                    null,
                    DEFAULT_SORT_ORDER + " LIMIT 1");
                if (c == null || !c.moveToFirst()) {
                    return "";
                }
                return c.getString(0);
            } finally {
                if (c != null) c.close();
            }
        }




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics