本文整理汇总了Java中android.provider.CallLog类的典型用法代码示例。如果您正苦于以下问题:Java CallLog类的具体用法?Java CallLog怎么用?Java CallLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CallLog类属于android.provider包,在下文中一共展示了CallLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkReadCallLog
import android.provider.CallLog; //导入依赖的package包/类
/**
* 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;
}
}
示例2: getPhonteContacts
import android.provider.CallLog; //导入依赖的package包/类
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;
}
示例3: checkReadCallLog
import android.provider.CallLog; //导入依赖的package包/类
/**
* 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;
}
}
示例4: addCallLog
import android.provider.CallLog; //导入依赖的package包/类
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);
}
}
示例5: onCreateLoader
import android.provider.CallLog; //导入依赖的package包/类
@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);
}
示例6: doInBackground
import android.provider.CallLog; //导入依赖的package包/类
@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";
}
示例7: startReadingCallLog
import android.provider.CallLog; //导入依赖的package包/类
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");
}
}
示例8: getPhones
import android.provider.CallLog; //导入依赖的package包/类
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();
}
}
}
示例9: getOutgoingDuration
import android.provider.CallLog; //导入依赖的package包/类
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;
}
示例10: getIncomingDuration
import android.provider.CallLog; //导入依赖的package包/类
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;
}
示例11: deleteContactCallLogs
import android.provider.CallLog; //导入依赖的package包/类
/**
* 删除联系人通话记录
*
* @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);
}
示例12: showNotificationCallBlocked
import android.provider.CallLog; //导入依赖的package包/类
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());
}
示例13: createCursorsIfNecessary
import android.provider.CallLog; //导入依赖的package包/类
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
);
}
}
示例14: onOptionsItemSelected
import android.provider.CallLog; //导入依赖的package包/类
@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;
}
示例15: getCallHistory
import android.provider.CallLog; //导入依赖的package包/类
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;
}