Screenshot from background service of another application (programmatically)

前端 未结 2 2033
小蘑菇
小蘑菇 2020-12-03 08:44

When I use the browser I want to save screenshots of the site that I visited. Because some pages disappear in the future. So I decided to do a background service that would

相关标签:
2条回答
  • 2020-12-03 09:22
    • https://market.android.com/details?id=com.edwardkim.android.screenshotitfullnoroot&hl=en

      Doesn't need to be rooted.

    • http://maketecheasier.com/take-screenshots-on-android-phone/2010/07/16

      Would need to be rooted.

    Worst case scenario you can use android SDK while plugged in via USB and take screen shots.

    0 讨论(0)
  • 2020-12-03 09:47
     Process sh = Runtime.getRuntime().exec("su", null,null);
    
                            OutputStream  os = sh.getOutputStream();
                            os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
                            os.flush();
    
                            os.close();
                            sh.waitFor();
    
        then read img.png as bitmap and convert it jpg as follows 
    
    Bitmap screen = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+ File.separator +"img.png");
    
    //my code for saving
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            screen.compress(Bitmap.CompressFormat.JPEG, 15, bytes);
    
    //you can create a new file name "test.jpg" in sdcard folder.
    
    File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "test.jpg");
                    f.createNewFile();
    //write the bytes in file
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
    // remember close de FileOutput
    
            fo.close();
    
    0 讨论(0)
提交回复
热议问题