1. Class Get_FileSize 

public class Get_FileSize {
 
    private static String getFileSizeMegaBytes(File file) {
        return (double) file.length() / (1024 * 1024) + " mb";
    }

    public static double getFileSizeKiloBytes(File file) {
        return (double) file.length() / 1024.0;
    }

    private static String getFileSizeBytes(File file) {
        return file.length() + " bytes";
    }

    public static void FileTooLarge(Context ctx){
        Toast.makeText(ctx,"File Terlalu besar !", Toast.LENGTH_SHORT).show();
    }
}

2. Acces Activity

float max_file_size= 5120; //5 MB

 if (getFileSizeKiloBytes(file)<=max_file_size){
                   // action
                }
                else {
                    FileTooLarge(this);

                }