我正在创建一个应用程序,其中我想获取所有传入,传出和未接来电的通话记录。我怎么能这样做?
答案 0 :(得分:9)
答案 1 :(得分:2)
此处的所有答案均使用String[] projection = new String[] {
CallLog.Calls.CACHED_NAME,
CallLog.Calls.NUMBER,
CallLog.Calls.TYPE,
CallLog.Calls.DATE
};
// String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cursor = mContext.getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, null, null, null);
while (cursor.moveToNext()) {
String name = cursor.getString(0);
String number = cursor.getString(1);
String type = cursor.getString(2); // https://developer.android.com/reference/android/provider/CallLog.Calls.html#TYPE
String time = cursor.getString(3); // epoch time - https://developer.android.com/reference/java/text/DateFormat.html#parse(java.lang.String
}
cursor.close();
,现已弃用。它应该替换为class Post(models.Model):
posted_by = models.ForeignKey('auth.User', on_delete=models.CASCADE)
def save(self, *args, **kwargs):
super(Post, self).save(*args, **kwargs)
方法,如上所述[{3}}并展示here。
以下是基于这些示例的简短示例代码:
class PostSerializer(serializers.ModelSerializer):
class Meta:
model = Post
fields = '__all__'
def create(self, validated_data):
post = Post.objects.create(**validated_data)
# extra code to add images
答案 2 :(得分:1)
<强>烨。它的作用我:)试试这个。
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery(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);
sb.append("Call Details :");
while (managedCursor.moveToNext()) {
String phNumber = managedCursor.getString(number); // mobile number
String callType = managedCursor.getString(type); // call type
String callDate = managedCursor.getString(date); // call date
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
}
managedCursor.close();
miss_cal.setText(sb);
Log.e("Agil value --- ", sb.toString());
}
注意:
<强> 1。你想获得特定的通话类型?然后使用以下代码。
<强> 2。例如: - 如果我想单独收入呼叫,则在交换机中命令/删除相同的代码 案例
第3。然后在收入调用案例中使用以下代码。
sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration);
sb.append("\n-----Agil----------------------------------");
&#13;
答案 3 :(得分:0)
public class MainActivity extends Activity
{
TextView textView = null;
int callcode;
String callType ;
String phNum;
Date callDate;
String callTypeCode;
String strcallDate;
String callDuration;
String currElement;
static boolean ring = false;
static boolean callReceived = false;
StringBuffer sb = new StringBuffer();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textview_call);
SmsManager sms = SmsManager.getDefault();
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
/* Query the CallLog Content Provider */
@SuppressWarnings("deprecation")
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, strOrder);
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);
sb.append("Call Log :");
if(managedCursor.moveToFirst())
{
String phNum = managedCursor.getString(number);
String callTypeCode = managedCursor.getString(type);
String strcallDate = managedCursor.getString(date);
Date callDate = new Date(Long.valueOf(strcallDate));
String callDuration = managedCursor.getString(duration);
String callType = null;
int callcode = Integer.parseInt(callTypeCode);
switch (callcode)
{
case CallLog.Calls.OUTGOING_TYPE:
callType = "Outgoing";
//sms.sendTextMessage(phNum, null, "Outgoing msg", null, null);
break;
case CallLog.Calls.INCOMING_TYPE:
callType = "Incoming";
//sms.sendTextMessage(phNum, null, "Incoming msg", null, null);
break;
case CallLog.Calls.MISSED_TYPE:
callType = "Missed";
//sms.sendTextMessage(phNum, null, "Missed msg", null, null);
break;
}
sb.append("\nPhone Number:--- " + phNum + " \nCall Type:--- "
+ callType + " \nCall Date:--- " + callDate
+ " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
}
managedCursor.close();
textView.setText(sb);
}
}
答案 4 :(得分:0)
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<billerBillPresentmentResponse xmlns="http://localhost/Services/Biller_bill_presentment.wsdl">
<result xmlns="">
<paramOut xmlns="http://localhost/Services/Biller_bill_presentment.wsdl/types/">
<errorCode>000</errorCode>
<errorDescription>SUCCESSFULL</errorDescription>
<billingsRec>
<array>
<billingNo>?</billingNo>
<billNo>?</billNo>
<billStatus>?</billStatus>
<dueAmount>?</dueAmount>
<issueDate>?</issueDate>
<openDate>?</openDate>
</array>
</billingsRec>
</paramOut>
<signature xmlns="http://localhost/Services/Biller_bill_presentment.wsdl/types/">aaa</signature>
</result>
</billerBillPresentmentResponse>
</soap:Body>
</soap:Envelope>