【Help】How can I set Activity.Background as the current wallpaper?

powerchen

Member
Licensed User
Longtime User
I am a novice.

How can I set Activity.Background as the current wallpaper in B4A?

Activity.Background = ???

Thank you!

JAVA CODE
B4X:
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Main.this.getWindow().setBackgroundDrawable(wallpaperDrawable);

=======================

I have got it! Thank everyone!

B4X:
    Dim r As Reflector
   Dim b As Bitmap
   Dim d As BitmapDrawable
   b.InitializeMutable(Activity.Width,Activity.Height)
   d.Initialize(b)
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", Array As Object(r.GetContext), Array As String("android.content.Context"))
   Activity.Background = r.RunMethod("getDrawable")
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should first read the live wallpaper tutorial: Android Live Wallpaper tutorial

There is an example of drawing a bitmap. If you want to draw an activity to the live wallpaper you will need to first save the activity background as a bitmap.

You can create a new bitmap and draw the activity background with Canvas.DrawDrawable.
 
Upvote 0

powerchen

Member
Licensed User
Longtime User
You should first read the live wallpaper tutorial: Android Live Wallpaper tutorial

There is an example of drawing a bitmap. If you want to draw an activity to the live wallpaper you will need to first save the activity background as a bitmap.

You can create a new bitmap and draw the activity background with Canvas.DrawDrawable.

Thank you! Sorry, my English is very poor.

I may be wrong expression means.

I mean that "Activity.Background = wallpaper"

The current wallpaper is set to activity background, then activity looks like a transparent.
 
Upvote 0

powerchen

Member
Licensed User
Longtime User
You should first read the live wallpaper tutorial: Android Live Wallpaper tutorial

There is an example of drawing a bitmap. If you want to draw an activity to the live wallpaper you will need to first save the activity background as a bitmap.

You can create a new bitmap and draw the activity background with Canvas.DrawDrawable.

In another way, how to read the current wallpaper to bitmap.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Maybe this helps

B4X:
Sub SetWallPaper(Bmp As Bitmap)
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   r.RunMethod4("setBitmap", Array As Object(Bmp), Array As String("android.graphics.Bitmap"))
   ToastMessageShow("Wallpaper added successfully.",False)
End Sub
 
Upvote 0

powerchen

Member
Licensed User
Longtime User
If you want to make the activity look like it is transparent, you can just make it transparent.
See the Documentation: Activity - Basic4android Wiki

if I set Activity.Color = Colors.Transparent , the Actual effect is this
豌豆荚截图201203240643.jpg
 
Upvote 0

powerchen

Member
Licensed User
Longtime User
If you want to make the activity look like it is transparent, you can just make it transparent.
See the Documentation: Activity - Basic4android Wiki

this is the Actual effect I want.
2.jpg

---------------------------------------

In the Eclipse, I can use the code to achieve.

B4X:
      // 1.获取与给定Context关联的WallpaperManager
      final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
      // 2.获取当前系统壁纸
      final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
      Main.this.getWindow().setBackgroundDrawable(wallpaperDrawable);

The pic Exceeds forum quota by 22.2 KB. So I compressed.

333.jpg
 
Last edited:
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
if I set Activity.Color = Colors.Transparent , the Actual effect is this
View attachment 10950

Without knowing what part of that screen shot is in your app and what part is the device's wallpaper, I can't tell what your screen shot is showing.

The screen shot in your other message doesn't appear to be a full screen, so it can't be the device's wallpaper, so I still can't tell what it is you want.

Sorry.

----Edit:

Now that you have posted the full screen shot, it appears that your problem with the screen shot in the other post is that you are not getting the transparent background when you enter Activity.Color = Colors.Transparent. Did you change the manifest file following the directions in this post?

If you did follow all the directions and still can't get it to work, then I'm afraid I'm not the one who can help you.
 
Last edited:
Upvote 0

powerchen

Member
Licensed User
Longtime User
Now that you have posted the full screen shot, it appears that your problem with the screen shot in the other post is that you are not getting the transparent background when you enter Activity.Color = Colors.Transparent. Did you change the manifest file following the directions in this post?

If you did follow all the directions and still can't get it to work, then I'm afraid I'm not the one who can help you.

Thank you!

http://www.b4x.com/forum/basic4andr...02-how-create-special-activity.html#post77475

If I set Activity.Color=Colors.Transparent and add the following line to the manifest editor,
B4X:
SetActivityAttribute(main, android:theme, "@android:style/Theme.Translucent.NoTitleBar")

you can see the laucher not only the wallpaper.
 
Upvote 0

powerchen

Member
Licensed User
Longtime User
Maybe this helps

B4X:
Sub SetWallPaper(Bmp As Bitmap)
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   r.RunMethod4("setBitmap", Array As Object(Bmp), Array As String("android.graphics.Bitmap"))
   ToastMessageShow("Wallpaper added successfully.",False)
End Sub


Thank you!

But I want to get the wallpaper, not to set.

Can you tell me how to do it?

============================================================

Thanks again! I got it!
B4X:
   Dim r As Reflector
   Dim b As Bitmap
   Dim d As BitmapDrawable
   b.InitializeMutable(Activity.Width,Activity.Height)
   d.Initialize(b)
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", Array As Object(r.GetContext), Array As String("android.content.Context"))
   Activity.Background = r.RunMethod("getDrawable")
 
Last edited:
Upvote 0
Top