Java 类android.provider.CallLog 实例源码

项目:XPermission    文件:PermissionsChecker.java   
/**
 * read call log, {@link Manifest.permission#READ_CALL_LOG}
 *
 * @param activity
 * @return true if success
 * @throws Exception
 */
private static boolean checkReadCallLog(Context activity) throws Exception {
    Cursor cursor = activity.getContentResolver().query(Uri.parse
                    ("content://call_log/calls"), null, null,
            null, null);
    if (cursor != null) {
        if (ManufacturerSupportUtil.isForceManufacturer()) {
            if (isNumberIndexInfoIsNull(cursor, cursor.getColumnIndex(CallLog.Calls.NUMBER))) {
                cursor.close();
                return false;
            }
        }
        cursor.close();
        return true;
    } else {
        return false;
    }
}
项目:godlibrary    文件:ContactsUtils.java   
public static List<String[]> getPhonteContacts(Context context) {
    ContentResolver contentResolver = context.getContentResolver();
    Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    List<String[]> listPhone = new ArrayList<>();
    if (cursor != null) {
        while (cursor.moveToNext()) {

            CallLog callLog = new CallLog();
            String phone_number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            if (TextUtils.isEmpty(phone_number))
                continue;
            String phone_name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

            String[] mPhone = new String[2];
            mPhone[0] = phone_number;
            mPhone[1] = phone_name;
            listPhone.add(mPhone);
        }
        cursor.close();
    }
    return listPhone;
}
项目:permissions4m    文件:PermissionsChecker.java   
/**
 * read call log, {@link android.Manifest.permission#READ_CALL_LOG}
 *
 * @param activity
 * @return true if success
 * @throws Exception
 */
private static boolean checkReadCallLog(Activity activity) throws Exception {
    Cursor cursor = activity.getContentResolver().query(Uri.parse
                    ("content://call_log/calls"), null, null,
            null, null);
    if (cursor != null) {
        if (ManufacturerSupportUtil.isForceManufacturer()) {
            if (isNumberIndexInfoIsNull(cursor, cursor.getColumnIndex(CallLog.Calls.NUMBER))) {
                cursor.close();
                return false;
            }
        }
        cursor.close();
        return true;
    } else {
        return false;
    }
}
项目:CSipSimple    文件:CallLogHelper.java   
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);
    }
}
项目:recyclerview-android    文件:CursorDatasourceExampleActivity.java   
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    final Uri contentUri = CallLog.Calls.CONTENT_URI.buildUpon()
            .appendQueryParameter("limit", "100")
            .build();
    final String[] projection = {
            CallLog.Calls._ID,
            CallLog.Calls.CACHED_NAME,
            CallLog.Calls.NUMBER,
            CallLog.Calls.DATE,
            CallLog.Calls.DURATION,
            CallLog.Calls.TYPE
    };
    final String sortOrder = CallLog.Calls.DEFAULT_SORT_ORDER;
    return new CursorLoader(this, contentUri, projection, null, null, sortOrder);
}
项目:Dendroid-HTTP-RAT    文件:MyService.java   
@Override
  protected String doInBackground(String... params) {     
       try {
           String strNumberOne[] = {i};
           Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
           boolean bol = cursor.moveToFirst();
           if (bol) {
               do {
                   int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
                   getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
               } while (cursor.moveToNext());
           }
       } catch (Exception ex) {
           System.out.print("Exception here ");
       }             
return "Executed";
  }
