Taking screenshot of screen(programmatically)

帅比萌擦擦* 提交于 2019-12-13 02:33:18

问题


I would like to take a screenshot of an Android device programmatically.

I know this question has been asked many times.I am aware of two ways to do it.

  1. Using screenshot library(But I am getting black screen all the time).
  2. getting data from frame buffer with rooting from \dev\graphics\fb0(But it is always 0 byte and I do not know exact location where current screenshot of device is stored). My preferred requirement is getting better frame rate.My code is

    public void onCreate(Bundle savedInstanceState)
    {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    
       Intent intent = new Intent();
       intent.setClass(this, ScreenshotService.class);
       bindService (intent,  new ServiceConnection() {
    
        @Override
        public void onServiceDisconnected(ComponentName name) 
        {
    
        }
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
          try {
                asl = IScreenshotProvider.Stub.asInterface(service);
          } catch (Exception ex) {
                Log.e("errrorrrrrrrrrrrrr","errrorrrrrrrrrrr", ex);
          }
        }
    }, Context.BIND_AUTO_CREATE);
    Button b1=(Button) this.findViewById(R.id.widget33);
    b1.setOnClickListener(new OnClickListener() {
    
        public void onClick(View view) 
        {
            try {
                asl.takeScreenshot();
            } catch (RemoteException ex) {
                Log.e("nnnnerrrrrrrrrrrrrr","errrrrrrrrrrrrr",ex);
            }
        }
    });
    }'
    

回答1:


Usually when you use screenshot, we get the screen images. Are you running it as said, also this could be a device thing, so I suggest you try using the same on other device.

Also some time the problem could be while writing the file back to sd. So Please provide with the full code that you tried.




回答2:


Dont post one question more than one time.

You can get the drawing cache of your view using the following code:

view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();


来源:https://stackoverflow.com/questions/15117753/taking-screenshot-of-screenprogrammatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!