Android open source activity to let the user select/create a media? - android

In my open source app, I want to let users insert a picture/video/sound/etc. The user can either select an existing media from the SD card or use the device's hardware (take a photo, record a video, record a sound, draw on touchscreen) if they prefer to create a new media.
There are plenty of code snippets showing how to implement each of these things, but rather than re-inventing the wheel, is there a library that handles the whole activity of choosing a media file? I would just call this library, it would handle the UI, and return me the filepath to the media the user selected/created.
Here is how it could look like:
I am sure many apps would find this widget useful (CMS authoring, wysiwyg, sharing apps, rich chat, ...). As an LGPL (or public domain) component, I am sure it would be popular and gather a community of developers. Before I launch this project, is there already such a gadget?

I wrote a small Android Library Project, called aFileChooser, that aims to streamline the selection part of this process. It includes a built-in file explorer, and returns a File object after selection. You can also retrieve the image or video thumbnail, and use helper methods to get the URI and path.
Disclaimer: I haven't had a chance to test this with ICS, but it should function properly.
https://github.com/iPaulPro/aFileChooser
Finding an all-in-one solution with capture may not be as easy, as this is one of the areas where fragmentation is real.

For taking a picture, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult(intent);
For taking video, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.ACTION_VIDEO_CAPTURE );
startActivityForResult(intent);
For recording audio, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION );
startActivityForResult( intent );
You, of course, would have to design the Activity to pick which action they would like to perform. See the linked documentation for retrieving the file path when the Activity returns.

OI File Manager for Android is an open file manager that seamlessly cooperates with other applications http://www.openintents.org/en/node/159

Related

Share Email intent or Generic message intent