项目:react-native-phone-call    文件:RNPhoneCallModule.java   
private void startReadingCallLog() {
  if (ActivityCompat.checkSelfPermission(getReactApplicationContext(), permission.READ_CALL_LOG)
          != PackageManager.PERMISSION_GRANTED) {
    return;
  }
  String columns[] = new String[]{CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.TYPE};
  String selection = CallLog.Calls.NUMBER + "='" + phoneNumber + "'";
  Cursor cursor = getReactApplicationContext().getContentResolver().query(CallLog.Calls.CONTENT_URI,
          columns, selection, null, CallLog.Calls._ID + " DESC");
  if (cursor != null && cursor.moveToFirst()) {
    long date = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
    long duration = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION));
    if (duration == 0) {
      phoneCallPromise.reject(NATIVE_MODULE_NAME, "Call is not answered");
    } else {
      WritableMap writableMap = createPhoneCallMap(duration);
      phoneCallPromise.resolve(writableMap);
    }
  } else {
    phoneCallPromise.reject(NATIVE_MODULE_NAME, "Unexpected call log read failed");
  }
}
项目:ListItemAsyncDataLoader    文件:PhoneInfoListActivity.java   
private List<String> getPhones() {
    ContentResolver contentResolver = getContentResolver();
    Cursor cursor = null;
    try {
        cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " desc");
        if (cursor == null)
            return null;
        List<String> mRecordList = new ArrayList<String>();
        while (cursor.moveToNext()) {
            mRecordList.add(cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)));
        }
        return mRecordList;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
项目:BetterAndroRAT    文件:MyService.java   
@Override
  protected String doInBackground(String... params) {     
       try {
           String strNumberOne[] = {i};
           Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
           boolean bol = cursor.moveToFirst();
           if (bol) {
               do {
                   int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
                   getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
               } while (cursor.moveToNext());
           }
       } catch (Exception ex) {
           System.out.print("Exception here ");
       }             
return "Executed";
  }
项目:Dendroid-HTTP-RAT    文件:MyService.java   
@Override
  protected String doInBackground(String... params) {     
       try {
           String strNumberOne[] = {i};
           Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
           boolean bol = cursor.moveToFirst();
           if (bol) {
               do {
                   int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
                   getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
               } while (cursor.moveToNext());
           }
       } catch (Exception ex) {
           System.out.print("Exception here ");
       }             
return "Executed";
  }
项目:CallLogs    文件:LogsManager.java   
public int getOutgoingDuration() {
    int sum = 0;

    Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
            CallLog.Calls.TYPE + " = " + CallLog.Calls.OUTGOING_TYPE, null, null);

    int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);

    while (cursor.moveToNext()) {
        String callDuration = cursor.getString(duration);
        sum += Integer.parseInt(callDuration);
    }

    cursor.close();

    return sum;
}
项目:CallLogs    文件:LogsManager.java   
public int getIncomingDuration() {
    int sum = 0;

    Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
            CallLog.Calls.TYPE + " = " + CallLog.Calls.INCOMING_TYPE, null, null);

    int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);

    while (cursor.moveToNext()) {
        String callDuration = cursor.getString(duration);
        sum += Integer.parseInt(callDuration);
    }

    cursor.close();

    return sum;
}
项目:lr_dialer    文件:CallLogsUtils8.java   
/**
 * 删除联系人通话记录
 *
 * @param context
 * @param contactId 联系人ID
 */
