Android Open Source - AndroidRandomWallpaper On Boot Receiver






From Project

Back to project page AndroidRandomWallpaper.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidRandomWallpaper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.elbauldelprogramador.randomwallpaper.reveivers;
/* ww w.ja v  a  2s  . c o m*/
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import com.elbauldelprogramador.randomwallpaper.activities.MainActivity;
import com.elbauldelprogramador.randomwallpaper.util.RWGlobal;

public class OnBootReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    
    SharedPreferences sharedPerf = 
        context.getSharedPreferences(RWGlobal.SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final boolean startAtBoot = 
        sharedPerf.getBoolean(RWGlobal.KEY_AT_BOOT, RWGlobal.DEFAULT_AT_BOOT);
    
    if (startAtBoot) {
      Log.d(MainActivity.TAG, "Starting RandomWallPaper...");
      
      int interval = sharedPerf.getInt(RWGlobal.KEY_INTERVAL, RWGlobal.DEFAULT_INTERVAL);
      String sourceFolder = sharedPerf.getString(RWGlobal.KEY_SOURCE_FOLDER, 
          RWGlobal.DEFAULT_SOURCE_FOLDER);
      int width = sharedPerf.getInt(RWGlobal.KEY_WIDTH, RWGlobal.DEFAULT_WIDTH);
      int height = sharedPerf.getInt(RWGlobal.KEY_HEGHT, RWGlobal.DEFAULT_HEIGHT);
      
      if (width == RWGlobal.DEFAULT_WIDTH || height == RWGlobal.DEFAULT_HEIGHT) {
        height = WallpaperManager.getInstance(context).getDesiredMinimumHeight();
        width = WallpaperManager.getInstance(context).getDesiredMinimumWidth() << 1;
        
        //Store values in preferences
        SharedPreferences settings = context.getSharedPreferences(RWGlobal.SHARED_PREFERENCES, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        
        editor.putInt(RWGlobal.KEY_HEGHT, height);
        editor.putInt(RWGlobal.KEY_WIDTH, width);
        
        editor.commit();
        Log.i(MainActivity.TAG, "in ONBOOT Updating heght to: " + height);
        Log.i(MainActivity.TAG, "in ONBOOT Updating width to: " + width);
      }
      
      AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      
      Intent i = new Intent(context, AlarmReceiver.class);
      i.putExtra(AlarmReceiver.ACTION_CHANGE_WALL_ALARM, 
          AlarmReceiver.ACTION_CHANGE_WALL_ALARM);
      i.putExtra(RWGlobal.EXTRA_PATH, sourceFolder);
      i.putExtra(RWGlobal.EXTRA_HEIGHT, height);
      i.putExtra(RWGlobal.EXTRA_WIDTH, width);
      
      final PendingIntent pIntent = PendingIntent
          .getBroadcast(context, 1234567, intent, PendingIntent.FLAG_UPDATE_CURRENT);    
      
      alarm.setRepeating(AlarmManager.RTC_WAKEUP, 
          System.currentTimeMillis(), interval * 60000, pIntent);
    }
  }
}




Java Source Code List

com.elbauldelprogramador.randomwallpaper.Service.java
com.elbauldelprogramador.randomwallpaper.activities.AboutTheApp.java
com.elbauldelprogramador.randomwallpaper.activities.MainActivity.java
com.elbauldelprogramador.randomwallpaper.reveivers.AlarmReceiver.java
com.elbauldelprogramador.randomwallpaper.reveivers.OnBootReceiver.java
com.elbauldelprogramador.randomwallpaper.util.RWGlobal.java
com.elbauldelprogramador.randomwallpaper.util.SimpleFileExplorer.java
com.elbauldelprogramador.randomwallpaper.util.StrictModeWrapper.java