Example usage for android.app Application getDir

List of usage examples for android.app Application getDir

Introduction

In this page you can find the example usage for android.app Application getDir.

Prototype

@Override
    public File getDir(String name, int mode) 

Source Link

Usage

From source file:com.quarterfull.newsAndroid.ssl.MemorizingTrustManager.java

/** Creates an instance of the MemorizingTrustManager class.
 *
 * You need to supply the application context. This has to be one of:
 *    - Application/*from   w  w w. jav a 2s.c  o m*/
 *    - Activity
 *    - Service
 *
 * The context is used for file management, to display the dialog /
 * notification and for obtaining translated strings.
 *
 * @param m Context for the application.
 */
public MemorizingTrustManager(Context m) {
    mContext = m;
    masterHandler = new Handler(mContext.getMainLooper());
    notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    Application app;
    if (m instanceof Application) {
        app = (Application) m;
    } else if (m instanceof Service) {
        app = ((Service) m).getApplication();
    } else if (m instanceof Activity) {
        app = ((Activity) m).getApplication();
    } else
        throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!");

    File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE);
    keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE);

    appKeyStore = loadAppKeyStore();
    defaultTrustManager = getTrustManager(null);
    appTrustManager = getTrustManager(appKeyStore);
}

From source file:de.duenndns.ssl.MemorizingTrustManager.java

void init(Context m) {
    master = m;/* w w  w.  j  av a 2 s.c o m*/
    masterHandler = new Handler(m.getMainLooper());
    notificationManager = (NotificationManager) master.getSystemService(Context.NOTIFICATION_SERVICE);

    Application app;
    if (m instanceof Application) {
        app = (Application) m;
    } else if (m instanceof Service) {
        app = ((Service) m).getApplication();
    } else if (m instanceof Activity) {
        app = ((Activity) m).getApplication();
    } else
        throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!");

    File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE);
    keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE);

    poshCacheDir = app.getFilesDir().getAbsolutePath() + "/posh_cache/";

    appKeyStore = loadAppKeyStore();
}