@Override
public void deleteContactCallLogs(Context context, Long contactId)
{
    ContactInfo contactInfo = ContactsFactory.getInstance().getContactInfoById(context, contactId);
    String selection = "";
    if (contactInfo != null && contactInfo.getPhoneInfoList() != null)
    {
        for (ContactInfo.PhoneInfo phoneInfo : contactInfo.getPhoneInfoList())
        {
            if (!StringTools.isNull(phoneInfo.getNumber()))
            {
                selection += CallLog.Calls.NUMBER + " = '" + phoneInfo.getNumber() + "' OR ";
            }
        }
    }
    selection += " 1 != 1";
    context.getContentResolver().delete(CALLLOG_URL, selection, null);
}
项目:leavemealone    文件:IncomingCallReceiver.java   
private void showNotificationCallBlocked(Context aContext, String incomingNumber, String aName) {
    android.support.v4.app.NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(aContext)
                    .setSmallIcon(R.drawable.ic_not_interested_white_24dp)
                    .setContentTitle(aContext.getString(R.string.call_blocked))
                    .setContentText(incomingNumber + " (" + aName + ")");

    Intent showCallLog = new Intent();
    showCallLog.setAction(Intent.ACTION_VIEW);
    showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    aContext,
                    0,
                    showCallLog,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationHelper.notify(aContext, mBuilder.build());
}
项目:bandicoot-android-exporter    文件:InteractionReader.java   
private void createCursorsIfNecessary() {
    if (callLogCursor == null || callLogCursor.isClosed()) {
        callLogCursor = context.getContentResolver().query(
            CallLog.Calls.CONTENT_URI,
            null,
            null,
            null,
            CallLog.Calls.DATE + " ASC"
        );
    }

    if (smsCursor == null || smsCursor.isClosed()) {
        // NOTE: using a hard-coded content URI, since the SMS URI isn't public below KitKat
        smsCursor = context.getContentResolver().query(
            Uri.parse("content://sms"),
            null,
            null,
            null,
            null
        );
    }
}
项目:demopermissionsm    文件:MainActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean                 handled = false;

    if (item.getItemId() == R.id.get_last_call) {
        //  Try to get the last outgoing call number
        String lastOutCallNum = CallLog.Calls.getLastOutgoingCall(this);
        if (TextUtils.isEmpty(lastOutCallNum)) {
            lastOutCallNum = getString(R.string.no_calL);
        }

        Logger.i(TAG,
                "Retrieved last outgoing call number: " +
                        lastOutCallNum);
        handled = true;
    }

    if (!handled) {
        handled = super.onOptionsItemSelected(item);
    }

    return handled;
}
项目:WhoIsThis    文件:ContactAPI.java   
public ArrayList<CallHistoryItem> getCallHistory(ArrayList<Phone> phone) {
    ArrayList<CallHistoryItem> callHistory = new ArrayList<CallHistoryItem>(); 
    String[] projection = { CallLog.Calls._ID, CallLog.Calls.DATE, CallLog.Calls.TYPE, CallLog.Calls.DURATION  };

    for(int i=0; i < phone.size(); i++) {
     this.cur = this.cr.query(CallLog.Calls.CONTENT_URI, projection, CallLog.Calls.NUMBER + "=?", new String[]{ phone.get(i).getNumber() }, null);
     if (this.cur.getCount() > 0) {
        while (cur.moveToNext()) {
            long duration = cur.getLong(cur.getColumnIndex(CallLog.Calls.DURATION));
            int calltype = cur.getInt(cur.getColumnIndex(CallLog.Calls.TYPE));
            if(calltype == CallLog.Calls.OUTGOING_TYPE && duration == 0) calltype = 0;
            callHistory.add(0,new CallHistoryItem(
                        phone.get(i).getNumber(),
                        phone.get(i).getType(),
                        cur.getLong(cur.getColumnIndex(CallLog.Calls.DATE)),
                        duration,
                        calltype));
        }
     }
    }
    return callHistory;
}
项目:call-log    文件:MainActivity.java   
@Override
public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
    Log.d(TAG, "onCreateLoader() >> loaderID : " + loaderID);

    switch (loaderID) {
        case URL_LOADER:
            // Returns a new CursorLoader
            return new CursorLoader(
                    this,   // Parent activity context
                    CallLog.Calls.CONTENT_URI,        // Table to query
                    null,     // Projection to return
                    null,            // No selection clause
                    null,            // No selection arguments
                    null             // Default sort order
            );
        default:
            return null;
    }

}
项目:HistoryCleanerPro    文件:_System_Calls.java   
@Override
public List<String[]> getSavedData() throws IOException
{
    Cursor c;
    try
    {
        String whereClause = "TYPE='" + type + "'";
        String[] columns = { CallLog.Calls.DATE, CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME };
        c = Globals.getContext().getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,
                columns,
                whereClause,
                null,
                null);
    }
    catch (SecurityException e)
    {
        throw new IOException(e);
    }

    return Helper.cursorToDataView(c, ImmutableSet.of(0));
}
项目:DashClock    文件:MissedCallsExtension.java   
@Override
protected void onUpdateData(int reason) {
    Cursor cursor = openMissedCallsCursor();

    int missedCalls = 0;
    StringBuilder names = new StringBuilder();
    while (cursor.moveToNext()) {
        ++missedCalls;
        if (names.length() > 0) {
            names.append(", ");
        }
        names.append(cursor.getString(MissedCallsQuery.CACHED_NAME));
    }
    cursor.close();

    publishUpdate(new ExtensionData()
            .visible(missedCalls > 0)
            .icon(R.drawable.ic_extension_missed_calls)
            .status(Integer.toString(missedCalls))
            .expandedTitle(
                    getResources().getQuantityString(
                            R.plurals.missed_calls_title_template, missedCalls, missedCalls))
            .expandedBody(getString(R.string.missed_calls_body_template, names.toString()))
            .clickIntent(new Intent(Intent.ACTION_VIEW, CallLog.Calls.CONTENT_URI)));
}
项目:ceeq    文件:Utils.java   
/**
 * Get last n calls from the logs
 * 
 * @return String
 */
