How to start a Service when .apk is Installed for the first time
Fortunately, Plan B does not work on Android 3.1+, as tested on a XOOM and a Galaxy Nexus.
What Plan B does is exploit a security hole that could be used by drive-by malware, which is specifically why Android prevents it from happening anymore.
UPDATE
To clarify: As inazaruk posted and I put into comments on other answers, all applications, upon installation, are placed in a "stopped" state. This is the same state that the application winds up in after the user force-stops the app from the Settings application. While in this "stopped" state, the application will not run for any reason, except by a manual launch of an activity. Notably, no BroadcastReceviers
will be invoked, regardless of the event for which they have registered, until the user runs the app manually.
This block covers the Plan B scenario of remote-install-and-run, which they were taking advantage of previously. After all, with that, anyone with a hacked Google account would be at risk of having their device infected, hands-free as it were.
So, when the OP says:
I need to start a Service as soon as the Applicaton gets installed on the Device
the OP will be unsuccessful and will need to redesign the application to avoid this purported "need".
Start a service automatically when app installed to device
Google shows the correct answer as the first hit so ... have you done some research on this?
How to start a Service when .apk is Installed for the first time
Summary: you can't do this.
Start service on installation of app without any activity
There is no straightforward way to start a service on just installing the app, without user opening it first time. If you read the answers on the above two questions, you will get the gist.
1) How to start a Service when .apk is Installed for the first time
2) How to start android service on installation
Hope it helps you.
How to start android service on installation
You cannot do this -- there is no way to automatically start your service merely because it was installed.
The application must first be invoked by the user through some sort of activity. Or, you are going to need to hook into some relevant broadcast Intent
via the manifest, so you can get control when one of those events occur and kick off your service that way. Or, you are going to need to ask the user to reboot so your BOOT_COMPLETED
Intent
filter can get control.
Auto launching android app after install
Check this out, it addresses the exact problem that you wish to solve: How to start a Service when .apk is Installed for the first time
Starting a *newly* installed app/service from another app
In other words, is the only way to start a newly installed app (from .apk) to start it manually?
For some definition of "manually", yes.
An app that is newly installed is in the so-called "stopped state". Until something uses an explicit Intent
to communicate with one of its components, nothing of that app will run, such as manifest-registered receivers.
Typically, this is handled by the user tapping on a home screen launcher icon. However, there are other scenarios. For example, in a host-and-plugin situation, the host could be monitoring ACTION_PACKAGE_ADDED
broadcasts, to see if a plugin was installed. The host can then use an explicit Intent
to initiate communications with the plugin (e.g., send a command to a service exposed by the plugin). At that point, the plugin will behave like a normal app.
the alternative solution is to have an app that can be remotely triggered to start the newly installed service
That strikes me as having some possible security issues, but yes, you could tell App A via some network event "Yo! App B is now installed! Go use some explicit Intent
to talk to it!".
Would this work without root privileges?
Yes.
How to implement service after installing application in android
Without any user interaction you can't launch your application.
As the application is put into onStopped
state as soon it is installed on device.
(still on devices with android vs < 3.0, it may be possible, like by listening for system broadcasts such as low battery, internet state changed, new message received, or new location change.)
You may see this answer for further clarifications.
Related Topics
How to Dynamically Add Elements to a Listview on Android
What's the Difference Between Commit() and Apply() in Sharedpreferences
Detect If Android Device Has Internet Connection
Scheduling Recurring Task in Android
Adb Server Version Doesn't Match This Client
Post Multipart Form Data Using Retrofit 2.0 Including Image
Android - How to Override the "Back" Button So It Doesn't Finish() My Activity
How to Make Layout With Rounded Corners..
Can't Find Theme.Appcompat.Light For New Android Actionbar Support
Getviewtypecount and Getitemviewtype Methods of Arrayadapter
Android Studio - Google Map Still Blank on Real Android Device on Release Apk
How to Get the Build/Version Number of Your Android Application
Android Listview With Different Layouts For Each Row
Instant Run in Android Studio 2.0 (How to Turn Off)