標籤:分享 android
//分享文字Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_TEXT, "要分享的文本。");intent.setType("text/plain");startActivity(Intent.createChooser(intent, "分享"));
//分享圖片Uri uri = Uri.fromFile(new File("/storage/emulated/0/DCIM/Camera/img.jpg"));Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_STREAM, uri);intent.setType("image/jpeg");startActivity(Intent.createChooser(intent, "分享"));
//分享一系列圖片ArrayList<Uri> uris = new ArrayList<>();uris.add(Uri.fromFile(new File("/storage/emulated/0/DCIM/Camera/img.jpg")));uris.add(Uri.fromFile(new File("/storage/emulated/0/DCIM/Camera/aaa.jpeg")));Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);intent.setType("image/*");startActivity(Intent.createChooser(intent, "分享"));
原理應該是這樣的:比如註冊了某個Action為Intent.ACTION_SEND的Activity,分享的時候只是調用了這個Activity,把資料傳過去,這些都是在手機內進行的,不需要連網,由實現分享,所以需要Internet許可權的只是。
調用系統分享功能