Open android package installer upon download of .apk file - android

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.

Related

Can android intent be used to access phone directory?

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.

Android-How prevent manual installation of android application

I have an application A that launches an intent to install application B(which is present in app A's data folder).
Once application B is installed, file managers like ASTRO can backup Application B's apk file.
So I want to prevent the user from manually installing it(say if he clicks on the backup apk file of Application B it should not install).
Is there a way to disable manual installation...?
But there are two ways to monitor the app.one is, you can use File Observer to
monitor the apps. whenever the apps been taken as back up do stuffs to prevent it. Another way is
For eg: if it's storing in sdcard\am\ use like this.
File f=new File("\mnt\sdcard\am\abc.apk");// file location of your app
{
if(f.exists)
{
f.delete();
}
}
For File Observer,have a glance of this.It might help you.
http://developer.android.com/reference/android/os/FileObserver.html
Can you find the location where the backup is taken and delete the apk.
If APk is available to the file manager then it can open it and install it, I am not aware of any way to stop it as its out of your application scope.
This isn't possible on AOSP Android.
The Install from unknown sources option is a setting in Settings.Global (previously in Settings.Secure) and cannot be controlled by third party applications.
However, it is possible do achieve this if you're willing to modify and compile Android itself for each and every device you want to use this on, as is done by AT&T on some of their devices.
The best you can do is try to find the backup file and delete it if you have access to that part of the storage.
Not sure if it's feasible, but I would solve this by having application A spit out a code that has to be manually entered (like a two step verification) on application B is installed, and then verify it server side. So that way the rogue install like you mentioned would be rendered useless. Maybe you could pop up an error to the user informing them of this.

Android application's exposed API or hooks

What is the best way to discover an Android application's API or hooks into/from the application?
Specifically, I am looking to pass a parameter or data to an application, utilize the application's specific functions, and return data or a parameter to the calling application.
A few ideas come to mind, but I am unfamiliar with what is available, specifically to Android.
Contact an application's developer directly
Somehow decompile the APK to browse the source
Read any available documentation
Some ways to check out what is available for :
Tool to re-engineer closed APK files
http://code.google.com/p/android-apktool/
Review intent filters for actions
Lookup the app in some sort of application manager on your phone. Android System Info. If you go to the details of the app it will tell you where the apk is and the name of it. For instance, under the Email app you can see "Source: /system/app/Email.apk".
To pull that off just do "adb pull /system/app/Email.apk Email.apk", to pull it to your current directory.
Look at the Manifest.xml. Rename the apk to zip and unpack.
Follow the instructions here: http://android.amberfog.com/?p=582
Then you can read the decompiled Manifest.xml and look at the intent filters they are registering.
Android applications are all in their own sandbox, so you can not just arbitrarily call some other Android applications' functions, they would need to be made public to you somehow.
If you are looking to execute some function that is provided by another Android application, you would most likely need to hear about it from the developer, most likely from their public documentation if they have any.
The correct way to do this is to use "intents". With an intent, you can launch another application (such as a barcode scanner) and the user interacts with it. Then, the application exits returning some data (such as the barcode). Try googling or see:
http://www.vogella.com/articles/AndroidIntent/article.html

How to list the data types that android application operates with?

In the scenario that I made up a user chooses an application and and I offer him/her the available pieces of data to operate on.
For example:
if the user chooses to open a pdf reader application - I want to offer him the available .pdf files?
or if the user select some music player I want to offer him the music files he/she has stored.
I agree that it is a strange use-case, but I got pretty curious about it.
I know that the possible data type for an application is specified in its manifest file and I suppose that this information is available, but I have some difficulty finding out what the data content type for application is?
I'm not sure exactly what you mean by data content type for an application.
Applications are released as APKs.
When you wish to open up a pdf or other type of file a broadcast is sent to the system.
In this broadcast is an intent and that intent stores the action and the data type of its content (including the content or path to it).
The system then looks through all the IntentFilters for an application that claims it can perform the given action on the given data type. If there are several it than asks you to store the preference.
On the other hand, if you are trying to find all the pdf files, than you don't you scan the storage to all files ending in .pdf
Does this answer your questions?
Nope, :) not at all.
I'm aware of how android handles a requiest for opening a particular file.
What I want is exactly vice-versa!
For example
- the user says I want to open MyPDFReader app.
and I ask him/ her:
- ok - you have one.pdf and two.pdf available - would you like to open some of them with MyPDFReader, or you will start it without pre-selected pdf file?
and that information I'll put in the intent to call MyPDFReader.
But before I offer files for opening to the user - I have to know which (what type of) files to seek for, because it would be inappropriate to ask the user whether he/she would like to start their PDF reader app with an .mp3 file
in fewer words - Is it possible to find what is the content data type that an application can start with and if you, friends, please - can you give me a clue how to sort it (the content data type) out?

Find out which browsers are installed?

I'm looking for a way to find out which browsers are installed on the Android Smartphone and their package names.
Why do I need it?
Well basically, my App reacts on certain URLs, i.e. http://bit.ly, so when the click such an he will get an choice in which App to open it. So far everything is working as intended.
If the user sets up this app as default for this kind of links, it will always open in this one without further asking the user. So far so good too. But by doing this, he will be completely unable to open this links in his browser.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user has set to be default for http/https scheme for example (as user can change it if there is more than 1 browser installed).
Sending the intend with
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
should't be a problem I think. The problem is, I can't send a standard intent für URLs, because my App would catch it again if set as default by the user.
should't be a problem I think
Hardwiring in the package and class names of code that is not yours is always a problem.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user
has set to be default for http/https scheme for example (as user can change it if there is more than 1
browser installed).
Use PackageManager and queryIntentActivityOptions() to filter your activity out and get a list of other activities that the user can choose from.

Categories

Resources