Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;

public class Main {
    public static boolean saveScreenshot(Activity activity, String fileName, Bitmap screenshot, boolean sdcard) {
        try {
            FileOutputStream fos = null;
            if (!sdcard) {
                fos = activity.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
            } else {
                File f = new File(fileName);
                f.createNewFile();
                fos = new FileOutputStream(f);
            }
            screenshot.compress(Bitmap.CompressFormat.JPEG, 70, fos);
            fos.flush();
            fos.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}