Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 拍摄屏幕截图(以编程方式)_Android_Screenshot - Fatal编程技术网

Android 拍摄屏幕截图(以编程方式)

Android 拍摄屏幕截图(以编程方式),android,screenshot,Android,Screenshot,我想以编程方式拍摄Android设备的屏幕截图 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent(); intent.setClass(this, ScreenshotService.class); bindService (in

我想以编程方式拍摄Android设备的屏幕截图

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);
        }
    }
});
}'
我知道这个问题已经被问过很多次了。我知道有两种方法

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);
        }
    }
});
}'
  • 使用屏幕截图库(但我一直都是黑屏)
  • 从帧缓冲区获取数据,从
    \dev\graphics\fb0
    (但它总是0字节,我不知道设备当前屏幕截图存储的确切位置)。我的首选要求是获得更好的帧速率。我的代码是

    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);
            }
        }
    });
    }'
    

  • 不要把一个问题贴一次以上

    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);
            }
        }
    });
    }'
    
    可以使用以下代码获取视图的图形缓存:

    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);
            }
        }
    });
    }'
    
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();
    

    通常当你使用屏幕截图时,我们会得到屏幕图像。您是否如前所述运行它,这也可能是一个设备问题,因此我建议您尝试在其他设备上使用相同的设备

    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);
            }
        }
    });
    }'
    

    还有一段时间,将文件写回sd时可能会出现问题。因此,请提供您尝试过的完整代码。

    Android没有内置的屏幕截图库。你说的是什么库?Linux上的路径分隔符是
    /
    不是\。你说的是以编程方式拍摄屏幕截图,还是简单地使用另一个应用程序,还是来自Eclipse,或者..?可能重复截图程序Matically不希望只截图我的应用程序,但设备屏幕上显示的任何内容SurfaceView或TextureView没有绘图缓存
    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);
            }
        }
    });
    }'