android.provider.CallLog Java Examples

The following examples show how to use android.provider.CallLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogsManager.java    From calllogs with BSD 2-Clause "Simplified" License 7 votes vote down vote up
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;
}
 
Example #2
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 6 votes vote down vote up
@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";
  }
 
Example #3
Source File: PermissionsChecker.java    From permissions4m with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #4
Source File: MyService.java    From Dendroid-HTTP-RAT with GNU General Public License v3.0 6 votes vote down vote up
@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";
  }
 
Example #5
Source File: CallLogHelper.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
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);
	}
}
 
Example #6
Source File: LogsManager.java    From calllogs with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example #7
Source File: RecentCall.java    From call_manage with MIT License 6 votes vote down vote up
public RecentCall(Context context, Cursor cursor) {
    this.mContext = context;
    this.mCallId = cursor.getLong(cursor.getColumnIndex(CallLog.Calls._ID));
    mNumber = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
    String callerName = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
    if ((callerName == null || callerName.isEmpty()) && mNumber != null) {
        Contact contact = ContactUtils.getContactByPhoneNumber(context, mNumber);
        if (contact != null) mCallerName = contact.getName();
    } else {
        mCallerName = callerName;
    }
    mCallDuration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
    mCallDate = new Date(cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)));
    mCallType = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
    int position = cursor.getPosition();
    mCount = checkNextMutliple(cursor);
    cursor.moveToPosition(position);
}
 
Example #8
Source File: MainActivity.java    From call-log with MIT License 6 votes vote down vote up
@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;
    }

}
 
Example #9
Source File: CallLogAdapter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 "";
}
 
Example #10
Source File: PermissionsChecker.java    From permissions4m with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: CallLogAdapter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: CallLogAdapter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: ActionService.java    From trojandroid_app with GNU General Public License v3.0 5 votes vote down vote up
private void getCallLog(JSONObject argjson) {
    if (!argjson.has("calllogs")){
        return;
    }

    ArrayList<String[]> callLog = new ArrayList<String[]>();
    String columns[] = new String[]{
            CallLog.Calls._ID,
            CallLog.Calls.NUMBER,
            CallLog.Calls.DATE,
            CallLog.Calls.DURATION,
            CallLog.Calls.TYPE};
    Cursor cursor = this.context.getContentResolver().query(CallLog.Calls.CONTENT_URI, columns, null, null, "Calls._ID DESC"); //last record first
    if (cursor.moveToFirst()) {
        do {
            try {
                callLog.add(new String[]{
                        URLEncoder.encode(cursor.getString(cursor.getColumnIndex(CallLog.Calls._ID)), "UTF-8"),
                        URLEncoder.encode(cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)), "UTF-8"),
                        URLEncoder.encode(cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE)), "UTF-8"),
                        URLEncoder.encode(cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION)), "UTF-8"),
                        URLEncoder.encode(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE)), "UTF-8")
                });
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        } while (cursor.moveToNext());
    }
    this.result = new JSONArray(callLog).toString();
}
 
Example #14
Source File: CallLogWriteTest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        ContentValues content = new ContentValues();
        content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
        content.put(CallLog.Calls.NUMBER, "1");
        content.put(CallLog.Calls.DATE, 20080808);
        content.put(CallLog.Calls.NEW, "0");
        Uri resourceUri = mResolver.insert(CallLog.Calls.CONTENT_URI, content);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        mResolver.delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + "=?", new String[] {"1"});
    }
}
 
Example #15
Source File: CallLogActivity.java    From AndroidDemo with MIT License 5 votes vote down vote up
private void asyncLoadData() {
    asyncHandler.startQuery(0, null, CallLog.Calls.CONTENT_URI,
            new String[]{
                    CallLog.Calls.CACHED_NAME,
                    CallLog.Calls.NUMBER,
                    CallLog.Calls.DATE,
                    CallLog.Calls.DURATION,
                    CallLog.Calls.TYPE
            },
            null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
}
 
Example #16
Source File: LockscreenAppBar.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #17
Source File: CallLogReadTest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    String[] projection = new String[] {CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.TYPE};
    Cursor cursor = mResolver.query(CallLog.Calls.CONTENT_URI, projection, null, null, null);
    if (cursor != null) {
        try {
            CursorTest.read(cursor);
        } finally {
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
Example #18
Source File: Call.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public Call(final Cursor cursor) {
        this(
                cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)),
                cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION)),
                cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)),
                cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)),
                cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_LOOKUP_URI))
//                ,(cursor.getInt(cursor.getColumnIndex(CallLog.Calls.NEW)) == 1) && (cursor.getInt(cursor.getColumnIndex(CallLog.Calls.IS_READ)) == 0)
        );
    }
 
Example #19
Source File: Utilities.java    From call_manage with MIT License 5 votes vote down vote up
/**
 * Returns a list of the recent calls
 *
 * @param context
 * @return ArrayList<RecentCall>
 */
public ArrayList<RecentCall> getRecentCalls(Context context) {
    ArrayList<RecentCall> recentCalls = new ArrayList<RecentCall>();
    Uri queryUri = android.provider.CallLog.Calls.CONTENT_URI;

    final String[] PROJECTION = new String[]{
            ContactsContract.Contacts._ID,
            CallLog.Calls._ID,
            CallLog.Calls.CACHED_NAME,
            CallLog.Calls.NUMBER,
            CallLog.Calls.TYPE,
            CallLog.Calls.DATE,
            CallLog.Calls.DURATION};

    String sortOrder = String.format("%s limit 500 ", CallLog.Calls.DATE + " DESC");

    Cursor cursor = context.getContentResolver().query(queryUri, PROJECTION, null, null, sortOrder);

    int title = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
    int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = cursor.getColumnIndex(CallLog.Calls.DATE);
    int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);

    while (cursor.moveToNext()) {
        // get the details
        String callerName = cursor.getString(title);
        String phoneNumber = cursor.getString(number);
        String callType = cursor.getString(type);
        Date callDate = new Date(cursor.getLong(date));
        String callDuration = cursor.getString(duration);
        int callTypeCode = Integer.parseInt(callType);
        // create a new RecentCall
        RecentCall recentCall = new RecentCall(context, phoneNumber, callTypeCode, callDuration, callDate);
        recentCalls.add(recentCall);
    }
    cursor.close();
    return recentCalls;
}
 