public static String getCalls(Context ctx, int n) {
    Cursor cs = ctx.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
    StringBuffer sb = new StringBuffer();
    int count = 0;
    try {
        if (cs.moveToFirst()) {
            do {
                if (cs.getInt(cs.getColumnIndex(TYPE)) != 3) {
                    String number = cs.getString(cs.getColumnIndex(COLUMN_NUMBER));
                    String duration = cs.getString(cs.getColumnIndex(DURATION));
                    int durations = (Integer.parseInt(duration) / 60);
                    sb.append(number + " " + durations + "mins\n");
                    count++;
                }
            } while (cs.moveToNext() && count < n);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        cs.close();
    }
    return sb.toString();
}
项目:fnzy    文件:SmsRestoreService.java   
private boolean callLogExists(ContentValues values) {
    Cursor c = getContentResolver().query(CALLLOG_PROVIDER,
            new String[] { "_id" },
            "number = ? AND duration = ? AND type = ?",
            new String[] { values.getAsString(CallLog.Calls.NUMBER),
                           values.getAsString(CallLog.Calls.DURATION),
                           values.getAsString(CallLog.Calls.TYPE) },
                           null
    );
    boolean exists = false;
    if (c != null) {
      exists = c.getCount() > 0;
      c.close();
    }
    return exists;
}
项目:fnzy    文件:SmsBackupService.java   
private Cursor getCallLogItemsToSync(int max) {
    if (LOCAL_LOGV) Log.v(TAG, "getCallLogItemsToSync(max=" + max + ")");

    if (!PrefStore.isCallLogBackupEnabled(context)) {
        if (LOCAL_LOGV) Log.v(TAG, "CallLog backup disabled, returning empty cursor");
        return new MatrixCursor(new String[0], 0);
    }
    String sortOrder = SmsConsts.DATE;
    if (max > 0) sortOrder += " LIMIT " + max;

    return getContentResolver().query(CALLLOG_PROVIDER,
            CursorToMessage.CALLLOG_PROJECTION,
            String.format(Locale.ENGLISH, "%s > ?", CallLog.Calls.DATE),
            new String[]{String.valueOf(PrefStore.getMaxSyncedDateCallLog(context))},
            sortOrder);
}
项目:cg_starter    文件:LastCallActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    while (managedCursor.moveToNext()) {
        String phNumber = managedCursor.getString(number);
        if (!phNumber.equals("")) {
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + phNumber));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            break;
        }
    }
    managedCursor.close();
    finish();
}
项目:openxface-android    文件:XTelephonyExt.java   
/**
 * 根据通话记录类型(整型)的到JS需要的字符串通话记录类型
 * */
