How does the Native Extension take a screenshot on an Android device?

I have an Adobe Air application that intends to take a screenshot using the Native Extension on an 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'm not very good at Adobe Air. My Java code works specifically on the Android Java Application, but returns a black image in the Adobe Air Android application with its own extension.

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

Thank you so much!

+8
java android actionscript-3 air
source share
2 answers

Maybe you are not getting the right idea. Try this to get the topmost view of the root directory.

 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 deleted the line buildDrawingCache (); which can sometimes cause problems, and from what I read, this is not entirely necessary.

Finally, you will want to check if the bitmap is returning. If so, then maybe why everything is black.

+1
source share

You can take a screenshot like this and save it on the SD card:

 View content = findViewById(R.id.layoutroot); content.setDrawingCacheEnabled(true); Function to get the rendered view: private void getScreen() { View content = findViewById(R.id.layoutroot); Bitmap bitmap = content.getDrawingCache(); File file = new File( Environment.getExternalStorageDirectory() + "/asdf.png"); try { file.createNewFile(); FileOutputStream ostream = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, ostream); ostream.close(); } catch (Exception e) { e.printStackTrace(); } } 

You must add this permission to your AndroidManifest (if you want to save it):

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
0
source share

All Articles