android調用系統自帶發送(分享)功能(文件、圖片、音視頻)

根據個人需求選用合適功能
//path爲本地文件絕對路徑
public void shareImage(String path) {
        //由文件得到uri
        Uri imageUri = Uri.fromFile(new File(path));
        Log.d("share", "uri:" + imageUri);
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
//        ArrayList<Uri> imageUris = new ArrayList<Uri>();//不需要多文件可以刪掉
//        for (File f : files) {
//            imageUris.add(Uri.fromFile(f));
//        }
//        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);//多個文件
        shareIntent.setType("image/*");//選擇視頻
        //shareIntent.setType(“audio/*”); //選擇音頻
        //shareIntent.setType(“video/*”); //選擇視頻
        //shareIntent.setType(“video/;image/”);//同時選擇音頻和視頻
        startActivity(Intent.createChooser(shareIntent, "分享到"));
    }

 

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