Hi @Taifun , how can I set the wallpaper of the home screen in extension. I am using the wallpaper manager class.
This is what I did-
@SimpleFunction(description = "")
public void SetWallpaper(String path) {
WallpaperManager manager = WallpaperManager.getInstance(); /** What is the thing which I want keep as the instance*/
try {
manager.setResource(); /** How can I keep the path as the resource?*/
} catch (Exception e) {
ErrorOccured(e.getMessage());
}
}
The questions are there in the code itself.
Thank you.....
1 Like
This will solve all your problems :
1.Import this :
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;
2.Add Permission
Add this line under @DesignerComponent
@UsesPermissions(permissionNames = "android.permission.SET_WALLPAPER")
3.Add the code that I fixed
@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();
}
}
Aix Source Code :
WallpaperNew.txt (1.6 KB)
To use the extension, you have to do something like this :
4 Likes
And I have tested the code and it works 100% so you don't need to worry. Thank you
1 Like
Your missing read permission in the extension. As your using image picker it's okay
1 Like
Oh, I am sorry
And I think it will work even if it doesn't use read permission
system
Closed
February 20, 2021, 9:03am
9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.