I have a requirement to show multiple files (2 or more each of images, music or video, but only one type). Given a series of thumbnails or filenames, the user should be able to select a chekbox and preview the selection. IF the user selects multiple images, I want to be able to show ONLY those images selected. If he selects multiple mp3 files, I want to be able to play ONLY those songs.
If the user selects only one file, that's easy to do:
Intent i = new Intent(Intent.ACTION_VIEW);
if (someType == IMAGE) {
i.setDataAndType(Uri.fromFile(imageFile),"image/*");
}
else
if (sometype == VIDEO) {
i.setDataAndType(Uri.fromFile(videoFile),"video/mp4");
}
else if (someType == MUSIC) {
i.setDataAndType(Uri.fromFile(musicFile),"audio/mpeg");
}
startActivity(i);
However, if the user selects two or more of one type, how can I architect the intent to use whatever image/audio/video apps the user may have installed? Don't want to write custom players/viewers as I know an existing app can do this.
I am trying to mimic the functionality of a cloud app called "AllShare Play" (https://www.samsung.com/us/2012-allshare-play/) . This app does exactly what I need to do in my app - allows the user to "preview" multiple files and uses just the standard "Gallery" app for images, standard music app for songs, etc. In each case, only the files selected are shown or played using standard apps each Android device is loaded with, so I know it's possible to do without writing a viewer or player.
Anyone have any ideas how to send multiple files via Intent.ACTION_VIEW to an external app?
There is no android standard for send multible to ACTION_VIEW.
But there is a standard for ACTION_SEND_MULTIPLE where the files are transfered via EXTRA_STREAM.
for a working sendmultible example see Secure-Photo-Viewer: you select multible images from a gallery app and send them to Secure-Photo-Viewer.
If your app is the only sender and receiver of this intent you can use the same mechanism with ACTION_VIEW, too.
To learn more on intent communication you can use the intent-intercept app that allows sending and receiving many types of intents
here is the code i use to send multible images
Intent sendIntent = new Intent();
sendIntent.setType("image/*");
if (selectionCount == 1) {
Long imageId = mSelectedItems.first();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(EXTRA_STREAM, getUri(imageId));
} else {
sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
ArrayList<Uri> uris = new ArrayList<Uri>();
for (Long mSelectedItem : mSelectedItems) {
uris.add(getUri(mSelectedItem));
}
sendIntent.putParcelableArrayListExtra(EXTRA_STREAM, uris);
}
startActivity(sendIntent);
Related
In my application i want to open the gallery and choose an image from it. So i do
gallery.setOnClickListener {
val imageIntent = Intent().apply {
type = "image/*"
action = Intent.ACTION_PICK
}
startActivityForResult(
Intent.createChooser(imageIntent, "Select an image"), IMAGE_REQUEST_CODE
)
}
However, when i choose an image i want the user to be able to preview the image that he selected before i get it in the ActivityResult. In some devices and some apps (Google Photos) they do this by default, but in other devices i can't get that feature.
How can i have this functionality by default in every device?
How can i have this functionality by default in every device?
You can't.
You are starting an activity from a third-party app. What the third-party app does is up to the developers of the third-party app.
In some cases, there are Intent extras that provide hints as to what we want the third-party app to do. In this case, there is no standard "please provide a full-screen preview" extra. And, even if there were, there is no requirement for any given ACTION_PICK activity to pay attention to that extra.
I start a Google's gallery intent in order to let users choose an image from their gallery. My app has the status bar hidden, but the gallery intent doesn't. This does not look nice when the intents are changed so I am hoping to also hide this in the gallery intent.
public void galleryClicked(View view){
Intent intent = new Intent(Intent.ACTION_PICK);
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String pictureDirectoryPath = pictureDirectory.getPath();
Uri data = Uri.parse(pictureDirectoryPath);
intent.setDataAndType(data, "image/*");
startActivityForResult(intent, GALLERY_REQUEST);
}
How do I hide the status bar when starting a gallery intent
You don't. You control the status bar in your app. The developers of the gallery app control the status bar in their app.
This does not look nice when the intents are changed
There are ~2 billion Android devices, made up of thousands of device models. Those devices will ship with hundreds of different gallery apps (or perhaps none at all), and users can install their own from the Play Store and elsewhere. Not all of them will "look nice" from your standpoint, whether with respect to the status bar or anything else (e.g., color scheme).
If you link to a third-party app, the behavior of that app is up to the developers of that app. If you want more control than that, do not link to a third-party app, but instead write your own gallery-style UI.
I'm going to develop a simple app to list .jpg files and after a click call an Intent.ACTION_VIEW, below the code:
File imageFile = new File(filename);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(imageFile), "image/jpeg");
startActivity(i);
The intent works properly, in fact in app I receive the message to select an app to show the selected image. But I noticed that after the choice, for example with Google Photos, not all function are enabled. For example the share function is not visible, has someone already noticed this behavior?
Some other details; if I choose Google Photos I only have the "Info" and "Guide and Feedback" options. If I choose gallery app (I have a Samsung Ace 3) I have only "Info" and "Set as wallpaper" options.
Note: if I open the same image directly from Google Photos all functions are enabled...
The ACTION_VIEW intent calls another application to view the content that you present, in your case a JPEG image. If there is more than on application that can handle that Intent, Android lets the user choose an app to display the image. Once the application receives the Intent, it is up to that application to display the content how it sees fit.
Basically, you have no control over what functions are available with Intent.ACTION_VIEW. If you want more control, you can create your own Activity in which you can view the image and provide whatever functions you would like.
I'm trying to launch the Amazon Kindle app from my android application but based on a specific book that the user clicks.
I'm able to determine the books available and which book the user has selected but I have only been able to launch the kindle application (using the package name com.amazon.kindle) to launch the kindle app.
Does anyone know of any additional commands I can send to specify a book to open? I know this is possible as there is a widget on the google play store where the user selects a boo and it creates a button on the homescreen that launches the kindle app and opens the book.
Thanks in advance!
First we need to set the intent to an ACTION_VIEW intent.
Then we need to define an Uri for the data which is actually a link that looks something like: kindle://book/?action=open&book_id=AMZNID0/B000FC1GHO/0/, where in this case the section B000FC1GHO corresponds to the ID of the book.
Finally we can then start the activity. In my case I had to set some flags on the intent to launch a new activity.
The code I'm using is as follows:
if(intent.getAction().contains("BOOK_ACTION_"))
{
Log.w("LOG", "We have a book selected");
bookID = intent.getAction().substring(12);
Log.w("LOG", bookID);
Intent readbook = new Intent(Intent.ACTION_VIEW);
readbook.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri file = Uri.parse("kindle://book/?action=open&book_id=AMZNID0/" + bookID + "/0/");
readbook.setData(file);
context.startActivity(readbook);
}
I'm overriding the onReceive method in this case so that I can perform some additional steps on each book. Presumably because I'm just setting an ACTION_VIEW intent this could have been handles in the other class that does the onClickListener for the imageview that holds the book I want.
I'm writing an app that uses the camera. I want to lauch an intent to allow users to annotate the resulting image with lines and text, AND I would like to provide the user with a list of appropriate image editting apps they can use, but I'm coming across these problems:
1. Not all image editting apps appear in the list when I perform this code:
editIntent = new Intent();
editIntent.setAction(Intent.ACTION_EDIT);
Uri imageToEditUri = selectedPhotoLocation; // Uri of existing photo
String imageToEditMimeType = "image/*";
editIntent.setDataAndType(imageToEditUri, imageToEditMimeType);
startActivityForResult(Intent.createChooser(editIntent,"Edit Image"), IMPLICIT_EDIT_IMAGE);
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
2. PS Express is the only app I've found that returns the Uri of the editted image in the data.getDate() Uri returned to OnActivityResult(), with other apps the user is forced to save, remember the location, and reselect the editted image.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
Not all image editting apps appear in the list when I perform this code
Just because an app implements image editing does not necessarily mean that it is set up to allow third parties to link to their image-editing activities.
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
If you mean that you want to do this programmatically at runtime, see Jedil's answer.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
No, except for those applications that have documentation on how developers should integrate with them.
First question answer:
try queryIntentActivities
Intent editIntent = new Intent(android.content.Intent.ACTION_EDIT);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(editIntent, 0);