Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Native Extension take screenshot on Android device?

I have a Adobe Air application that intend to take a screenshot with Native Extension on Android device, but the java code returns a black image.

public FREObject call(FREContext context, FREObject[] params) {
    View view = context.getActivity().getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap image = view.getDrawingCache();
}

I don't know much about Adobe Air. My java code runs exactly on Android Java Application, but returns black image on Adobe Air Android Application with Native Extension.

Is there any solution or any way to take a screenshot using Java in NativeExtension?

Thanks much!

like image 804
user2644464 Avatar asked Jan 16 '14 14:01

user2644464


1 Answers

Could be that you are not getting the correct view. Try this to get the topmost root view.

public FREObject call(FREContext context, FREObject[] params)
{
    View view = findViewById(android.R.id.content).getRootView();
    view.setDrawingCacheEnabled(true);
    Bitmap image = view.getDrawingCache();
    if(image == null)
    {
        System.out.println("Image returned was null!");
    }
}

I also removed the buildDrawingCache() line; that can sometimes cause issues, and from what I've read it's not completely necessary.

Finally you'll want to check if the bitmap being returned is null. If so that could be why it's all black.

like image 76
Akshay Avatar answered Oct 04 '22 16:10

Akshay