Android 調用系統的分享界面,進行文件分享

 //分享文字  
    public void shareText(View view) {  
        Intent shareIntent = new Intent();  
        shareIntent.setAction(Intent.ACTION_SEND);  
        shareIntent.putExtra(Intent.EXTRA_TEXT, "text內容.");  
        shareIntent.setType("text/plain");  
  
        //設置標題(彈出分享列表的界面標題),
        startActivity(Intent.createChooser(shareIntent, "分享到"));  
    }  
  
    //分享一張圖片  
    public void shareSingleImage(View view) {  
        String imagePath = Environment.getExternalStorageDirectory() + File.separator + "aaa.jpg";  
        //由文件得到uri  
        Uri imageUri = Uri.fromFile(new File(imagePath));  //imagePath--本地的文件路徑
        Log.d("share", "uri:" + imageUri);  
  
        Intent shareIntent = new Intent();  
        shareIntent.setAction(Intent.ACTION_SEND);  
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);  
        shareIntent.setType("image/*");  
        startActivity(Intent.createChooser(shareIntent, "分享到:"));  
    }  
  
    //分享多張圖片  (保存一個集合)
    public void shareMultipleImage(View view) {  
        ArrayList<Uri> uriList = new ArrayList<>();  
  
        String path = Environment.getExternalStorageDirectory() + File.separator;  
        uriList.add(Uri.fromFile(new File(filePath+"aaa-1.jpg")));  
        uriList.add(Uri.fromFile(new File(filePath+"aaa-2.jpg")));  
        uriList.add(Uri.fromFile(new File(filePath+"aaa-3.jpg")));  
  
        Intent shareIntent = new Intent();  
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);  
        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);  
        shareIntent.setType("image/*");  
        startActivity(Intent.createChooser(shareIntent, "分享到:"));  
    }  
}  

//分享所有類型文件:

 Intent shareIntent = new Intent(Intent.ACTION_SEND);
 shareIntent.putExtra(Intent.EXTRA_STREAM,
 Uri.fromFile(new File(filePath)));
 shareIntent.setType("*/*");//此處可發送多種文件
 startActivity(Intent.createChooser(shareIntent, “分享到:”));
--------------------- 
作者:假裝我在飛 
來源:CSDN 
原文:https://blog.csdn.net/yuzhidao/article/details/75267627 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

 

Android分享---調用系統自帶的分享功能https://blog.csdn.net/s13383754499/article/details/81943895

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章