Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.example.stins.orbotcamera;
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 {
public static volatile boolean orbotConnected = false;
public void 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";
private void initNetCipher() {
Log.i("NetCipherClient", "Initializing NetCipher client");
try {
StrongOkHttpClientBuilder.forMaxSecurity(this).build(new StrongBuilder.Callback<OkHttpClient>() {
public void onConnected(OkHttpClient okHttpClient) {
UploadService.HTTP_STACK = new OkHttpStack(okHttpClient);
orbotConnected = true;
Log.i("NetCipherClient", "Connection to orbot established!");
// from now on, you can create upload requests as usual, and they
// will be proxied through TOR
public void onConnectionException(Exception e) {
// handle exception
orbotConnected = false;
Log.e("NetCipherClient", "onConnectionException()", e);
public void onTimeout() {
// do something on timeout
orbotConnected = false;
Log.e("NetCipherClient", "onTimeout()");
public void onInvalid() {
// do something on invalid
orbotConnected = false;
Log.e("NetCipherClient", "onInvalid()");
} 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