[英]How to make a capture screen app on Android
我想制作一個無需root即可捕獲設備屏幕的應用程序: https : //play.google.com/store/apps/details?id=com.icecoldapps.screenshotultimate
但是我找不到解決方案。 有人幫我嗎?
非常感謝你。
通過編程,您可以通過使用adb執行以下命令來執行此操作:
adb shell /system/bin/screencap -p /sdcard/img.png
但是,要在應用程序中執行相同的操作,可以使用以下方法:
Process sh = Runtime.getRuntime().exec("su", null,null); //getting superuser permission to access /system/bin
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII")); //executing the command
os.flush();
os.close();
sh.waitFor();
在/sdcard/
您將擁有img.png屏幕截圖。
從應用程序的常見問題解答中:
我的設備沒有可用的“捕獲方法”!
如果您的設備沒有植根,這是正常的。 這就是Android安全模型的工作方式。 只是不允許在某些設備上截圖。 但是,您可以通過計算機啟用設備上的屏幕快照功能。 要查看如何執行此操作,請轉到“ Screenshot Ultimate”>“設置”>“捕獲方法”>“無捕獲方法幫助”。 您可以通過電子郵件將手冊發送給自己,以便可以在計算機(Windows,Linux或Mac OSX)上完成該手冊。
檢查這是否可以幫助您。 以下代碼將幫助您捕獲特定布局的屏幕
RelativeLayout screenShotLayout=(RelativeLayout)findViewById(R.id.ScreenShotLayout);
Bitmap Bitmapimage=Bitmap.createBitmap(screenShotLayout.getWidth(),screenShotLayout.getHeight(), Config.ARGB_8888);
screenShotLayout.setDrawingCacheEnabled(true);
screenShotLayout.buildDrawingCache();
Bitmapimage=screenShotLayout.getDrawingCache();
//Bitmapimage is the screenshot of the layout. Do your stuff with it
// 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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.