gpt4 book ai didi

android - 如何在 Android 中通过短信发送通话记录历史记录?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:12:03 25 4
gpt4 key购买 nike

我正在尝试通过短信发送 CallLog 历史记录。 CallLog 历史记录显示在 TextView 中,但 SMS 不工作。

代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_log);
tv = (TextView) findViewById(R.id.call);

getCallDetails();
}


private void getCallDetails() {
// TODO Auto-generated method stub
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 );
String callType = managedCursor.getString( type );
String callDate = managedCursor.getString( 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();


String str = sb.toString();
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("5554", null, str, null, null);
}

最佳答案

因为您的消息字符串长度可能超过一条消息长度,所以使用 smsManager. divideMessage (String text)如果字符串超过 SMS 大小限制,用于发送消息:

SmsManager sms = SmsManager.getDefault(); 

if(str.length()>160){
ArrayList<String> smses = smsManager.divideMessage(str);

smsManager.sendMultipartTextMessage("5554", null,
smses, null, null);
}
else{
sms.sendTextMessage("5554", null, smses, null, null);
}

并确保您在 AndroidManifest.xml 中添加了以下权限:

 <uses-permission android:name="android.permission.SEND_SMS" />

关于android - 如何在 Android 中通过短信发送通话记录历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891139/

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