Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.os.Build;

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

public class Main {
    static boolean isTestnet(final Context c) {
        try {
            final Properties p = new Properties();
            p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
            return p.getProperty("testnet", p.getProperty("regtest", "0")).equals("1");
        } catch (final IOException e) {
            return false;
        }
    }

    static String getBitcoinConf(final Context c) {
        return String.format("%s/.bitcoin/bitcoin.conf", getDir(c).getAbsolutePath());
    }

    static File getDir(final Context c) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            return c.getNoBackupFilesDir();
        else
            return c.getFilesDir();
    }
}