Thursday, April 14, 2016

Android Phone Call UI - Change

Leave a Comment

How do I change the phone call user interface? Like I have my own dialer layout and contacts layout but how do I change the calling UI. So, when the call is going on, can I remove the speaker button for example?

Here is my dialer scene that I have created: Dialer Picture

But I don't know how to edit this screen: Calling Picture

EDIT: I have already built the UI, I just can not get it to show during call!

Here is the code for as a simpler version:

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;         }      } } } 

Thanks!

3 Answers

Answers 1

Add calling permission in manifest

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

Then need to check if call button pressed. for that use below intent filter

<intent-filter>     <action android:name="android.intent.action.CALL_BUTTON" />     <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

and when firing the UI

<intent-filter>     <action android:name="android.intent.action.VIEW" />     <action android:name="android.intent.action.DIAL" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />     <data android:scheme="tel" /> </intent-filter> 

that means your calling activity in manifest will be something like this

<activity         android:name="com.example.MainActivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.MAIN" />             <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>          <!-- open activity when establishing a call -->         <intent-filter>             <action android:name="android.intent.action.CALL_PRIVILEGED" />             <category android:name="android.intent.category.DEFAULT" />             <data android:scheme="tel" />         </intent-filter>      </activity> 

Answers 2

Build your own Dialer UI. Check this out. You will need an Activity to handle the intent and then displaying a custom UI is your business.

Answers 3

The actual calling view (what you see during calls) CAN`T be changed.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment