Breaking News

How to create a Wallpaper App in Android Studio



1 - Copy Paste this code inside MainActivity.class:

package com.android.wallpaperbackgrapp;

import android.app.Activity;
import android.app.WallpaperManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity implements View.OnClickListener {

    private int[] backgrounds;

    private ImageView background1;
    private ImageView background2;
    private ImageView background3;
    private ImageView background4;

    private WallpaperManager wallpaperManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wallpaperManager = WallpaperManager.getInstance(this);

        background1 = findViewById(R.id.background1);
        background1.setOnClickListener(this);
        background2 = findViewById(R.id.background2);
        background2.setOnClickListener(this);
        background3 = findViewById(R.id.background3);
        background3.setOnClickListener(this);
        background4 = findViewById(R.id.background4);
        background4.setOnClickListener(this);

        loadBackgrounds();
    }

    void loadBackgrounds(){
        backgrounds = new int[4];
        backgrounds[0] = R.drawable.background1;
        backgrounds[1] = R.drawable.background2;
        backgrounds[2] = R.drawable.background3;
        backgrounds[3] = R.drawable.background4;
    }

    void updateBackground(int background){
        try{
            wallpaperManager.setResource(background);
        }catch (Exception e){
            System.err.println(e.getMessage());
        }
    }

    @Override
    public void onClick(View view) {
        if(view == background1){
            updateBackground(backgrounds[0]);
            return;
        }

        if(view == background2){
            updateBackground(backgrounds[1]);
            return;
        }

        if(view == background3){
            updateBackground(backgrounds[2]);
            return;
        }

        if(view == background4){
            updateBackground(backgrounds[3]);
            return;
        }
    }
}

2 - Copy Paste this code inside activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"
         android:layout_margin="10dp"
         android:padding="5dp">

         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="horizontal"
             android:weightSum="2"
             android:layout_weight="1">

             <ImageView
                 android:id="@+id/background1"
                 android:layout_width="0dp"
                 android:layout_weight="1"
                 android:layout_height="match_parent"
                 android:src="@drawable/background1"
                 android:layout_margin="5dp"/>

             <ImageView
                 android:id="@+id/background2"
                 android:layout_width="0dp"
                 android:layout_weight="1"
                 android:layout_height="match_parent"
                 android:src="@drawable/background2"
                 android:layout_margin="5dp"/>


         </LinearLayout>

         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="horizontal"
             android:layout_weight="1">

             <ImageView
                 android:id="@+id/background3"
                 android:layout_width="0dp"
                 android:layout_weight="1"
                 android:layout_height="match_parent"
                 android:src="@drawable/background3"
                 android:layout_margin="5dp"/>

             <ImageView
                 android:id="@+id/background4"
                 android:layout_width="0dp"
                 android:layout_weight="1"
                 android:layout_height="match_parent"
                 android:src="@drawable/background4"
                 android:layout_margin="5dp"/>

         </LinearLayout>

     </LinearLayout>

</LinearLayout>

3 - Copy Paste this code inside AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.wallpaperbackgrapp">

    <uses-permission android:name="android.permission.SET_WALLPAPER"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

4 - Download Images and put inside "drawable" folder:





5 - Click run and Enjoy.

Full Video:

24 comments:

  1. Great Post and very helpful for me Thanks by Hani Studio

    ReplyDelete
  2. Thanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. XE88

    ReplyDelete
  3. They additionally need to actualize a complete computerized advertising technique to advance the application by focusing on the most pertinent clients. Bulk SMS Service Provider in Sharjah UAE

    ReplyDelete
  4. if i copy and paste this into android studio is there the code for the users to submit a photo?

    ReplyDelete
  5. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. download prince of persia psp games

    ReplyDelete
  6. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. cyberflix

    ReplyDelete
  7. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. best android app creator

    ReplyDelete
  8. On the off chance that you are going to video a show, ensure that you are in a physical situation to make your subject look great on this Download Social Media

    ReplyDelete
  9. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! yabo

    ReplyDelete
  10. That is the reason; it gets basic for engineers fabricate portable applications by focusing on a wide scope of gadgets controlled by various variants of Android. bluestacks download

    ReplyDelete
  11. Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! photographe Strasbourg

    ReplyDelete
  12. The game has multiple versions. Among them, the Guitar Hero 3 Apk and the Guitar Hero 5 Apk are the most popular ones.

    ReplyDelete
  13. Every sensible business owner today should have a social media marketing strategy. The real secret to success is in being able to earn money from your social media following. my response

    ReplyDelete
  14. Most people use their Android phones (or any Smart Phone really) for entertainment purposes beyond what a normal cell phone could do a decade ago. Because there are literally thousands of apps focused on entertaining Android phone users, when beginning to build your app collection, you should start with a manageable number of the best Android apps to start with and then go from there. Sweatcoin moves site

    ReplyDelete
  15. I am continually amazed by the amount of information available on this subject. What you presented was well researched and well worded in order to get your stand on this across to all your readers. Hire Phone Hacker

    ReplyDelete
  16. With most people plugged in all the time, I often wonder what effect technology is having on our kids. Some say technology is another helpful learning tool that is making our kids smarter and some say it is having no significant effect at all. Still, others propose that technology use is encouraging social isolation, increasing attentional problems, encouraging unhealthy habits, and ultimately changing our culture and the way humans interact. Hire a hacker

    ReplyDelete
  17. i never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. android programming backgrounds

    ReplyDelete
  18. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. Hire Flutter Developers

    ReplyDelete
  19. Really great useful and interesting site Androwalls

    ReplyDelete
  20. The significant advantage of western home decor is that this style of home decoration isn't over the top expensive and should be possible rather rapidly.
    Cool wallpaper

    ReplyDelete