Created
August 1, 2017 15:20
-
-
Save kortstin/d0352dbc5facc3de38124c2a31bd7bee to your computer and use it in GitHub Desktop.
Initializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.stins.orbotcamera; | |
import android.app.Application; | |
import android.util.Log; | |
import net.gotev.uploadservice.UploadService; | |
import net.gotev.uploadservice.okhttp.BuildConfig; | |
import net.gotev.uploadservice.okhttp.OkHttpStack; | |
import info.guardianproject.netcipher.client.StrongBuilder; | |
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder; | |
import info.guardianproject.netcipher.proxy.OrbotHelper; | |
import okhttp3.OkHttpClient; | |
/** | |
* Created by stins on 7/19/2017. | |
*/ | |
public class Initializer extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
// setup the broadcast action namespace string which will | |
// be used to notify upload status. | |
// Gradle automatically generates proper variable as below. | |
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID; | |
// Or, you can define it manually. | |
//UploadService.NAMESPACE = "com.example.stins.orbotcamera"; | |
OrbotHelper.get(this).init(); | |
try { | |
StrongOkHttpClientBuilder.forMaxSecurity(this).build(new StrongBuilder.Callback<OkHttpClient>() { | |
@Override | |
public void onConnected(OkHttpClient okHttpClient) { | |
UploadService.HTTP_STACK = new OkHttpStack(okHttpClient); | |
// from now on, you can create upload requests as usual, and they | |
// will be proxied through TOR | |
} | |
@Override | |
public void onConnectionException(Exception e) { | |
// handle exception | |
} | |
@Override | |
public void onTimeout() { | |
// do something on timeout | |
} | |
@Override | |
public void onInvalid() { | |
// do something on invalid | |
} | |
}); | |
} catch (Exception exc) { | |
Log.e("Error", "Error while initializing TOR Proxy OkHttpClient", exc); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment