I want to share image to snapchat but giving me "Sorry! You can only share images and videos"
I tried this code but doesnt work Android share image on snapchat
I have this intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.snapchat.android");
int n = Integer.parseInt(number.getText().toString());
Uri uri = Uri.fromFile(new File(db.getimage(n))); //This is retrieving the Uri path from DB
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Open Snapchat"));
the type that you are setting for the setType method is not correct,
if you want to support any format of Image, I suggest you first get the format of Image And after that pass the correct parameter to the setType() method.
for getting a file extension you can use this link:
link
For sharing data in snapchat, there is a kit available in their official website called Creative Kit.
Also you can find the Doc and Tutorials here.
Related
I'm trying to upload a file by copying it from mobile app to server app running on windows.
I used a file chooser to let the user select the file:
public void openFile(View view) {
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select file"), LEARN_TREE);
}
Then i got the uri from the intent of onActivityResult.
First question here is why it displays a file named "servo.dat" as numbers (in this case it shows "5889")?
After that I put the uri as an extra into another intent and use that intent to start another activity.
In the second activity I retrieve the uri.
Now I'd like to use FileInputStream to read bytes from my file in order to write them to the ObjectOutputStream created from Socket.getOutputStream().
Here is where it doesn't work. Basically the path provided here
FileInputStream fis = new FileInputStream(uri.getPath());
is incorrect. If I check on my device the file location is Download/servo.dat, the Uri in the app shows Download/5889 and the absolute path that I tried retrieving using a UriUtils library found online shows storage/emulated/0/Download/servo.dat but this one doesn't actually exist on my phone.
I think it's not so hard but I'm getting confused since I'm new to both Android app development and Android itself, please help!
I'm open to any good solution, I saw online there is the ContentResolver class that should be helpful but I didn't manage to understand how to use it :|
First question here is why it displays a file named "servo.dat" as numbers (in this case it shows "5889")?
Because it is not a file. It is a piece of content, and you are attempting to treat the path portion of a Uri as a filesystem path, which is is not.
If you want a display name for the content:
Call DocumentFile.fromSingleUri(), passing in your Uri, to create a DocumentFile
Call getDisplayName on the DocumentFile
Basically the path provided here is incorrect
That is because you are trying to treat the path portion of a Uri as a filesystem path, which it is not.
To get an InputStream, call openInputStream() on a ContentResolver, passing in your Uri. See the documentation. So, for example, from a method in an Activity, you would use InputStream inputStream = getContentResolver().openInputStream(uri);.
I'm getting confused since I'm new to both Android app development and Android itself
You may wish to consider reading a book on Android app development or taking a course in Android app development.
In my app I need to share *.json file to other app (messenger, google disk, etc). How can I do this via Intent or something else?
But when I trying to do this via Intent, I have some problems.
override fun shareBackupData(path: String) {
val uri = Uri.parse(path)
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.type = "*/*"
startActivity(Intent.createChooser(shareIntent, "Choose"))
}
When I run this code, I choose app to share and then I see toast "unsupported attachment"
I had similar problems with this and I found this article where it recommends us to use FileProvider.
What it does is :
FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content:// Uri for a file instead of a file:/// Uri.
I recommend you to take a look to the article and also if you want code, take a look at this Stackoverflow post
i think you can use the file as ExtrtaStream the following code is sharing image file you can change it to your json file
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");//change it with your file
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
I'm using ACTION_GET_CONTENT so that the user can select text files that the rest of my code can read and deal with.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
startActivityForResult(Intent.createChooser(intent, "select data"), SELECT_DATA);
Above is my code so that the user can browse which works fine.
Uri DataUri = data.getData();
File FileUri = new File(DataUri.getPath());
If I convert DataUri or FileUri to a string after using getPath or getAbsolutePath, I get a completely wrong path.
The path should be /storage/emulated/0/Documents/myFile but it gives me /document/primary:Documents/myFile. I have no idea what this "primary:Documents" thing is.
The data from the intent itself already has the wrong path, any suggestions?
I'm using ACTION_GET_CONTENT so that the user can select text files
No, you are using ACTION_GET_CONTENT so that the user can select some content that has a MIME type of text/*. Where that content comes from is largely up to the user. It may or may not be a file on the filesystem, and if it is, is may or may not be a file that you could access yourself directly (e.g., internal storage of the Dropbox app, files on removable storage on Android 4.4+ devices).
The path should be /storage/emulated/0/Documents/myFile
No, it should not.
but it gives me /document/primary:Documents/myFile
What you get will vary by whatever activity handles the ACTION_GET_CONTENT request. What that activity is will depend on what the user has installed that supports ACTION_GET_CONTENT and what the user chooses out of that list of installed stuff.
Usually, you will get a content Uri (i.e., getScheme() on Uri will return content), as the Uri will point to data being served by a ContentProvider.
The data from the intent itself already has the wrong path
It has the correct path. It is simply not a path on the filesystem.
any suggestions?
Use a ContentResolver and openInputStream() to get an InputStream for the content represented by the content Uri.
I recently noticed that when sharing an animated .gif that I generate from my app, the official Twitter app will only share it as a static image.
Previously, I thought everything was working because when I shared the same type of animated .gif with an unofficial Twitter app (Tweetcaster), it properly shared it as an animated .gif.
The thing I'm questioning is whether this is an issue on my end or with the official Twitter app? I ask this because when sharing an animated .gif from the Android Gallery with the official Twitter app, it is also posted as a static .gif.
Here's the code in question:
public void shareGif(String path)
{
File file = new File(path);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/gif");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Choose a sharing option"));
}
I was having the same issue as you. I was loading URIs from the drawables and for whatever it was not animating.
I fixed my problem by implementing a custom file provider and loaded GIFs from the assets folder.
Also it was very important to add this flag intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Twitter supports looping GIFs. If your animated GIF doesn’t loop and plays a single time, it will display as a static image.
Hi I'm working on an app where I need to list all types of applications able to open a file. If the file were an image I would do something like this normally to show all applications capable of viewing the image.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "image/*");
context.startActivity(intent);
However say I have an unknown file how could I list all applications able to view a file so the user can select the appropriate application to open the file in my application.
I also need the titles listed in an arraylist if possible so I can list them in a listview.
Thank you for any help with getting a list of applications capable of viewing a file
===================================
Edit
Alright well something easier how can i get the applications from the above intent into an arraylist i could just do image/* audio/* etc and add them all to a list and then list them in a listview and that would solve my problem
As far as i know there is no API in android that links files to a program like in windows. Your best choose I'm afraid is to build a database of known file types and program/android app linked to them.
Okay well i figured my problem out what i was looking for was
Intent audioIntent = new Intent(android.content.Intent.ACTION_VIEW);
audioIntent.setDataAndType(Uri.fromFile(Opener.file), "audio/*");
List<ResolveInfo> audio = packageManager.queryIntentActivities(audioIntent, 0);
for (ResolveInfo info : audio){
String label = info.loadLabel(packageManager).toString();
Drawable icon = info.loadIcon(packageManager);
String packageName = info.activityInfo.packageName;
String name = info.activityInfo.name;
iconlabel.add(a.new HolderObject(label, icon, audioIntent, "audio/*", packageName, name));
}
But the main thing in the code above is the queryIntentActivities method that was what solved my issue allowing me to add those apps to a list
This may help you to list the application that are capable of opening a particular file.
// extension : The file extension (.pdf, .docx)
String extension = filePath.substring(filePath.lastIndexOf(".") + 1);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
if (null == mimeType) {
// Need to set the mimetype for files whose mimetype is not understood by android MimeTypeMap.
mimeType = "";
}
File file = new File(filePath);
Uri data = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(data, mimeType);
context.startActivity(Intent.createChooser(intent, "Complete action using"));