package com.SalmanDev.WallpaperNew; import android.content.Context; import android.util.Log; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.ComponentCategory; import com.google.appinventor.components.annotations.UsesPermissions; import android.app.WallpaperManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.io.IOException; @DesignerComponent(version = 1, description = "Created By Salman Developer", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "") @UsesPermissions(permissionNames = "android.permission.SET_WALLPAPER") @SimpleObject(external = true) public class WallpaperNew extends AndroidNonvisibleComponent { private ComponentContainer container; public WallpaperNew(ComponentContainer container) { super(container.$form()); this.container = container; } @SimpleFunction(description = "") public void SetWallpaper(String imagePath) { Bitmap myBitmap = BitmapFactory.decodeFile(imagePath); WallpaperManager manager = WallpaperManager.getInstance(container.$context()); try{ manager.setBitmap(myBitmap); } catch (IOException e) { Toast.makeText(container.$context(), "Error!", Toast.LENGTH_SHORT).show(); } } }