1

How do i start my application on startup in case when application is installed on SD card? If i application is installed on Internal memory then using BOOT_COMPLETED completed broadcast we can achieve our requirements but this BOOT_COMPLETED intent is broadcasts before the media is mounted so we can not use this broadcast.

What i tried so far is, i used the another intent which is MEDIA_MOUNTED but don't know why broadcast is not being received.

Here is my code:
AndroidManifest.xml

<receiver
            android:name=".ui.Receiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_MOUNTED" />
                <data android:scheme="file" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
                <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REPLACED" />

                <data android:scheme="package" />
                <data android:path="org.sipchat.sipua" />
            </intent-filter>
        </receiver>

Receiver.java

public void onReceive(Context context, Intent intent) {
        String intentAction = intent.getAction();
        if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {
            Toast.makeText(context, "BOOT Completed", Toast.LENGTH_LONG).show();
            on_vpn(false);
            engine(context).register();
        } else if (intentAction.equals(Intent.ACTION_MEDIA_MOUNTED)) {
            Toast.makeText(context, "Media is Mounted", Toast.LENGTH_LONG)
                    .show();
            engine(context).register();
        } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
                || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
                || intentAction
                        .equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)
                || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) {
            engine(context).register();}}

Any help and suggestion will be appreciated
Thanks

Juned
  • 6,290
  • 7
  • 45
  • 93

1 Answers1

0

The application start at when the device boot up will works in android version below 3.0. For more information refer this post Link 01

Community
  • 1
  • 1
Aerrow
  • 12,086
  • 10
  • 56
  • 90
  • Its not true boot completed is works fine in ICS too. But here my question is not about `BOOT_COMPLETED` its about `MEDIA_MOUNTED` – Juned Oct 04 '12 at 11:00
  • @juned: Once you restart your device, if your application get run? – Aerrow Oct 04 '12 at 11:20
  • Yeah it runs when its in internal store but while in external storage its not – Juned Oct 04 '12 at 11:34
  • @juned: Can you please guide me, because i need this exact feature in my application i tired but i failed. – Aerrow Oct 04 '12 at 11:42
  • yeah,why not. so in your application intent doesn't broadcasts the BOOT_COMPLETED in the devices which has the version 3.0 and higher – Juned Oct 04 '12 at 11:55
  • @juned: If i add android:installLocation="internalOnly" this in my manifest means, if it work? I used the same code which i mentioned in Link 01, but it won't work – Aerrow Oct 04 '12 at 12:00
  • checkout this [click here](http://code.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/Receiver.java#691) i am using the same. yeah and if you didn't got anything then let me know – Juned Oct 04 '12 at 12:06
  • @juned: Hey man, thanks for your Valuable help,i add that key work in manifest it works great. thanks once again. – Aerrow Oct 04 '12 at 12:07