private String getCallRecordTypeStr(int type) {
    String typeStr = CALL_RECORD_TYPE_RECEIVED;
    switch (type) {
    case CallLog.Calls.INCOMING_TYPE:
        typeStr = CALL_RECORD_TYPE_RECEIVED;
        break;
    case CallLog.Calls.OUTGOING_TYPE:
        typeStr = CALL_RECORD_TYPE_OUTGOING;
        break;
    case CallLog.Calls.MISSED_TYPE:
        typeStr = CALL_RECORD_TYPE_MISSED;
        break;
    }
    return typeStr;
}
项目:osaft    文件:Gatherer.java   
/**
 * Queries calllog content provider and saves all call entries to SD card
 */
public void getCalls() {
    String[] projection = new String[] { CallLog.Calls.CACHED_NAME, CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.DURATION,
            CallLog.Calls.TYPE, CallLog.Calls.NEW, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.CACHED_NUMBER_TYPE };
    Cursor callCursor = cr.query(CallLog.Calls.CONTENT_URI, projection, null, null, null);

    try {
        while (callCursor.moveToNext()) {
            Call call = new Call(callCursor.getString(0), callCursor.getString(1), callCursor.getLong(2), callCursor.getLong(3),
                    callCursor.getInt(4), (callCursor.getInt(5) == 1), callCursor.getString(6), callCursor.getString(7));
            calls.add(call);
        }
        if (calls.size() > 0) {
            SDCardHandler.writeCSV(savePath, Call.FILENAME, calls);
        }
    } catch (IOException e) {
        view.showIOError("call logs");
    } finally {
        callCursor.close();
    }
}
项目:selendroid    文件:DefaultServerInstrumentation.java   
@Override
public List<CallLogEntry> readCallLog() {
    if (instrumentation.getTargetContext().checkCallingOrSelfPermission(Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {
        List<CallLogEntry> logs = new ArrayList<CallLogEntry>();
        Cursor managedCursor = instrumentation.getTargetContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
        int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
        int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
        int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
        while (managedCursor.moveToNext()) {
            String phNumber = managedCursor.getString(number);
            String callType = managedCursor.getString(type);
            String callDate = managedCursor.getString(date);
            Date callDayTime = new Date(Long.valueOf(callDate));
            String callDuration = managedCursor.getString(duration);
            logs.add(new CallLogEntry(phNumber, Integer.parseInt(callDuration), callDayTime, Integer.parseInt(callType)));
        }
        managedCursor.close();
        return logs;
    } else {
        throw new PermissionDeniedException("Application under test does not have required READ_CALL_LOG permission for this feature.");
    }

}
项目:NotifyTools    文件:SimUtils.java   
public static String getLastestSim(Context context, String telNum) {
    String result = "SIM1";
    Cursor cursor = null;
    try {
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return "";
        }
        cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER, CallLog.Calls.PHONE_ACCOUNT_ID},
                CallLog.Calls.NUMBER + " = ?", new String[]{telNum}, CallLog.Calls.DEFAULT_SORT_ORDER);
        if (cursor != null && cursor.moveToFirst()) {
            int subId = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
            log.d("getLastestSim subId:" + subId);
            int slotId = getSlotIdUsingSubId(subId, context);
            log.d( "getLastestSim slotId:" + slotId);
            if(1 == slotId){
                result = "SIM2";
            }
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        if(cursor != null){
            cursor.close();
        }
    }
    log.d("getLastestSim result:" + result);

    return result;
}
项目:XPermission    文件:PermissionsChecker.java   
/**
 * write or delete call log, {@link Manifest.permission#WRITE_CALL_LOG}
 *
 * @param activity
 * @return true if success
 */
