Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start a Service when .apk is Installed for the first time
    text
    copied!<p>In my Application I am not having any UI part, so I need to start a Service as soon as the Applicaton gets installed on the Device. I saw many links from which the answer was that its not possible but I guess it is surely possible. Just have a look at <a href="https://market.android.com/details?id=com.lookout.labs.planb">PlanB</a> Application on the Android Market that does fulfil my requirement. Below is my Manifest file how I tried, but the Service was not called at all. So, let me know what is the best possible way to start a Service when the Application gets Installed.</p> <p><strong>UPDATE</strong></p> <p>I also tried using <code>android.intent.action.PACKAGE_ADDED</code> it works fine for detecting the Package for the other Applications but not for itself.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.auto.start" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt; &lt;application android:icon="@drawable/ic_launcher" &gt; &lt;service android:name=".MyService"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;receiver android:name=".BootUpReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt; &lt;category android:name="android.intent.category.DEFAULT"/&gt; &lt;action android:name="android.intent.action.PACKAGE_INSTALL" /&gt; &lt;action android:name="android.intent.action.PACKAGE_ADDED" /&gt; &lt;data android:scheme="package"/&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload