How to programmatically access installer service in android? - java

I have struck an idea of creating an app that automatically installs all the .apk packages placed inside a particular folder. In context to this, I want to learn how do I programmatically access installer service ?
Please enlighten me in this regard.

Your best bet would be to set an intent with type application/vnd.android.package-archive and then start installer activity:
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file:///path/to/your.apk"),
"application/vnd.android.package-archive");
startActivity(promptInstall);
Check out Install Application programmatically on Android
Also, note, that for security reasons, you cannot install an apk 'silently' or automatically without user agreement. Therefore, the best you can do is like above.

Related

How can I create an app which deletes itself?

How can i write a function that can remotely self-destruct it, ie delete that application from the phone?
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.myapplication"));
startActivity(intent);
This code does not work on Android 10+
You can purge application files by enumerating app directory and deleting everything in there plus removing your application files on SD card. Uninstalling application itself is a different beast altogether. Non system apps cannot do that AFAIK (starting from android 2.0?).

Uninstall APP using its APK

I need to trigger an uninstall of a certain app from within my own app. The only thing i have is the apps apk, even tho it doesn't have to be the same version as the installed app.
The uninstall would be handled by android of course. Just like installing an app from a given apk file.
Is there a way how i can put together an intent to make android open the responsible system service and and ask the user to uninstall or something like that?
The app to be uninstalled can change, so i can't use a constant packagename or something like that.
Is there some way to do this? I know you can extract the packagename from an apk, but it seems like a lot of work and probably overkill.
Using Intent.ACTION_DELETE intent
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.mypackage"));
startActivity(intent);
You can get your own package name from context;
getApplicationContext().getPackageName();

Open Another App with android.intent.action.VIEW

I want to open another app and open a specific page in it!
in their guide they said to use the bellow for default action
android.intent.action.VIEW
and use a kind of intent, which didn't get which, like bellow to go to that specific page:
somecompany://details?id=com.example.calendar
but i don't know how!
And i tryed a ton of solutions but coudn't do it !
Thanks for your help.
I think this is what you're asking for. This will open a specific app's page in the Google Play store.
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(
"market://details?id=com.mycompany.mypackage")));
Don't replace the word market. That is specifically reserved by Android to open the Google Play store.
You can launch an app using intents. But to go to a specific page in the app, there should be a pre defined intent to reach there. Either it can be custom intent defined by that app and exposed to others or may be predefined system app. For example, you can open Settings application and reach a particular page in it based on the intents "Setting Application" has defined. Another example is "Camera Application". You can launch it and reach some page in it but not all pages.
In your case you may try something like this though:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/mp4");
I hope you understand what I meant.

Launching system and third party apps in android

I have searched ALOT now, i cant find a solid way to run apps like calendar, camera, facebook, twitter, insatgram, and all kinds of apps in android. I know that i need to use intents, but HOW can i do it? I really need help! Please help me and thanks alot!
There is no such concept in Android as "run apps". You start activities. Talented developers do not focus on specific apps (e.g., "facebook, twitter, insatgram"), because those apps may not exist on any given device. Instead, you focus on generic capabilities (e.g., use an ACTION_SEND Intent with startActivity() to share something, create a launcher by using PackageManager to find those activities that support ACTION_MAIN and CATEGORY_HOME).
If you want to launch some other application from your android application then you should know the package name for that particular application For example for launching facebook use
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
Otherwise this can also be used
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
If you want to launch the default android applications installed for some particular kind of operation then you can use implicit intents for that. For example to start a browser you can use
Uri webpage = Uri.parse("http://www.android.com");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);
You should take also take a look at intents and intent filters and how to allow other apps to open your application.

How can I load an apk dependency from the android market?

I'm using google moderator as a simple way to collect feedback for my application. There's a google moderator app on the market that provides a better interface than the website for mobile users.
Getting to the point: Is there a way to get it to install along with your application or a reasonable way to identify if another package is available so I can direct users to the market to download it?
Is there a way to get it to install
along with your application
Not automatically, no.
a reasonable way to identify if
another package is available
Use PackageManager. Create the Intent you would use to start the third-party activity and use queryIntentActivities() on PackageManager. If you get an empty list back, nothing is installed that will respond to your Intent.

Categories