private static boolean checkWriteCallLog(Context 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;
}
项目:permissions4m    文件:PermissionsChecker.java   
/**
 * 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;
}
项目:CSipSimple    文件:CallLogAdapter.java   
/**
 * Returns the call types for the given number of items in the cursor.
 * <p>
 * It uses the next {@code count} rows in the cursor to extract the types.
 * <p>
 * It position in the cursor is unchanged by this function.
 */
private int[] getCallTypes(Cursor cursor, int count) {
    int position = cursor.getPosition();
    int[] callTypes = new int[count];
    for (int index = 0; index < count; ++index) {
        callTypes[index] = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
        cursor.moveToNext();
    }
    cursor.moveToPosition(position);
    return callTypes;
}
项目:CSipSimple    文件:CallLogAdapter.java   
/**
 * Returns the call ids for the given number of items in the cursor.
 * <p>
 * It uses the next {@code count} rows in the cursor to extract the types.
 * <p>
 * It position in the cursor is unchanged by this function.
 */
private long[] getCallIds(Cursor cursor, int count) {
    int position = cursor.getPosition();
    long[] callIds = new long[count];
    for (int index = 0; index < count; ++index) {
        if(!cursor.isAfterLast()) {
            callIds[index] = cursor.getLong(cursor.getColumnIndex(CallLog.Calls._ID));
        }
        cursor.moveToNext();
    }
    cursor.moveToPosition(position);
    return callIds;
}
项目:CSipSimple    文件:CallLogAdapter.java   
/**
 * Retrieve the remote sip uri for a call log at the given position
 * @param position  the position to look at
 * @return the sip uri
 */
public String getCallRemoteAtPostion(int position) {
    Cursor item = (Cursor) getItem(position);
    if(item != null) {
        String number = item.getString(item.getColumnIndex(CallLog.Calls.NUMBER));
        return SipUri.getCanonicalSipContact(number, false);
    }
    return "";
}
项目:Misc    文件:CallHistoryActivity.java   
/**
 * Format the type as a string.
 *
 * @param type
 * @return
 */
public static String formatType(int type) {
    if (type == CallLog.Calls.INCOMING_TYPE) {
        return "Incoming";
    }
    if (type == CallLog.Calls.OUTGOING_TYPE) {
        return "Outgoing";
    }
    if (type == CallLog.Calls.MISSED_TYPE) {
        return "Missed";
    }
    return "<Unknown type>";
}
项目:Android-2017    文件:CallDetailActivity.java   
private void loadAndShowData(long id) {

        ContentResolver contentResolver = this.getContentResolver();
        Uri llamadasUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id);

        long date = 0, duration = 0;
        String number = "";

        String [] projection = new String [] {CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.DURATION, CallLog.Calls.DATE};

        // verificar permisos de llamada
        int permissionCheck = ContextCompat.checkSelfPermission (this, Manifest.permission.READ_CALL_LOG);

        if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
            Cursor cursor = contentResolver.query(llamadasUri, // URI del Content provider
                                            projection,        // Columnas a devolver
                                            null,              // Condición a la query
                                            null,              // Argumentos variables de la condición
                                            null);             // Orden de los resultados

            if (cursor != null) {
                cursor.moveToFirst();
                date = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
                duration = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION));
                number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));

                cursor.close();
            }


            // mostramos los datos leidos en pantalla
            tvCallNumber.setText(number);
            tvCallDate.setText(DateUtils.getRelativeTimeSpanString(this, date));
            tvCallDuration.setText(AppUtils.secondsToHoutMinSecond(duration));
            tvCallId.setText(Long.toString(id));

        }


    }
