我将连接到一个android应用程序中的服务器,带有tor,但不使用orbot。
我找到了这个图书馆:https://github.com/jehy/Tor-Onion-Proxy-Library
我补充说

    compile 'com.github.jehy:Tor-Onion-Proxy-Library:0.0.7'
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.slf4j:slf4j-android:1.7.7'

到我的build.gradle(模块:app)和
allprojects {
repositories {
    maven { url 'https://jitpack.io' }
}

}
接下来我在oncreateview中添加了片段
    int totalSecondsPerTorStartup = 4 * 60;
    int totalTriesPerTorStartup = 5;
    try {
        boolean ok = onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup);
        if (!ok)
            Log.e("TorTest", "Couldn't start Tor!");
    }
    catch (InterruptedException | IOException e) {
        e.printStackTrace();
    }

但我得到一个错误Cannot resolve symbol 'onionProxyManager'。我按照github上的说明…
如果我将onionProxyManager更改为OnionProxyManager我可以导入com.msopentech.thali.toronionproxy.OnionProxyManager,但在startWithRepeat上会得到一个错误。
所以如果可以的话请帮帮我。谢谢!

最佳答案

int totalSecondsPerTorStartup = 4 * 60;
int totalTriesPerTorStartup = 5;
String fileStorageLocation = "torfiles";
OnionProxyManager onionProxyManager =
        new AndroidOnionProxyManager(getActivity(), fileStorageLocation);
    public void start(){
// Start the Tor Onion Proxy
try {
  boolean ok = onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup);
// Now the socket is open but note that it can take some time before the Tor network has everything
// connected and connection requests can fail for spurious reasons (especially when connecting to
// hidden services) so have lots of retry logic.
  if (!ok)
    // Log.e("TorTest", "Couldn't start Tor!");
    return;
  }
  catch (InterruptedException | IOException e) {
    e.printStackTrace();
}

07-26 09:39