如何拨打通话记录中的号码
How do I call a number from call log
我需要帮助才能拨打通话记录中的号码。我需要让用户能够点击其中一个号码并拨打该号码。我想我需要做一个数组,但我真的不知道或者数字应该变成链接?
public class MainActivity extends AppCompatActivity {
TextView call;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
call = (TextView)findViewById(R.id.call); //finds textview
getCallDetails();
final TextView dialers=(TextView)this.findViewById(R.id.call);
dialers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_DIAL,
Uri.parse("tel://"+ dialers.getText().toString().trim())));
}
});
}
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 );
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;
//gets outcoming calls
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
//gets incoming calls
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();
call.setText(sb);
}
}
将这些属性添加到显示 phone 数字的 call
TextView:
android:autoLink="phone"
android:linksClickable="true"
并且数字将具有 link 颜色,当您单击该数字时,您将启动拨号应用程序。
或
call.setText(sb);
call.setLinkTextColor(Color.RED);
Linkify.addLinks(call, Linkify.PHONE_NUMBERS);
我需要帮助才能拨打通话记录中的号码。我需要让用户能够点击其中一个号码并拨打该号码。我想我需要做一个数组,但我真的不知道或者数字应该变成链接?
public class MainActivity extends AppCompatActivity {
TextView call;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
call = (TextView)findViewById(R.id.call); //finds textview
getCallDetails();
final TextView dialers=(TextView)this.findViewById(R.id.call);
dialers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_DIAL,
Uri.parse("tel://"+ dialers.getText().toString().trim())));
}
});
}
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 );
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;
//gets outcoming calls
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
//gets incoming calls
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();
call.setText(sb);
}
}
将这些属性添加到显示 phone 数字的 call
TextView:
android:autoLink="phone"
android:linksClickable="true"
并且数字将具有 link 颜色,当您单击该数字时,您将启动拨号应用程序。
或
call.setText(sb);
call.setLinkTextColor(Color.RED);
Linkify.addLinks(call, Linkify.PHONE_NUMBERS);