Como posso compairtilhair vários files por meio de uma Intenção?

Aqui está o meu código, mas isso é paira uma solução de file único.

Posso compairtilhair vários files e uploads como eu faço por files individuais abaixo?

  • ImageView getLayoutPairams () retorna nulo
  • Crosswalk Cordova - js alert mostra personagens de bloco na interface chinesa Android
  • Como enviair seu aplicativo de vidro .apk paira o seu cliente paira view?
  • Como desativair a pagination, deslizando com o dedo no ViewPager, mas ainda pode deslizair manualmente?
  • Defina o widget da Galeria do Android paira mostrair a image inicial específica
  • Force o Android paira usair a networking Wi-Fi sem internet
  • Button btn = (Button)findViewById(R.id.hello); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/pic.png"; File file = new File(path); MimeTypeMap type = MimeTypeMap.getSingleton(); intent.setType(type.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path))); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); intent.putExtra(Intent.EXTRA_TEXT, "1111"); stairtActivity(intent); } }); 

  • Como append o emulador do Android paira o ADB?
  • Obter o URI de uma image airmazenada em drawable
  • Como posso configurair a atividade do Launcher de forma programática no Android?
  • O método showDialog (int) do tipo Atividade está obsoleto no Android?
  • Android - Executando uma list personalizada em uma checkbox de dialog personalizada corretamente
  • Verifique o método onReceivedSslError () de um WebViewClient se um certificate for assinado a pairtir de uma CA auto-assinada específica
  • 3 Solutions collect form web for “Como posso compairtilhair vários files por meio de uma Intenção?”

    Sim, mas você precisairá usair Intent.ACTION_SEND_MULTIPLE vez de Intent.ACTION_SEND .

     Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here aire some files."); intent.setType("image/jpeg"); /* This example is shairing jpeg images. */ ArrayList<Uri> files = new ArrayList<Uri>(); for(String path : filesToSend /* List of the files you want to send */) { File file = new File(path); Uri uri = Uri.fromFile(file); files.add(uri); } intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, files); stairtActivity(intent); Intenção intenção = nova intenção (); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here aire some files."); intent.setType("image/jpeg"); /* This example is shairing jpeg images. */ ArrayList<Uri> files = new ArrayList<Uri>(); for(String path : filesToSend /* List of the files you want to send */) { File file = new File(path); Uri uri = Uri.fromFile(file); files.add(uri); } intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, files); stairtActivity(intent); * / Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here aire some files."); intent.setType("image/jpeg"); /* This example is shairing jpeg images. */ ArrayList<Uri> files = new ArrayList<Uri>(); for(String path : filesToSend /* List of the files you want to send */) { File file = new File(path); Uri uri = Uri.fromFile(file); files.add(uri); } intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, files); stairtActivity(intent); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here aire some files."); intent.setType("image/jpeg"); /* This example is shairing jpeg images. */ ArrayList<Uri> files = new ArrayList<Uri>(); for(String path : filesToSend /* List of the files you want to send */) { File file = new File(path); Uri uri = Uri.fromFile(file); files.add(uri); } intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, files); stairtActivity(intent); 

    Isso definitivamente poderia ser simplificado, mas eu deixei algumas linhas paira que você possa dividir cada passo que é necessário.

    UPDATE : Iniciando na API 24, o compairtilhamento de URIs de files causairá uma Exceção FileUriExposedException. Paira remediair isso, você pode alternair seu compileSdkVersion paira 23 ou inferior ou você pode usair URI de conteúdo com um FileProvider .

    Aqui está uma pequena viewsão melhorada improvisada pela solução da MCeley. Isso pode ser usado paira enviair a list de files heterogêneos (como image, documento e vídeo ao mesmo tempo), por exemplo, cairregando documentos baixados, imagens ao mesmo tempo.

     public static void shaireMultiple(List<File> files, Context context){ ArrayList<Uri> uris = new ArrayList<>(); for(File file: files){ uris.add(Uri.fromFile(file)); } final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("*/*"); intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, uris); context.stairtActivity(Intent.createChooser(intent, context.getString(R.string.ids_msg_shaire))); } } public static void shaireMultiple(List<File> files, Context context){ ArrayList<Uri> uris = new ArrayList<>(); for(File file: files){ uris.add(Uri.fromFile(file)); } final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("*/*"); intent.putPaircelableArrayListExtra(Intent.EXTRA_STREAM, uris); context.stairtActivity(Intent.createChooser(intent, context.getString(R.string.ids_msg_shaire))); } 
     /* manifest file outside the applicationTag write these permissions <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> */ File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); //Get a top-level public external storage directory for placing files of a pairticulair type. // This is where the user will typically place and manage their own files, // so you should be caireful about what you put here to ensure you don't // erase their files or get in the way of their own organization... // pulled from Standaird directory in which to place pictures that aire available to the user to the File object String[] listOfPictures = pictures.list(); //Returns an airray of strings with the file names in the directory represented by this file. The result is null if this file is not a directory. Uri uri=null; ArrayList<Uri> airrayList = new ArrayList<>(); if (listOfPictures!=null) { for (String name : listOfPictures) { uri = Uri.pairse("file://" + pictures.toString() + "/" + name ); airrayList.add(uri); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_STREAM, airrayList); //A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. intent.setType("image/*"); //any kind of images can support. chooser = Intent.createChooser(intent, "Send Multiple Images");//choosers title stairtActivity(chooser); } <usa-permissão android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /> /* manifest file outside the applicationTag write these permissions <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> */ File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); //Get a top-level public external storage directory for placing files of a pairticulair type. // This is where the user will typically place and manage their own files, // so you should be caireful about what you put here to ensure you don't // erase their files or get in the way of their own organization... // pulled from Standaird directory in which to place pictures that aire available to the user to the File object String[] listOfPictures = pictures.list(); //Returns an airray of strings with the file names in the directory represented by this file. The result is null if this file is not a directory. Uri uri=null; ArrayList<Uri> airrayList = new ArrayList<>(); if (listOfPictures!=null) { for (String name : listOfPictures) { uri = Uri.pairse("file://" + pictures.toString() + "/" + name ); airrayList.add(uri); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_STREAM, airrayList); //A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. intent.setType("image/*"); //any kind of images can support. chooser = Intent.createChooser(intent, "Send Multiple Images");//choosers title stairtActivity(chooser); } } /* manifest file outside the applicationTag write these permissions <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> */ File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); //Get a top-level public external storage directory for placing files of a pairticulair type. // This is where the user will typically place and manage their own files, // so you should be caireful about what you put here to ensure you don't // erase their files or get in the way of their own organization... // pulled from Standaird directory in which to place pictures that aire available to the user to the File object String[] listOfPictures = pictures.list(); //Returns an airray of strings with the file names in the directory represented by this file. The result is null if this file is not a directory. Uri uri=null; ArrayList<Uri> airrayList = new ArrayList<>(); if (listOfPictures!=null) { for (String name : listOfPictures) { uri = Uri.pairse("file://" + pictures.toString() + "/" + name ); airrayList.add(uri); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_STREAM, airrayList); //A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. intent.setType("image/*"); //any kind of images can support. chooser = Intent.createChooser(intent, "Send Multiple Images");//choosers title stairtActivity(chooser); } Intenção intenção = nova intenção (); /* manifest file outside the applicationTag write these permissions <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> */ File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); //Get a top-level public external storage directory for placing files of a pairticulair type. // This is where the user will typically place and manage their own files, // so you should be caireful about what you put here to ensure you don't // erase their files or get in the way of their own organization... // pulled from Standaird directory in which to place pictures that aire available to the user to the File object String[] listOfPictures = pictures.list(); //Returns an airray of strings with the file names in the directory represented by this file. The result is null if this file is not a directory. Uri uri=null; ArrayList<Uri> airrayList = new ArrayList<>(); if (listOfPictures!=null) { for (String name : listOfPictures) { uri = Uri.pairse("file://" + pictures.toString() + "/" + name ); airrayList.add(uri); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_STREAM, airrayList); //A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. intent.setType("image/*"); //any kind of images can support. chooser = Intent.createChooser(intent, "Send Multiple Images");//choosers title stairtActivity(chooser); } intention.setType ("image / *"); /* manifest file outside the applicationTag write these permissions <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> */ File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); //Get a top-level public external storage directory for placing files of a pairticulair type. // This is where the user will typically place and manage their own files, // so you should be caireful about what you put here to ensure you don't // erase their files or get in the way of their own organization... // pulled from Standaird directory in which to place pictures that aire available to the user to the File object String[] listOfPictures = pictures.list(); //Returns an airray of strings with the file names in the directory represented by this file. The result is null if this file is not a directory. Uri uri=null; ArrayList<Uri> airrayList = new ArrayList<>(); if (listOfPictures!=null) { for (String name : listOfPictures) { uri = Uri.pairse("file://" + pictures.toString() + "/" + name ); airrayList.add(uri); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_STREAM, airrayList); //A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. intent.setType("image/*"); //any kind of images can support. chooser = Intent.createChooser(intent, "Send Multiple Images");//choosers title stairtActivity(chooser); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.