I have 2 types of Intents for sharing. One for simple generic messaging like SMS/Slack etc. and Another one for email. What I can't seem to figure out is how to make where I can find a way to resolve what someone has chosen via the chooser and use the appropriate intent.
(This would be done via pressing the share button and all send options would show in the chooser
Any help with this would be awesome.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
Intent chooser = Intent.createChooser(shareIntent,"");
My thought was when resolving the chooser I could see if it was an email type but that doesn't seem to work either.
Once you have fired off an Intent, control of what happens is outside your control. The chooser will not provide a callback to your app once the user chooses an action- instead the system will pass the intent you launched on to the selected application.
As discussed in How to filter specific apps for ACTION_SEND intent (and set a different text for each app), if you want to customize the chooser you have a few options. You can:
Use Intent.EXTRA_INITIAL_INTENTS to surface other intents in addition to the default option.
Create your own custom chooser that provides the behavior you want
The first option may not be ideal because the ordering of options might not be want you want.
The second option provides much more control, but is a lot of work to maintain, particularly if you want newer platform features like directly sharing with a contact.
Another option would be to change your UI to offer separate "share" and "email" options, then use the default intents for each.

Why does an "Intent Selector" exists, what is it used for?

Android's Intent class provides an API called setSelector. I am trying to understand it from the example given in the documentation.
I want to ask that why did Android need to add this API ? What was breaking in Intent before this API ?
My understanding from reading the references is that the problem this API is intending to solve is where you want to send a launcher intent for an app that meets some general restrictions. Say you want to match all apps that open .mp3 files, but you don't want to actually open an mp3 file, you just want to launch an app that supports that. In that case, you could create a generic ACTION_MAIN, CATEGORY_LAUNCHER intent, and set the selector to an intent with an mp3 mime type or data URI.
Before this API there would be no way to do that - if you wanted to target an app that supports opening mp3s, you would have to send an intent for an mp3, which could either cause music to start playing, or cause the music player to throw an error. Also, depending on the music player's launch mode, the launcher intent may return to an existing instance of the music player, while the mp3 intent might create a new one.
According to my understanding, it gives choice to user which intent he wants to select. In that documentation they have given that it gives selection of intents whether user wants to open app's main activity or wants to launch any diff app/activity other than user's app. This is what i understood from that documentation. Check this links for your reference : https://code.google.com/p/android/issues/detail?id=67162 & http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/android/content/Intent.java#Intent.setSelector%28android.content.Intent%29

Adding Image To System Content Provider From Camera Intent

At the moment my app has a service running which is fired every hour. This pulls any photos thats have been taken since last time it was open and uploads then to the server. This is done using the system content provider
Now what I want to do is send an intent to open the camera app, I am doing this like so...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
What I would like to happen is when the focus comes back to my app (after the user has taken a picture), I can open the service and that takes care of the photo.
However it seems like the photo is never added to the content provider. The service opens it and the cursos has a count of 0. Is there anything i can do so the system adds the photo to the content provider or do I need to handle this myself?
Edit
So I figure there no intents I can use to get it to save to the system. So it would seem my options are either
contentResolver.insert()
or
MediaStore.Images.Mediea.insertImage()
What is the difference between these 2 methods?
Edit
So I am starting to think google are clueless with there implementation of this feature. Take this link
http://developer.android.com/guide/topics/media/camera.html#intent-receive
You pass in the Uri and when it returns to your app it gives you the uri you gave it. If you did not specify a uri it doesn't return one. What is the point in that? Why would I want data I already have? Surely it would make sense the other way around. Or even just giving you basic data you need such as name, path, mimetype. Would that be too difficult?
Notify MediaScanner, when the scan is complete your photo will be added to the system database.

What does an Android Intent do with its URIs?

Reading through the document and a couple others, none really specified what an Intent does with the URI that it is passed. I'm simply curious as to what happens when it gets a URI. I know it depends on the scheme, so if the scheme was http, does it then attempt to open that web URI?
I ask since I'm trying to consume RESTful API that sends data back in JSON format. Having it open the URI for me when trying to pass the data from one Activity to another rather than making the HTTP call myself via HttpClient would be nice. Not a big deal but I was just curious if that is how works.
An Intent is just an object ... it does nothing with the URI. An Intent is used in function calls like startActivity(), sendBroadcast(), etc.
For example, when you pass an Intent to startActivity(), that Intent object is made available to the Activity. The Activity can interpret the URI as it pleases.
Android also uses Intent Filters to help route intents to various installed activities, these intent filters may inspect the URI.
Review http://developer.android.com/guide/components/intents-filters.html for all the info.
It's not entirely clear what you mean, however the behavior of Intents is basically dictated by the Android package manager. You can think of an Intent as being a procedure call: you specify someone to handle the Intent, along with some additional data (parameters), possibly some category, etc...
The Android package manager looks at your intent and basically asks the question "what app on the system is prepared to consume and handle this intent?" The system then opens up that app (if it is not already resident in memory), and then throws the intent at the app. Note that there are cases where there exist some possibility of ambiguity among intent handlers: multiple apps could be prepared to handle the intent. You can sometimes see this in the form of the user being asked to select what app should handle the intent (and the user can select a default one).
The dynamic semantics of how intents are handled depends, of course, on the set of apps installed on the system, and may change depending on the type of app installed. It sounds like, in your case, you are mostly concerned with intents that have an ACTION_VIEW action associated with them. In the general case, things that look like URLs will be "caught" by the browser (though there is no guarantee that this be the case!), and the package manager will look at the structure of the URI and say "hey, this looks like it should be handled by app X," I'm going to send this URL to it. (And, of course, new apps can change this behavior by registering other intent filters..)
An intent is an abstract description of an operation to be performed.uri specific data that intent has to do operation on it:
Intent Structure
The primary pieces of information in an intent are:
action: The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
data: The data to operate on, such as a person record in the contacts database, expressed as a Uri.
Some examples of action/data pairs are:
ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1".
ACTION_VIEW tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is
considered the most reasonable thing for a particular URI.
ACTION_VIEW content://contacts/people/ -- Display a list of people, which the user can browse through. This example is a typical
top-level entry into the Contacts application, showing you the list of
people. Selecting a particular person to view would result in a new
intent { ACTION_VIEW content://contacts/N } being used to start an
activity to display that person.
So you can see that same Action with different data/uri perform different Action on data operate on.

Launching a pdf asset from android menu?

I have included a file called "Manual.pdf" in my assets folder. I have created a menu button called "Help". I want the user to be able to go to the menu, press on the Help button, and launch the Manual.pdf file in whatever viewer the phone has installed.
I have read for a few hours on this site and other sites, but I just can't get the file to launch.
Thanks for any help.
There is no unified PDF reader for Android Devices. I assume that in the course of your research you would have found that, you could use an implicit intent to invoke a pdf reader if it does exists.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
intent.setType("application/pdf");
It works in some devices and fails in some other devices. ( so please check availability of intent using the package manager). If you are targeting a particular device then you could get the corresponding Activity Object and use an Implicit Intent.(com.htc.pdfreader for HTC Phones).

Categories

Resources