<activity ......>
<intent-filter>
<action android:name = "android.intent.action.SEND_MULTIPLE"/> <!--多選檔案時持分享-->
<action android:name = "android.intent.action.SEND"/> <!--單檔案分享-->
<data android:mimeType = "image/*"/> <!--圖片分享-->
<data android:mimeType = "video/*"/> <!--影片分享-->
<data android:mimeType = "audio/*"/> <!--音樂分享-->
<data android:mimeType = "*/*"/> <!--所有分享-->
</intent-filter>
</activity>
private ArrayList<String> getShareFilePathList(){
ArrayList<String> mShareFilePathList = new ArrayList<String>();
Intent intent = getIntent();
if(Intent.ACTION_SEND.equals(intent.getAction())){ //分享單個
Bundle extras = intent.getExtras();
if(extras.containsKey(Intent.EXTRA_STREAM)){
Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM);
String scheme = uri.getScheme();
if(scheme.equals("content")){
ContentResolver cr = getContentResolver();
Cursor c = cr.query(uri,null,null,null,null);
c.moveToFirst();
String filePath = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA));
mShareFilePathList.add(filePath);
c.close();
}
}
}else if(Intent.ACTION_SEND_MULIPLE.equals(mIntent.getAction())){ //分享多個
Bundle extras = mIntent.getExtras();
if(extras.containsKey(Intent.EXTRA_STREAM)){
ArrayList<Parcelable> mList = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
for(Parcelable pa:mList){
Uri uri = (Uri)pa;
String scheme = uri.getScheme();
if(scheme.equals("content")){
ContentResolver cr = getContentResolver();
Cursor c = cr.query(uri,null,null,null.null);
c.moveToFirst();
String filePath = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA));
mShareFilePathList.add(filePath);
c.close();
}
}
}
}
return mShareFilePathList;
}
全站熱搜
留言列表