Android調用系統分享功能以及createChooser的使用

來源:互聯網
上載者:User

標籤:filter   tle   enable   sel   layout   out   lib   dialog   tools   

工程結構

//  

點擊測試分享                                                                                                          點擊createChoose妙用

     

主要是看右邊的,可不是用什麼Dialog來搞的哦,而是你Activity程式,可以啟用進去了

提示:這個東西可以延伸到一個音頻檔案,開啟時,可以調用你的音樂播放器來播放哦,視頻,圖片,也是類似,可以調用你自己的東西

當然,前提是你的manifest.xml裡的東西要配置對呀

<data Android:mimeType="mark/nimei" />  

如下

<activity android:name=".TestActivity"
            android:label="你妹啊"
            >
            <intent-filter>  
                <action android:name="android.intent.action.XXMM" />  
                 <category android:name="android.intent.category.DEFAULT" />  
                 <category android:name="android.intent.category.OPENABLE" />  
                 <data android:mimeType="mark/nimei" />  
            </intent-filter>  
        </activity>
        <activity android:name=".Test2Activity"
            android:label="你妹啊2"
            >
            <intent-filter>  
                <action android:name="android.intent.action.XXMM" />  
                 <category android:name="android.intent.category.DEFAULT" />  
                 <category android:name="android.intent.category.OPENABLE" />  
                 <data android:mimeType="mark/nimei" />  
            </intent-filter>  
        </activity>

 

//代碼如下:

[java] view plain copy
  1. package com.mark.share.demo;  
  2.   
  3. import java.io.File;  
  4.   
  5. import android.app.Activity;  
  6. import android.content.Intent;  
  7. import android.net.Uri;  
  8. import android.os.Bundle;  
  9. import android.view.View;  
  10. import android.view.View.OnClickListener;  
  11. import android.widget.Button;  
  12.   
  13. public class AppShareDemoActivity extends Activity  
  14. {  
  15.     private Button testshare;  
  16.     private Button createChooserBtn;  
  17.     @Override  
  18.     public void onCreate(Bundle savedInstanceState)  
  19.     {  
  20.         super.onCreate(savedInstanceState);  
  21.         setContentView(R.layout.main);  
  22.           
  23.         testshare=(Button) findViewById(R.id.testshare);  
  24.         createChooserBtn=(Button) findViewById(R.id.Test_createChooser);  
  25.           
  26.         testshare.setOnClickListener(new OnClickListener()  
  27.         {  
  28.               
  29.             @Override  
  30.             public void onClick(View v)  
  31.             {  
  32.                 Intent intent = new Intent(Intent.ACTION_SEND);  
  33.                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  34.                 intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("sdcard/1.png")));  //傳輸圖片或者檔案 採用流的方式  
  35.                 intent.putExtra(Intent.EXTRA_TEXT, "分享分享微博");   //附帶的說明資訊  
  36.                 intent.putExtra(Intent.EXTRA_SUBJECT, "標題");  
  37.                 intent.setType("image/*");   //分享圖片  
  38.                 startActivity(Intent.createChooser(intent,"分享"));  
  39.             }  
  40.         });  
  41.           
  42.         createChooserBtn.setOnClickListener(new OnClickListener()  
  43.         {  
  44.             @Override  
  45.             public void onClick(View v)  
  46.             {  
  47.                 Intent intent = new Intent();  
  48.                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  49.                 intent.setAction("android.intent.action.XXMM");  
  50.                 intent.setDataAndType(Uri.parse("file:///sdcard/DCIM/cc.mp3"), "mark/nimei");    
  51.                 startActivity(Intent.createChooser(intent, "Select music1 app"));    
  52.             }  
  53.         });  
  54.     }  

 

Android調用系統分享功能以及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.