gpt4 book ai didi

android - 在android中获取以前的通话时间而不是上次通话时间?

转载 作者:搜寻专家 更新时间:2023-11-01 09:26:17 25 4
gpt4 key购买 nike

我正在创建一个基于某些规则以编程方式断开调用的应用程序!我遇到的麻烦是我试图在断开电话后获取上次通话的通话时间!但问题是我得到的持续时间是之前的通话持续时间,而不是断开的通话!

我的代码是:

public void disconnect(){
disconnectPhoneItelephony(context);
calldisconnected();
WhitelistDAO whiteListDao1 = new WhitelistDAO(context);
String dura = LastCall();
if (dura.equals("0")) {
int dbTime = Integer.parseInt(whiteListDao1.getLimit(finalNumber));
whiteListDao1.updateLimit(String.valueOf(dbTime), finalNumber);
} else {
whiteListDao1.updateLimit("0", finalNumber);
}
}


public String LastCall() {
String callDura = "0";
StringBuffer sb = new StringBuffer();
Uri contacts = CallLog.Calls.CONTENT_URI;
if (ActivityCompat.checkSelfPermission(this, 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 null;
}
Cursor managedCursor = getApplicationContext().getContentResolver().query(
contacts, null, null, null, android.provider.CallLog.Calls.DATE+ " DESC limit 1;");
int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
int duration1 = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
if( managedCursor.moveToFirst() == true ) {
String phNumber = managedCursor.getString( number );
callDura = managedCursor.getString( duration1 );
String callDate = managedCursor.getString(date);
String callDayTime = new Date(Long.valueOf(callDate)).toString();
String dir = null;
Log.e("DUR","\nPhone Number:--- "+phNumber +" \nCall duration in sec :--- "+callDura +" \nCall Date in sec :--- "+callDayTime );
}
managedCursor.close();
return callDura;
}

最佳答案

我想这应该可以解决!延迟 1 秒运行处理程序中的函数!然后您将获得正确的上次通话时长,而不是之前的通话时长。我认为android无法在断开连接后立即获取最后一次通话的详细信息!可能需要第二次延迟才能插入数据库!

喜欢:

 private Handler handler = new Handler();
public void disconnect(){
disconnectPhoneItelephony(context);
calldisconnected();
handler.removeCallbacksAndMessages(null);
handler.postDelayed(new Runnable() {
@Override
public void run() {
WhitelistDAO whiteListDao1 = new WhitelistDAO(context);
String dura = LastCall();
if (dura.equals("0")) {
int dbTime = Integer.parseInt(whiteListDao1.getLimit(finalNumber));
whiteListDao1.updateLimit(String.valueOf(dbTime), finalNumber);
} else {
whiteListDao1.updateLimit("0", finalNumber);
}
}
}, 1000);

}

关于android - 在android中获取以前的通话时间而不是上次通话时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50369057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com