【问题标题】:Take screen shot of any screen截取任何屏幕的屏幕截图
【发布时间】:2014-07-29 20:34:08
【问题描述】:

我正在使用以下代码截取当前活动的屏幕截图:

View rootview = findViewById(android.R.id.content).getRootView();
rootview.setDrawingCacheEnabled(true);

并将图像保存在 SD 卡上。

但我不仅要截取这个应用程序的屏幕截图,还要截取这个应用程序之外的屏幕截图,我做了一些研究,发现只有 ROOTED 设备才有可能,但有什么方法可以截取屏幕截图没有root设备的任何屏幕截图?

【问题讨论】:

  • 我很确定不是,但不是 100%。我知道现在很多公司都将功能作为内置功能包含在内,因为很多人都想要它,但它是无根的。
  • 希望不是,出于明显的隐私和安全原因。

标签: android screenshot


【解决方案1】:

尝试使用反射从PhoneWindowManager.java Refer to this link调用takeScreenshot()

参考here以下代码

为 PhoneWindowManger 执行此操作。

TelephonyManager telephony = (TelephonyManager) 
  context.getSystemService(Context.TELEPHONY_SERVICE);  
  try {
      Log.v(TAG, "Get getTeleService...");
      Class c = Class.forName(telephony.getClass().getName());
      Method m = c.getDeclaredMethod("getITelephony");
      m.setAccessible(true);
      telephonyService = (ITelephony) m.invoke(telephony);
      telephonyService.silenceRinger();
      Log.v(TAG, "Answering Call now...");
      telephonyService.answerRingingCall();
      Log.v(TAG, "Call answered...");
      //telephonyService.endCall();
  } catch (Exception e) {
   e.printStackTrace();
   Log.e(TAG,
           "FATAL ERROR: could not connect to telephony subsystem");
   Log.e(TAG, "Exception object: " + e);
  }

Android L 提供 API 来截取屏幕截图。refer-https://developer.android.com/reference/android/media/projection/package-summary.html

【讨论】:

【解决方案2】:

您对 READ_FRAME_BUFFER 权限感兴趣:http://developer.android.com/reference/android/Manifest.permission.html#READ_FRAME_BUFFER

问题在于它明确指出:“不供第三方应用程序使用。”

你运气不好。这是一项不会消失的安全功能(不允许任何应用程序截取其他应用程序的屏幕截图)。您将被限制为 root 设备。

【讨论】:

    【解决方案3】:

    这是允许我的屏幕截图存储在 sd 卡上并在以后用于任何您需要的代码:

    // image naming and path  to include sd card  appending name you choose for file
    
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   
    
    // create bitmap screen capture
    
    Bitmap bitmap;
    View v1 = mCurrentUrlMask.getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    
    OutputStream fout = null;
    imageFile = new File(mPath);
    
    try {
    
    fout = new FileOutputStream(imageFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
    fout.flush();
    fout.close();
    
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    

    然后,当您需要访问时,请使用以下内容:

     Uri uri = Uri.fromFile(new File(mPath));
    

    【讨论】:

      【解决方案4】:

      取决于你的目的。如果您在应用程序中需要分发到 Playstore 的该功能,那么您就没有运气了。没有root权限,根本不可能。

      不过,出于测试或个人目的,adb 会有所帮助。你只需发送 一些数据包到您机器的 adb 服务器,您可以检索设备的屏幕截图。

      为此,您应该读出adb client <-> server protocolframebuffer 协议对你来说似乎很完美。

      或者如果您熟悉 node.js,adbkit 将节省您的时间。

      【讨论】:

        【解决方案5】:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-07-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-09-26
          • 2012-03-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多