Can android intent be used to access phone directory? - android

I am making an android app to open a file and send it back to a remote server. I know how to do this with a file hardcoded into the app but I want to make it so that it can search the phone's directory, choose a file then send it. I am wondering can this be done with an intent? Or is there any other approach that could be used?

Yes, you can do this with an Intent. You would use startActivityForResult() and specify an Intent that can launch a file picker. Now the actual Intent you use depends on which application(s) you expect will actually service this Intent for you. For example, ES File Explorer exports a custom PICK_FILE action that you can use to support a file picker. With any scenario where you rely on a third party application to provide a service, you'll want some sort of fallback in case no application can handle the Intent (such as linking to an app that implements the Intent in the Google Play store). A similar question may provide some additional Intents to try for a variety of different file choosers available.

Related

How to have an app select the intent filter from the same app

I am building multiple apps simultaneously. Each app requires to have the same imported library which I included in the Gradle like this:
compile project(':myimportedlibrary-release')
This library, in which I have absolutely no control over since its from a private source, contains an Activity which I open in my different apps using an implicit intent as required by the library. The problem is that if I have two or more of my apps on the same device, opening the library's Activity triggers an intent chooser with the Activity from all apps as choices. I could let the user select one by default, but it would be best if a certain app opening the library's Activity would just choose its own library. Would there be a way to limit the intent filtering to the current app?
I've seen how to restrict packages but then again, they all have the same. And I also cannot use android:exported since I do not have access to the library's Manifest.
Did you try using an explicit Intent instead of an implicit one? It should resolve to the one that's in the requesting app. You already know you want to open a specific activity, so I don't see why you need the implicit Intent.

Saving file using Storage Access Framework in Android

I am integrating the Document Access Framework with my cloud storage access app.
Using this documentation I have been able to access the file and retrieve it (I simply use Gmail app's attach function to check this).
I am now trying to find how to save file using the same method (Save file directly via the app to cloud storage) and I have done the following changes:
For the getRoots call,
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE);
and I have also overriden the createDocument method.
I don't see much in ways of sample code or documentation on how to do this. I also see that a bunch of apps like the "Photos" app have "Share" button that use a different method (The logs show miniShareActivity) and my app does not show up in that (It looks like it is using a different filesharing mechanism)
I am looking for information on
How to use the SAF to store file (any sample file will be great or pointers to documentation). I Am assuming it will allow the user to use the picker interface to navigate to folder and store the file.
How to get the app to show up in the "Minishare activity" list of apps to import the file into the app (It looks like it does not provide a picker interface but I still would like to provide the support so the file is saved to a default location)
The Share button you're referring to in other apps probably uses ACTION_SEND as the Intent action, rather than ACTION_CREATE_DOCUMENT that was introduced with the Storage Access Framework.
You probably want to support both, since ACTION_CREATE_DOCUMENT was only introduced in KitKat and older apps may not be aware of it. Similarly, you may want to also support Intent action ACTION_GET_CONTENT for read access on pre-KitKat devices (ACTION_GET_CONTENT is handled by the SAF when running on KitKat+, but your app still needs to handle it when running on a pre-KitKat device). Are the <intent-filter>s in your AndroidManifest set up to match all of those Intent types?

Share pdf file via my application on android

Hi I have to develop an application which should enable sharing of pdf files. I have to create a service wich puts my application as default for .PDF file sharing. As you can see on the picture I can share the pdf via bluetooth/Gmail/Drive...etc. I need to put there my application to. How can it be done? thanks :)
http://www.vogella.com/articles/AndroidIntent/article.html
Go here, then check
4.3. Example: Register an activity for the share intent
You need to register it as a reciever for the SEND action. An example is given here. The mime type for pdf is 'application/pdf'.
I think you cannot force that, its totally on android system, thats why it pushes for a chooser with all the apps that has registered themselves as handler for specified data type, following which user can mark it as default or not.

Open android package installer upon download of .apk file

Is there any way to signal Android OS to open the package installer upon download of an .apk file?
Perhaps by Content-Type? or maybe an APK specific url protocol, like apk://apk.location?
Are you doing the download yourself in your own app, or are you trying to create some behavior in an external app?
I don't think you'll be able to trigger behavior upon download outside of your app (since the user would have to select the downloaded file in order to open it), but if you're handling the download yourself, I think you want this post on how to install an application programmatically.
Edit: Addressing your comment in which you said you are writing a website and want to be able to force the APK to be opened by a native app: I can think of a way to do something like it, but you would have to handle the download in the native app because you won't get the browser to do the download for you.
You'll need to register your native app to receive ACTION_VIEW Intents with URIs in whatever format you choose; I recommend using something like yourappname://localhost/escaped_download_url_to.apk. In your Activity get the path from the URI in the Intent and grab the last part of it (URI handling is broken into a few components: protocol, host, and path). Unescape it as necessary and then start the download manually in the app, and then upon completion you open the downloaded APK from wherever your app put it, using the link I provided.
So long as you make sure your mobile website provides an href to yourappname://localhost/escaped_download_url_to.apk, you'll be able to trigger this behavior. When the user clicks that link, it should provide a dialog to choose which app to use to open it (if they have more than one app capable of doing so) which when they select your app will launch the Activity that you registered with the Intent filter.
Edit the second: you probably don't need to do any escaped URIs; just using a made-up URI protocol as you suggest in your own post should work, so long as your app registers to receive Intents with that protocol. yourappname://yourserver.com/my/location.apk will work. All that really matters is being able to pull the download URL out of the data you give to the app in the URI.

How to include external android application activity (or external application entirely) as a dependency of a main application?

I understand that intents can be used to employ external activities to accomplish specific tasks, my question is whether those called external activities can be included within the project itself.
For example, if I wanted to include check-in functionality to my application, and knew that google plus has this great check-in activity, would it be possible to include that specific check-in activity for use in my application?
You need the intent of that activity. I think if you have installed G+ app, you need to iterate through the list of Intents you have installed and find the matching one.
List<ResolveInfo> IntentsList= getPackageManager().queryIntentActivities(new Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0);
PackageManager.PERMISSION_GRANTED = 0 in the addCategory
The 1st argument of addCategory() method varies whether the intent category is CATEGORY_LAUNCHER, CATEGORY_ALTERNATIVE or most likely your required intent to be CATEGORY_DEFAULT. If you know the intent name then you might be able to call it in your activity, also adding it to you manifest as activity in your application.
The short answer is yes, if you had the library project for the external app you want to use. This generally not the best solution because if you could get the source (a big if) and then the user downloaded the app then you'd have to choose which app to complete the intent with (if you didn't use explicit intents) plus you'd have to update your own app when theirs is updated. All this creates overhead on you. An alternative would be to follow the example of the Text-to-Speech library. The Android O/S doesn't come with one preinstalled so whenever the functionality is requested the user is prompted to download the related library. Just uninstall Pico TTS and you'll see what I mean.

Categories

Resources