Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

public class Main {
    public static final String DATABASE_START = "BLANK ";
    public static final String DATABASE_TYPE = ".db";

    public static void deleteDatabase(Context context, String name) {
        String dbName = formatDatabaseName(context, name);
        if (!context.deleteDatabase(dbName)) {
            context.deleteDatabase(dbName.replace(":", "_"));
        }
    }

    private static String formatDatabaseName(Context context, String name) {
        if (name == null || name.isEmpty()) {
            name = getDefaultDatabaseName(context);
        }

        if (!name.startsWith(DATABASE_START)) {
            name = DATABASE_START + name;
        }
        if (!name.endsWith(DATABASE_TYPE)) {
            name += DATABASE_TYPE;
        }

        return name;
    }

    public static String getDefaultDatabaseName(Context context) {
        return DATABASE_START + context.getString(context.getApplicationInfo().labelRes) + DATABASE_TYPE;
    }
}