Native Extension如何在Android设备上截屏?

use*_*464 8 java air android actionscript-3

我有一个Adobe Air应用程序打算在Android设备上使用Native Extension截取屏幕截图,但java代码返回一个黑色图像.

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

我对Adobe Air了解不多.我的java代码完全在Android Java Application上运行,但在带有Native Extension的Adobe Air Android Application上返回黑色图像.

是否有任何解决方案或任何方法在NativeExtension中使用Java截取屏幕截图?

非常感谢!

Sol*_*nya 0

您可以像这样截屏并将其保存到 SD 卡:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

您必须将此权限添加到您的 AndroidManifest(如果您想保存它):

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
Run Code Online (Sandbox Code Playgroud)