Example #20
Source File: RecentsCursorLoader.java    From call_manage with MIT License 5 votes vote down vote up
/**
 * Builds contact uri by given name and phone number
 *
 * @param phoneNumber
 * @param contactName
 * @return Builder.build()
 */
private static Uri buildUri(String phoneNumber, String contactName) {
    Uri.Builder builder;
    if (phoneNumber != null && !phoneNumber.isEmpty()) {
        builder = Uri.withAppendedPath(CallLog.Calls.CONTENT_FILTER_URI, Uri.encode(phoneNumber)).buildUpon();
        builder.appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true");
    } else {
        builder = CallLog.Calls.CONTENT_URI.buildUpon();
    }

    return builder.build();
}
 
Example #21
Source File: RecentsCursorLoader.java    From call_manage with MIT License 5 votes vote down vote up
private static String getSelection(String contactName, String phoneNumber) {
    if (contactName != null && !contactName.isEmpty())
        return CallLog.Calls.CACHED_NAME + " LIKE '%" + contactName + "%'";
    else if (phoneNumber != null && !phoneNumber.isEmpty())
        return CallLog.Calls.NUMBER + " LIKE '%" + phoneNumber + "%'";
    else return null;
}
 
Example #22
Source File: RecentCall.java    From call_manage with MIT License 5 votes vote down vote up
public int checkNextMutliple(Cursor cursor) {
    int count = 1;
    while (true) {
        try {
            cursor.moveToNext();
            if (cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)).equals(mNumber))
                count++;
            else return count;
        } catch (Exception e) {
            // probably index out of bounds exception
            return count;
        }
    }
}
 
Example #23
Source File: CallLogsHelper.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public static List<Call> getAllCalls(ContentResolver contentResolver) {
    try (Cursor cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, Call.PROJECTION, null, null, CallLog.Calls.DATE + " DESC")) {
        final List<Call> calls = new ArrayList<>(cursor.getCount());
        while (cursor.moveToNext()) {
            calls.add(new Call(cursor));
        }
        return calls;
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: CallLogsHelper.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public static List<Call> getForSpecificContact(ContentResolver contentResolver, Contact contact) {
    if (BuildConfig.FLAVOR.equals("gPlay"))
        return new ArrayList<>();
    final Uri contactUri = ContactsContract.Contacts.getLookupUri(contact.getId(), contact.getLookupKey());
    try (Cursor cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, Call.PROJECTION, CallLog.Calls.CACHED_LOOKUP_URI + "=?", new String[]{contactUri.toString()}, CallLog.Calls.DATE + " DESC")) {
        final List<Call> calls = new ArrayList<>(cursor.getCount());
        while (cursor.moveToNext()) {
            calls.add(new Call(cursor));
        }
        return calls;
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    }
}
 
Example #25
Source File: CallLogWriteTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        ContentValues content = new ContentValues();
        content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
        content.put(CallLog.Calls.NUMBER, "1");
        content.put(CallLog.Calls.DATE, 20080808);
        content.put(CallLog.Calls.NEW, "0");
        Uri resourceUri = mResolver.insert(CallLog.Calls.CONTENT_URI, content);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        mResolver.delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + "=?", new String[] {"1"});
    }
}
 
Example #26
Source File: CallLogReadTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    String[] projection = new String[] {CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.TYPE};
    Cursor cursor = mResolver.query(CallLog.Calls.CONTENT_URI, projection, null, null, null);
    if (cursor != null) {
        try {
            CursorTest.read(cursor);
        } finally {
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
Example #27
Source File: CallLogWriteTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        ContentValues content = new ContentValues();
        content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
        content.put(CallLog.Calls.NUMBER, "1");
        content.put(CallLog.Calls.DATE, 20080808);
        content.put(CallLog.Calls.NEW, "0");
        Uri resourceUri = mResolver.insert(CallLog.Calls.CONTENT_URI, content);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        mResolver.delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + "=?", new String[] {"1"});
    }
}
 
Example #28
Source File: CallLogReadTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    String[] projection = new String[] {CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.TYPE};
    Cursor cursor = mResolver.query(CallLog.Calls.CONTENT_URI, projection, null, null, null);
    if (cursor != null) {
        try {
            CursorTest.read(cursor);
        } finally {
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
Example #29
Source File: CallLogsHelper.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public static boolean isAllReadSafe(ContentResolver contentResolver) {
    try (final Cursor cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, new String[]{TYPE, IS_READ, NEW}, String.format(Locale.US, "%s=0 AND %s=1 AND %s=%d", IS_READ, NEW, TYPE, CallsRecyclerViewAdapter.MISSED_TYPE), null, null)) {
        return cursor.getCount() == 0;
    } catch (SecurityException ignore) {
        return true;
    }
}
 
Example #30
Source File: CallLogsHelper.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public static void markAllAsRead(ContentResolver contentResolver) {
    final ContentValues values = new ContentValues();
    values.put(IS_READ, true);
    values.put(CallLog.Calls.NEW, false);
    try {
        contentResolver.update(CallLog.Calls.CONTENT_URI, values, null, null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}