標籤:android style blog http color 使用
http://blog.csdn.net/xyz_lmn/article/details/16856843採用Intent隱式調用Activity的方法,主要使用Intent.ACTION_SEND和Intent.createChooser();調用Android系統的分享介面。系統會過濾手機上的具有分享應用的程式,讓使用者進行選擇。如果沒有使用Intent.createChooser()則會取系統預設的使用者分享方式,只有未設定的情況下才會彈出讓使用者進行選擇。1、簡單的分享文本
1 Intent intent = new Intent();2 intent.setAction(Intent.ACTION_SEND);//設定Intent的ACTION3 intent.putExtra(Intent.EXTRA_TEXT, "YOUR SHARE TEXT");//分享的內容tag和內容4 intent.setType("text/plain");//標誌發送的資料類型,方便接收方進行處理(類型/子類型)5 startActivity(inten);//使用隱式調用Activity的方法
- 隱式調用Activity的方法
或者
- startActivity(Intent.createChooser(intent, "the chooser dialog title"));//
2、發送圖片則使用
- intent.putExtra(Intent.EXTRA_STREAM, imageUri);
- intent.setType("imag/*");//*可以為jpg,png等等
3、也可以同時分享一組資料
1 List<Uri> uris;2 Intent intent = new Intent();3 intent.setAction(Intent.ACTION_SED_MULTIPLE);//發送組4 intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);5 intent.setType("*/*");//如果都是視頻則video/*6 startActivity(intent);如果想讓應用進入彈出來的分享列表則需要在mainifest中activity添加intent-filter:例子:
1 <intent-filter> 2 <action android:name="android.intent.action.SEND" /> 3 4 <category android:name="android.intent.category.DEFAULT" /> 5 6 <data android:mimeType="image/*" /> 7 </intent-filter> 8 <intent-filter> 9 <action android:name="android.intent.action.SEND" /> 10 11 <category android:name="android.intent.category.DEFAULT" /> 12 13 <data android:mimeType="text/plain" /> 14 </intent-filter> 15 <intent-filter> 16 <action android:name="android.intent.action.SEND_MULTIPLE" /> 17 18 <category android:name="android.intent.category.DEFAULT" /> 19 20 <data android:mimeType="image/*" /> 21 </intent-filter>
在接收的activity裡面接收
1 Intent intent = getIntent();2 String action = intent.getAction();//對應intent.setAction()3 String type = intent.getType();//對應intent.setType()4 inten.get???Extra(Intent.EXTRA_???)或者intent.getParcelableExtra(Intent.EXTRA_STREAM);
也可以把分享放到ActionBar裡面。