Android------Intent.createChooser

來源:互聯網
上載者:User

標籤:

       Intent的匹配過程中有三個步驟,包括Action categorydata 的匹配。如果匹配出了多個結果,系統會顯示一個dialog讓使用者來選    擇。如:

     那麼今天我們主要是講解一下,如何自訂這個Chooser的標題?

     代碼其實很簡單,如下:

 
  1. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  2. intent.setType("audio/*");
  3. startActivity(Intent.createChooser(intent, "Select music"));

     可能很多同學就會疑問到底在createChooser()方法裡面,android做了什嗎?

     我們再來看看這個方法的源碼:

 
  1. public static Intent createChooser(Intent target, CharSequence title) {
  2. Intent intent = new Intent(ACTION_CHOOSER);
  3. intent.putExtra(EXTRA_INTENT, target);
  4. if (title != null) {
  5. intent.putExtra(EXTRA_TITLE, title);
  6. }
  7. return intent;
  8. }

     這下大家應該清楚了,原來在調用createChooser()方法時候,系統又建立了一個新的Action為ACTION_CHOOSER的Intent ,並把我們的原始Intent當成了參數傳進去 。選取器的title是通過 EXTRA_TITLE傳入進去的。

Android------Intent.createChooser

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.