I want to share the audio file in android using but didn't found any working solution.
In My app the app records and save the audio file named as audio_1.wav each time in the app directory and then provide the option for sharing it. So always it share the file with same name(audio_1.wav).
Also checked that it is creating the file correctly.
I tried to share the audio file with below code;
File f = new File(sharePath);
Uri uri = Uri.parse(f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));
But while sharing and selecting any app it show unable to attach File.
Also Used FileProvider Class for Nougat Devices but it didn't worked as well.
Checked multiple SO Link as well:
Sharing an audio file
Picking up an audio file android
With regards to the code that you have:
Replace Uri uri = Uri.parse(f.getAbsolutePath()); with Uri uri = Uri.fromFile(f);, to get a valid Uri
Use audio/wav, not audio/*, for the MIME type
Your code will crash on Android 7.0+ with a FileUriExposedException. Use FileProvider for that, where you use <external-path> in your metadata XML resource and add the FLAG_GRANT_READ_URI_PERMISSION flag to your Intent. See the documentation for more.
Related
I'm trying to share Google File Type (eg: application/vnd.google-apps.document, application/vnd.google-apps.form, application/vnd.google-apps.presentation, application/vnd.google-apps.spreadsheet) with the Intent.
My code:
private void shareFile(String uri) {
ContentResolver contentResolve = getContentResolver();
String mimeType = contentResolve.getType(Uri.parse(uri));
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
intentShareFile.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intentShareFile.putExtra(Intent.EXTRA_STREAM,
Uri.parse(uri));
intentShareFile.setType(mimeType);
intentShareFile.putExtra(Intent.EXTRA_TEXT, "Hey, check out this file!");
startActivity(Intent.createChooser(intentShareFile, "Share File"));
}
But when I click an apps to share that file, it doesn't respond and not do anything. Even when I'm trying to upload it on Google Drive, it says that upload is unsuccessful. The share file works fine when I share pdf or docx file.
Apparently, we can't share the Google File Type via Intent. We have to convert the file that has Google File Type to something like Microsoft File Type (application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/msword, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/x-excel, application/vnd.ms-powerpoint, or application/vnd.openxmlformats-officedocument.presentationml.presentation).
Is there any way to convert the URI mimeType so I can share a file that has Google File Type? For the example is changing a file that has application/vnd.google-apps.document as its mimeType to application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.google-apps.presentation to application/vnd.openxmlformats-officedocument.presentationml.presentation, and etc. Is there a way to do that so I can share a file that has Google File Type? Any help will be appreciated, thanks!
Do it like this:
Intent uploadIntent = ShareCompat.IntentBuilder.from(this)
.setType(mimeType)
.setStream(fileUri)
.getIntent()
.setPackage("com.google.android.apps.docs");
startActivity(uploadIntent)
Please note setStream requires Uri.
I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */
I'm trying to make an application with sharing of children that are inside the "raw" folder of the application, but I'm not getting it. The file is shared but does not have an .mp3 extension. I was not able to hear Windows Media Player, but I put a .mp3 extension manually. Does anybody have any idea how I do it to get .mp3 extension automatically? Transform / rename a URI into mp3 file.
The name of the song comes as it is registered in the file, I believe that if it was possible to rename adding the .mp3 in the end may work. But I'm not able to rename.
I am using this code:
Intent share;
Uri uri = Uri.parse("android.resource://"+this.getPackageName()+"/raw/name_musica");
share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri); share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(share, "Enviar via: "));
The documentation for EXTRA_STREAM states that it is:
A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent.
android.resource: is not content:. There is no requirement for anything that responds to ACTION_SEND to know what to do with an android.resource: Uri in EXTRA_STREAM.
Copy the resource to the local filesystem and use FileProvider, so FileProvider can give you a content: Uri to use with EXTRA_STREAM. Or, write your own ContentProvider that serves the content directly from your raw resource, and use a content: Uri for your provider.
Also, do not use audio/*. Use the actual concrete MIME type of the content that you are sharing.
I have designed two buttons.One button for selecting the file and another button for to open the selected file.I have selected the file correctly and the file path also retrieved.But i cant open the particular file directly by the file path.Any one I have tried something like this
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ selectedFilePath);
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
First, ACTION_GET_CONTENT does not accept a Uri as input.
Second, ACTION_GET_CONTENT has nothing to do with opening a file. Presumably, you should be using ACTION_VIEW.
Third, the value that you are passing to Uri.parse() is not a String form of a Uri.
Also, I would expect few Android devices to have an ACTION_VIEW activity for text/csv content.
I am new in android Java. I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
Above code is not working, it showing like this ...
is think i cant get Exact image file location. My file location
I tried bellow code also, But not work,
String imagePath = Environment.getExternalStorageDirectory()
+ "/assets/www/sharethis.png";
Please Help
Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file. Have a look here