title: How do I set my android studio project as my phones background?
body: <p>I have created an android studio project that contains a countdown until Christmas. I use two images to create the background and the outline for the countdown timer. I have made the application look nice and I was wondering if there is any way to set the project as my phone's background and if it is possible how to do it. The code below is how I set the timer and give it its value. Is there anything I need to change to make this possible?</p>
  <pre><code>package com.example.holidaycountdown;
  
  import android.app.WallpaperManager;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.os.Handler;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  public class MainActivity extends AppCompatActivity {
  
      private TextView txtTimerDay, txtTimerHour, txtTimerMinute, txtTimerSecond;
      private TextView tvEvent;
      private Handler handler;
      private Runnable runnable;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          txtTimerDay = (TextView) findViewById(R.id.txtTimerDay);
          txtTimerHour = (TextView) findViewById(R.id.txtTimerHour);
          txtTimerMinute = (TextView) findViewById(R.id.txtTimerMinute);
          txtTimerSecond = (TextView) findViewById(R.id.txtTimerSecond);
          tvEvent = (TextView) findViewById(R.id.tvhappyevent);
          countDownStart();
  
          Button button = (Button) findViewById(R.id.button);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  setWallpaper();
              }
          });
      }
      private void setWallpaper() {
          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper);
          WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
          try{
              manager.setBitmap(bitmap);
              Toast.makeText(this, &quot;Wallpaper set!&quot;, Toast.LENGTH_SHORT).show();
          } catch (IOException e) {
              Toast.makeText(this, &quot;Error!&quot;, Toast.LENGTH_SHORT).show();
          }
      }
      public void countDownStart() {
          handler = new Handler();
          runnable = new Runnable() {
              @Override
              public void run() {
                  handler.postDelayed(this, 1000);
                  try {
                      SimpleDateFormat dateFormat = new SimpleDateFormat(
                              &quot;yyyy-MM-dd&quot;);
                      // Please here set your event date//YYYY-MM-DD
                      Date futureDate = dateFormat.parse(&quot;2020-12-25&quot;);
                      Date currentDate = new Date();
                      if (!currentDate.after(futureDate)) {
                          long diff = futureDate.getTime()
                                  - currentDate.getTime();
                          long days = diff / (24 * 60 * 60 * 1000);
                          diff -= days * (24 * 60 * 60 * 1000);
                          long hours = diff / (60 * 60 * 1000);
                          diff -= hours * (60 * 60 * 1000);
                          long minutes = diff / (60 * 1000);
                          diff -= minutes * (60 * 1000);
                          long seconds = diff / 1000;
                          txtTimerDay.setText(&quot;&quot; + String.format(&quot;%02d&quot;, days));
                          txtTimerHour.setText(&quot;&quot; + String.format(&quot;%02d&quot;, hours));
                          txtTimerMinute.setText(&quot;&quot;
                                  + String.format(&quot;%02d&quot;, minutes));
                          txtTimerSecond.setText(&quot;&quot;
                                  + String.format(&quot;%02d&quot;, seconds));
                      } else {
                          tvEvent.setVisibility(View.VISIBLE);
                          tvEvent.setText(&quot;The event started!&quot;);
                          textViewGone();
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          };
          handler.postDelayed(runnable, 1 * 1000);
      }
  
      public void textViewGone() {
          findViewById(R.id.LinearLayout10).setVisibility(View.GONE);
          findViewById(R.id.LinearLayout11).setVisibility(View.GONE);
          findViewById(R.id.LinearLayout12).setVisibility(View.GONE);
          findViewById(R.id.LinearLayout13).setVisibility(View.GONE);
          findViewById(R.id.textView1).setVisibility(View.GONE);
          findViewById(R.id.textView2).setVisibility(View.GONE);
      }
  }
  </code></pre>