I have implemented a video calling feature in our app. There is a button which captures the screenshot of specific view. On video call there a two views Local View and Remote View. These are actually Relative and Frame layouts. In this case i want take screenshot of remote view but it's just giving me a blank image. I think somehow agora video calling not allowing it but there should be any settings or something to disable this but that i have not found yet. here is the code:
Setting up remote video:
mRemoteContainer is a RelativeLayout and mRemoteVideo is VideoCanvas by agora.io
Similarly mLocalContainer is FrameLayout.
private void setupRemoteVideo(int uid) {
ViewGroup parent = mRemoteContainer;
if (parent.indexOfChild(mLocalVideo.view) > -1) {
parent = mLocalContainer;
}
if (mRemoteVideo != null) {
return;
}
SurfaceView view = RtcEngine.CreateRendererView(getBaseContext());
view.setZOrderMediaOverlay(parent == mLocalContainer);
parent.addView(view);
mRemoteVideo = new VideoCanvas(view, VideoCanvas.RENDER_MODE_HIDDEN, uid);
mRemoteVideo.view.setWillNotDraw(false);
mRtcEngine.setupRemoteVideo(mRemoteVideo);
}
This function used to get bitmap from the view
private Bitmap getScreenShotFromView(View v) {
Bitmap screeShoot = null;
try {
screeShoot = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(screeShoot);
v.draw(canvas);
} catch (Exception e) {
Log.e("GFG", "Failed to capture screenshot because:" + e.getMessage());
}
return screeShoot;
}
I tried function call with both view but getting black or blank image
Bitmap bitmap = getScreenShotFromView(mRemoteVideo.view);
Bitmap bitmap = getScreenShotFromView(mRemoteContainer);
Your help will be really appreciated for me as i stuck on this issue.
By the way I used the same view capturing technique on iOS with swift
and Its working fine.
I created a wallpaper app ,I'm using Firebase to upload images to a database and shown it to RecyclerView.
I can see the images that I uploaded in Firebase through the RecyclerView and I can also pass that image to a another activity.
but my problem is, I can't set the image as wallpaper, when I set the button the image is disappearing.
my code to set wallpaper:
img = (ImageView) findViewById(R.id.images);
Intent intent = getIntent();
String webUrl = intent.getStringExtra("URL");
Picasso.get().load(webUrl).into(img);
fab1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
WallpaperManager wallpaper = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaper.setResource(+ R.drawable.pug); //by using this code i can set a image in directory a wallpaper
//wallpaper.setResource(+ R.id.images); //i tried this one it doesn't work it just crashes the app
}catch (IOException e){
e.printStackTrace();
}
}
});
what I want is to set any image shown in the ImageView
is there any way
I'm assuming you already have the permission in place for this:
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
I'm not sure what you are trying to achieve, but I am assuming you want the user to choose an image from the list and set it as wallpaper.
You can only pass a Bitmap or Resource ID to WallpaperManager. In this case, fetch the image as a Bitmap first, and then load into the ImageView.
Since you are already using Picasso, you can do this:
Picasso.with(this).load(webUrl).centerCrop().into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
wallpaper.setBitmap(bitmap);
}
}
I am trying to open a default intent of android gallery (screenshot given below).
for this i have referred some
SO Questions but none of them are worked for me Question and this Question
here's a screenshot what i want...samsung device's gallery
this is a working app on playstore..wallpaperApp
can Anyone please tell me how can i achieve this?
Thanks In Advance!!
You can use wallpaper manager to set image as wallpaper.
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.wallpaper);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
After I take a picture with the Camera API, this picture displays on the screen/this activity. I want to send this picture that covers the whole screen to another activity called PictureEditor. There I will add functionality that can edit the picture.
// Code in MainActivity
mCamera.takePicture(null, null, mPicture);
Intent i = new Intent(getApplicationContext(), PictureEditor.class);
Bitmap b = getBitmapFromView(mPreview);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);
In PictureEditor I have this code in OnCreate.
// Code in PictureEditor
if(getIntent().hasExtra("byteArray")) {
ImageView previewThumbnail = new ImageView(this);
Bitmap b = BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
previewThumbnail.setImageBitmap(b);
}
What can I do to retrive this picture in PictureEditor, and that this picture is the only thing that is visible on the screen in this activity? (Decode the bitmap and display it as an image on the screen)
Thanks for all kind of help!
Instead of startActivity call startActivityForResult and get the image from the bundle in onActivityResult call back method in the same activity and pass the image to the new Activity.
// Code in PictureEditor
if(getIntent().hasExtra("byteArray")) {
ImageView previewThumbnail = new ImageView(this);
Bitmap b =(Bitmap) getIntent().getParcelableExtra("byteArray");
previewThumbnail.setImageBitmap(b);
}
But if you send information between activitys. The size of this information cant exceed 1 MB. You have to compress your bitmap.
I'm just getting started with android programming, and want to see if there is a way to programmatically set the lock screen image. I've found various ways of setting the wallpaper in the API, but I can't seem to find the equivalent ways of setting the lock screen image.
I've seen various posts saying that customising the lock screen by adding widgets or bits of applications is not possible, but surely there must be a way to set the image programmatically?
Cheers,
Robin
As of API Level 24 they have added new methods (and updated the documentation) and flags to the WallpaperManager which allow you to set a Wallpaper not only to the home screen but also to the Lockscreen
To set a Wallpaper to the Lockscreen use the new flag WallpaperManager.FLAG_LOCK, and one of the methods which take int which
WallpaperManager.getInstance(this).setStream(inputStream, null, true, WallpaperManager.FLAG_LOCK);
You can also use one of the following methods
int setStream (InputStream bitmapData, Rect visibleCropHint, boolean allowBackup, int which)
int setResource (int resid, int which)
int setBitmap (Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)
A nice addition is that you can now also check if you are allowed to set the wallpaper via isSetWallpaperAllowed, and get the current set wallpaper via getWallpaperFile
Check out the updated documentation for the WallpaperManager.
There is no "lock screen image" in Android. There most certainly is no "lock screen image" concept that is the same between stock Android, HTC Sense, MOTOBLUR, etc. This simply is not part of the Android SDK.
The project that Mr. Rijk points to is a security violation that pretends to be a lock screen replacement.
There is a way to do it on Samsung devices. In the intent you can put an extra.
intent.putExtra("SET_LOCKSCREEN_WALLPAPER", true);
startActivity(intent);
I've only tested this on some Samsung phones and there's no guarantee that this won't break some time in the future. Use with caution.
You can use these three methods of WalpaperManager class but it will only work for nought version devices or above it:-
public int setBitmap (Bitmap fullImage,
Rect visibleCropHint,
boolean allowBackup,
int which)
public int setResource (int resid,
int which)
public int setStream (InputStream inputStreamData,
Rect visibleCropHint,
boolean allowBackup,
int which)
Parameter of these three methods:-
Bitmap/resid/inputStreamData :-this parameter accept data
visibleCropHint:-this parameter accept Rect object which is mainly used for Cropping functionality, for more information refer to Android developer reference website, you can also pass null if u don't want cropping functionality
allowBackup:-boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
which:-It is one of the most important parameter which helps you to configure wallpaper for lock screen and home wallpaper. for lock screen use WalpaperManager.FLAG_LOCK and for home wallpaper use FLAG_SYSTEM
I am giving one example to make you understand how to use it:-
WalaperManager wm = WalaperManager.getInstance();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wm.setBitmap(bitmap,null,true,WalpaperManager.FLAG_LOCK);//For Lock screen
Toast.makeText(context.context, "done", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(context.context, "Lock screen walpaper not supported",
Toast.LENGTH_SHORT).show();
}
} catch (e: Exception) {
Toast.makeText(context.context, e.message, Toast.LENGTH_SHORT).show();
}
for more information visit Android developer wallpaper manager reference
There is another way to do this. at first ,you need save the pic which you wanna set in lockedscreen in a folder(suppose it's called "appName").and then ,use following code to open gallery, after gallery has opened.lead user to open "appName" folder ,and choose the pic in gallery of system. in the gallery,user can set a pic as wallpaper or lockscreen paper.
// this code to open gallery.
startActivity(new Intent(Intent.ACTION_SET_WALLPAPER));
Bitmap icon = BitmapFactory.decodeResource(getViewContext().getResources(), R.drawable.wall);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getViewContext());
try {
wallpaperManager.setBitmap(icon, null, true, WallpaperManager.FLAG_LOCK);
} catch (IOException e) {
e.printStackTrace();
}
usage for api30+
public void onWallpaperChanged(Bitmap bitmap, boolean onHomeScreen, boolean onLockScreen) {
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
if(onHomeScreen) {
myWallpaperManager.setBitmap(bitmap);// For Home screen
}
if(onLockScreen) {
myWallpaperManager.setBitmap(bitmap,null,true, WallpaperManager.FLAG_LOCK);//For Lock screen
}
} catch (IOException e) {
e.printStackTrace();
}
}
Since API level 24, you can set wallpaper to your home screen, lock screen, or both:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// home screen
wallpaperManager.setBitmap(mBitmap, null, true, WallpaperManager.FLAG_SYSTEM);
// lock screen
wallpaperManager.setBitmap(mBitmap, null, true, WallpaperManager.FLAG_LOCK);
// home screen & lock screen
wallpaperManager.setBitmap(mBitmap, null, true, WallpaperManager.FLAG_LOCK | WallpaperManager.FLAG_SYSTEM);
} else {
wallpaperManager.setBitmap(mBitmap);
}
source