2016-01-31 14 views
5

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!

+0

Tạo trình quay số của riêng bạn – TheSunny

+2

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? –

Trả lời

-1

Xây dựng giao diện người dùng Dialer của riêng bạn. Kiểm tra this. Bạn sẽ cần một Hoạt động để xử lý ý định và sau đó hiển thị giao diện người dùng tùy chỉnh là doanh nghiệp của bạn.

+2

Tôi đã tạo giao diện người dùng! Tôi chỉ không biết làm thế nào để hiển thị nó !!! –

+0

Nếu bạn theo dõi liên kết đó, nó sẽ cho bạn biết cách hướng lại mục đích cho ứng dụng của bạn – TheSunny

5

Add gọi phép trong manifest

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

Sau đó, cần phải kiểm tra xem nút gọi ép. để sử dụng mà bên dưới lọc ý định

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

và khi bắn 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> 

đó có nghĩa là hoạt động gọi điện thoại của bạn trong manifest sẽ được cái gì như thế này

<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> 
0

Quan điểm gọi điện thoại thực tế (những gì bạn thấy trong suốt cuộc gọi) KHÔNG thể thay đổi.

Để cụ thể hơn, một số phần của Android KHÔNG THỂ bị ghi đè, android có cốt lõi của mình và là nhà phát triển chúng tôi có quyền truy cập hạn chế vào lõi này. Trong trường hợp của bạn bạn có thể ghi đè trình quay số nhưng bạn không thể ghi đè chế độ xem cuộc gọi điện thoại thực tế.

Bạn không thể làm bất cứ điều gì về điều này, cho đến khi nhóm Android quyết định chia sẻ tính năng cốt lõi này whit cho chúng tôi (nhà phát triển).

+0

Hãy mô tả chi tiết hơn và có thể nói những gì anh ấy có thể làm vì những gì anh ấy muốn không hoạt động. – Arin

+0

Ash Patel hỏi "Tôi chỉ không thể làm cho nó hiển thị trong khi gọi!", Và câu trả lời là: Không, bạn không thể, bởi vì không ai có thể! –

Các vấn đề liên quan