我見過以下Link,它並採取截圖與頂端回答如何以編程方式採取截圖處於警戒機器人對話
不過,我要的是爲應用程序採取的截圖警報對話框顯示給用戶,上面的解決方案和下面的代碼只需要對警報對話框背後的內容進行截圖,因此沒有什麼好處
下面是在任何人沒有經過的情況下使用的代碼提供的鏈接
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
編輯:作爲請求代碼對話框
public void showCalc(String title, String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton("Capture + Open",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Remove Values From Inventory
captureScreenAndOpen();
}
});
builder.setNegativeButton("Capture",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
captureScreen();
Context context = getApplicationContext();
Toast.makeText(context, "Screenshot Captured", Toast.LENGTH_LONG).show();
}
});
builder.setNeutralButton("Return", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
進一步編輯:
在這裏你會看到兩個截圖,第一個顯示了當一切都從對話框保存的截圖保存的截圖,你」我會注意到底部有一些文字總是出現在底部。
第二截圖是哪裏有對話的對話是滾動的,這樣你可以看到所有的數據在這麼多的文字,你會發現,在第一張截圖底部串不存在
如果可能的話,我想它,所有的數據都顯示,我不知道但如果一個截圖功能將能夠做到這一點還是一種替代方法
請發佈您的對話框代碼。 – Rohit5k2
你只想要對話框的截圖嗎?因爲我剛剛開發了一個代碼。 – Rohit5k2
這很有趣:開發一個代碼來回答一個問題。 :D – Rohit5k2