1. 程式人生 > 其它 >Android 呼叫系統的分享

Android 呼叫系統的分享

public class ShareManager {

    //分享檔案
    public static void shareFiles(Context context, List<File> fileList) {
        if(context == null || fileList == null || fileList.size() < 1) {
            return;
        }
        List<Uri> uriList = new ArrayList();
        for(File file : fileList) {
            Uri uri 
= Uri.fromFile(file); uriList.add(uri); } Intent intent = null; boolean isMultiple = uriList.size() > 1; //是否批量分享 if(isMultiple) { intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("**"); intent.putExtra(Intent.EXTRA_STREAM,uriList.get(
0)); } context.startActivity(Intent.createChooser(intent, "Choose a channel to share your files...")); } //分享圖片 public static void shareImage(Context context, File imageFile) { if(context == null || imageFile == null) { return; } Intent intent
= new Intent(Intent.ACTION_SEND); intent.setType("image/*"); Uri uri = Uri.fromFile(imageFile); intent.putExtra(Intent.EXTRA_STREAM, uri); context.startActivity(Intent.createChooser(intent, "Choose a channel to share your image...")); } //分享文字 public static void shareText(Context context, String text) { if(context == null || text == null) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, text); context.startActivity(Intent.createChooser(intent, "Choose a channel to share your text...")); } }