Introduce how to add screenshot button in your application.
Now I would like to use previous app which I post below.
Use Save button add alert with screenshot button.
...
public void onClick(View v) {
...
case R.id.bScript:
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("How do you like to save this page?");
builder.setItems(new CharSequence[] { "URL Save", "Screenshot", "exit" },
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
case 0:
// save url in sqlite
DatabaseOperations dop = new DatabaseOperations(
ctx);
dop.addUrl(dop, currentUrl, currentUrlTitle);
Toast.makeText(ctx,
"URL is successfully saved", 0)
.show();
break;
case 1:
// save screenshot
View v = webview.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v
.getDrawingCache());
v.setDrawingCacheEnabled(true);
String filename = "KarlScreenShot"
+ System.currentTimeMillis()
+ ".png";
try {
FileOutputStream fos = new FileOutputStream(
new File(
Environment
.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
.toString(),
filename));
bmp.compress(CompressFormat.PNG, 100,
fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(ctx,
"Screenshot is successfully saved",
0).show();
break;
case 2:
break;
}
}
});
builder.create().show();
break;
...
2. AndroidManifest.xml
...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
please do not forget to add this permission.
Now I would like to use previous app which I post below.
Use Save button add alert with screenshot button.
1.WebviewActivity.java
...
public void onClick(View v) {
...
case R.id.bScript:
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("How do you like to save this page?");
builder.setItems(new CharSequence[] { "URL Save", "Screenshot", "exit" },
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
case 0:
// save url in sqlite
DatabaseOperations dop = new DatabaseOperations(
ctx);
dop.addUrl(dop, currentUrl, currentUrlTitle);
Toast.makeText(ctx,
"URL is successfully saved", 0)
.show();
break;
case 1:
// save screenshot
View v = webview.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v
.getDrawingCache());
v.setDrawingCacheEnabled(true);
String filename = "KarlScreenShot"
+ System.currentTimeMillis()
+ ".png";
try {
FileOutputStream fos = new FileOutputStream(
new File(
Environment
.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
.toString(),
filename));
bmp.compress(CompressFormat.PNG, 100,
fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(ctx,
"Screenshot is successfully saved",
0).show();
break;
case 2:
break;
}
}
});
builder.create().show();
break;
...
2. AndroidManifest.xml
...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
please do not forget to add this permission.
No comments:
Post a Comment