Question

wallpaper in that i am showing data from database, which is actually in SDCARD

-so first if i want to access data from sdcard i have put some condition

       if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {

it's working fine, now when i restart my device, at the startup time of my device, my wallpaper is want to access database, so it will first check above condition, but it will return FALSE

May be SDCARD is mounted after some time of starting of ANDROID OS...

so can anybody suggest me how to resolve that issue, because of large size of database i have to put it on SDCARD

Was it helpful?

Solution

May be SDCARD is mounted after some time of starting of ANDROID OS

Yes Right, so register action.MEDIA_MOUNTED BroadcastReceiver to get broadcast when sd-card is mounted.

First Register BroadcastReceiver in AndroidManifest.xml :

  <receiver
    android:enabled="true"
    android:exported="false"
    android:name=".ExternalStorageInfoReceiver">
    <intent-filter> 
            <action android:name="android.intent.action.MEDIA_MOUNTED"/> 
    </intent-filter>
  </receiver>

In ExternalStorageInfoReceiver do your work inside onReceive method:

public class ExternalStorageInfoReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
       //change wallpaper here....
    }
}

OTHER TIPS

If your application is stored on External storage then you should provide following intent filter,

<receiver android:name=".YourBroadcastReceiver">
      <intent-filter>                
           <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />                
           <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
</receiver>

See App Install Location.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top