Intent.createChooser

來源:互聯網
上載者:User

 平常在玩應用的時候,比如你現在登入的是QQ  ,你可能要看QQ空間的資訊,又因為QQ不知道是哪個版本的,還必須通過瀏覽器查看

這時候你點擊那個串連時 :彈出兩個瀏覽器 一個UC 一個QQ 預設瀏覽器,他讓你選擇,當時在玩的時候他是怎麼樣做到的,今天在別人的一篇文章中

看到了

startActivity(Intent.createChooser (xx,xx));

 剛開始很納悶 !這是幹嘛用的!

看了下官方的文檔:

Convenience function for creating a ACTION_CHOOSER Intent. Parameters:target The Intent that the user will be selecting an activity to perform.title Optional title that will be displayed in the chooser.Returns:Return a new Intent object that you can hand to Context.startActivity() and related methods.

看的不是很明白 ,直接上手寫了一個:

public void buttonClick(View view){Intent intent =new Intent(Intent.ACTION_SET_WALLPAPER);startActivity(Intent.createChooser(intent, "choose"));}

 一點擊這個button 效果出現了,就是我前面說的的那效果:

一看圖大家明白了是幹什麼用的吧。

 

一個不能說明什麼:在來一個發簡訊的

 Intent share = new Intent(android.content.Intent.ACTION_SEND);          share.setType("text/plain");                                //確定資料格式                                        share.putExtra(Intent.EXTRA_SUBJECT, "Title");    //添加附加資訊            share.putExtra(Intent.EXTRA_TEXT,"helloffff");          startActivity(Intent.createChooser(share, "其他轉寄方式"));  

 我覺得這個還很有意思的! 大家也多看看

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.