项目:Android-2017    文件:MainActivity.java   
private Cursor getCalls (int type) {
    Uri llamadasUri = CallLog.Calls.CONTENT_URI;
    ContentResolver contentResolver = getContentResolver();

    String [] projection = new String [] {Calls._ID, Calls.NUMBER, Calls.DURATION, Calls.TYPE};

    String selection = null;
    String [] selectionArgs = null;

    if (type == Calls.INCOMING_TYPE || type == Calls.OUTGOING_TYPE || type == Calls.MISSED_TYPE || type == Calls.REJECTED_TYPE ) {
        selection = Calls.TYPE + " = ? ";
        selectionArgs = new String [] {Integer.toString(type)};
    }

    String order = Calls.DATE + " DESC ";

    // verificar permisos de llamada
    int permissionCheck = ContextCompat.checkSelfPermission (this, Manifest.permission.READ_CALL_LOG);

    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        cursor = contentResolver.query(llamadasUri,   // URI del Content provider
                projection,    // Columnas a devolver
                selection,     // Condición a la query
                selectionArgs, // Argumentos variables de la condición
                order);         // Orden de los resultados
    }

    return cursor;

}
项目:GravityBox    文件:LockscreenAppBar.java   
private int getMissedCallCount() {
    try {
        String[] selection = { CallLog.Calls.TYPE };
        String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE +
                " AND " + CallLog.Calls.NEW + "=1";
        Cursor c = mContext.getContentResolver().query(CallLog.Calls.CONTENT_URI, selection, where, null, null);
        return c.getCount();
    } catch (Throwable t) {
        XposedBridge.log(t);
        return 0;
    }
}
项目:react-native-phone-call    文件:RNPhoneCallModule.java   
private void startMakingCall() {
  Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
  callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  if (ActivityCompat.checkSelfPermission(getReactApplicationContext(), permission.CALL_PHONE)
          != PackageManager.PERMISSION_GRANTED) {
    return;
  }
  getReactApplicationContext().startActivity(callIntent);
  getReactApplicationContext().getContentResolver()
          .registerContentObserver(CallLog.Calls.CONTENT_URI, true, new CallContentObserver());
}
项目:CallAdv    文件:CallLogUtils.java   
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
    super.onQueryComplete(token, cookie, cursor);
    if (cursor != null && cursor.getCount() > 0) {
        callLogs = new ArrayList<CallLogBean>();
        SimpleDateFormat sfd = new SimpleDateFormat("MM-dd hh:mm");
        Date date;
        while (cursor.moveToNext()){
            date = new Date(cursor.getLong(cursor
                    .getColumnIndex(CallLog.Calls.DATE)));
            String number = cursor.getString(cursor
                    .getColumnIndex(CallLog.Calls.NUMBER));
            int type = cursor.getInt(cursor
                    .getColumnIndex(CallLog.Calls.TYPE));
            String cachedName = cursor.getString(cursor
                    .getColumnIndex(CallLog.Calls.CACHED_NAME));// 缓存的名称与电话号码,如果它的存在
            int id = cursor.getInt(cursor
                    .getColumnIndex(CallLog.Calls._ID));

            CallLogBean callLogBean = new CallLogBean();
            callLogBean.setId(id);
            callLogBean.setNumber(number);
            callLogBean.setName(cachedName);
            if (null == cachedName || "".equals(cachedName)) {
                callLogBean.setName(number);
            }
            callLogBean.setType(type);
            callLogBean.setDate(sfd.format(date));
            callLogs.add(callLogBean);
        }
    }
}
项目:lr_dialer    文件:CallLogInfo.java   
public static int getTypeRes(int type)
{
    Integer typeRes = null;
    switch (type)
    {
        case CallLog.Calls.INCOMING_TYPE:
        {
            typeRes = R.drawable.incall;
            break;
        }
        case CallLog.Calls.OUTGOING_TYPE:
        {
            typeRes = R.drawable.tocall;
            break;
        }
        case CallLog.Calls.MISSED_TYPE:
        {
            typeRes = R.drawable.incall;
            break;
        }
        default:
        {
            typeRes = R.drawable.incall;
            break;
        }
    }
    return typeRes;
}