0% found this document useful (0 votes)
10 views2 pages

Wallaaapaper

This document contains an Android application code for changing the device wallpaper every 30 seconds. It uses a Timer to cycle through five drawable resources when a button is clicked. The application extends AppCompatActivity and utilizes the WallpaperManager to set the wallpaper dynamically.

Uploaded by

bksshimoga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Wallaaapaper

This document contains an Android application code for changing the device wallpaper every 30 seconds. It uses a Timer to cycle through five drawable resources when a button is clicked. The application extends AppCompatActivity and utilizes the WallpaperManager to set the wallpaper dynamically.

Uploaded by

bksshimoga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.example.

myapplication;

import android.os.Bundle;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button changewallpaper;
Timer mytimer;
Drawable drawable;
WallpaperManager wpm;
int id=1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
mytimer = new Timer ();
wpm = WallpaperManager.getInstance(this);
changewallpaper = findViewById(R.id.btn_click);
changewallpaper.setOnClickListener(new
View.OnClickListener()
{
@Override public void onClick(View view) {
setWallpaper();
}
});
}
private void setWallpaper()
{
mytimer.schedule(new TimerTask()
{
@Override
public void run() {
if(id==1) {
drawable =
getResources().getDrawable(R.drawable.one);
id = 2;
}
else if(id==2) {
drawable =
getResources().getDrawable(R.drawable.two); id=3;
}
else if(id==3) {
drawable =
getResources().getDrawable(R.drawable.three); id=4;
}
else if(id==4) {
drawable =
getResources().getDrawable(R.drawable.four); id=5;
}
else if(id==5) {
drawable =
getResources().getDrawable(R.drawable.five); id=1;

}
Bitmap wallpaper =
((BitmapDrawable)drawable).getBitmap();
try {
wpm.setBitmap(wallpaper);

}
catch (IOException e)
{ e.printStackTrace();
}
}
},0,30000);
}
}

You might also like