Làm cách nào để thay đổi giao diện người dùng của cuộc gọi điện thoại? Giống như tôi có bố trí trình quay số và bố cục liên hệ của riêng mình nhưng làm cách nào để thay đổi giao diện người dùng đang gọi. Vì vậy, khi cuộc gọi đang diễn ra, tôi có thể tháo nút loa không?Giao diện người dùng điện thoại Android - Thay đổi
Đây là cảnh quay của tôi mà tôi đã tạo ra: Dialer Picture
Nhưng tôi không biết làm thế nào để chỉnh sửa màn hình này: Calling Picture
EDIT: Tôi đã xây dựng giao diện người dùng, tôi chỉ có thể không làm cho nó hiển thị trong khi gọi!
Đây là mã cho là một phiên bản đơn giản hơn:
public class MainActivity extends Activity {
private Button callBtn;
private Button dialBtn;
private EditText number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
number = (EditText) findViewById(R.id.phoneNumber);
callBtn = (Button) findViewById(R.id.call);
dialBtn = (Button) findViewById(R.id.dial);
// add PhoneStateListener for monitoring
MyPhoneListener phoneListener = new MyPhoneListener();
TelephonyManager telephonyManager =
(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
// receive notifications of telephony state changes
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
callBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
// set the data
String uri = "tel:"+number.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
startActivity(callIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Your call has failed...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
dialBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
String uri = "tel:"+number.getText().toString();
Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(uri));
startActivity(dialIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Your call has failed...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
private class MyPhoneListener extends PhoneStateListener {
private boolean onCall = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// phone ringing...
Toast.makeText(MainActivity.this, incomingNumber + " calls you",
Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// one call exists that is dialing, active, or on hold
Toast.makeText(MainActivity.this, "on call...",
Toast.LENGTH_LONG).show();
//because user answers the incoming call
onCall = true;
break;
case TelephonyManager.CALL_STATE_IDLE:
// in initialization of the class and at the end of phone call
// detect flag from CALL_STATE_OFFHOOK
if (onCall == true) {
Toast.makeText(MainActivity.this, "restart app after call",
Toast.LENGTH_LONG).show();
// restart our application
Intent restart = getBaseContext().getPackageManager().
getLaunchIntentForPackage(getBaseContext().getPackageName());
restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(restart);
onCall = false;
}
break;
default:
break;
}
}
}
}
Cảm ơn!
Tạo trình quay số của riêng bạn – TheSunny
Tôi đã xây dựng giao diện người dùng nhưng làm cách nào để hiển thị giao diện người dùng trong khi gọi? –