0

I am trying to create an android application to connect on a cloud. I bassically try to connect to koofr.eu using theyr api.

Koofr is the safe and simple way to store, backup and share your photos, videos and documents. Access all your data anywhere and anytime, from any device, be it a computer, a phone or a tablet. Safety and security are at the heart of our software and our mindset.

The documentation they provide on Java is small, it looks simple but the library is pretty big. Also, one of the problems I encountered was that the library used another 3-4 libraryes to be added to work.

This is how my app gradle looks like:

dependencies {
   /*compile fileTree(dir: 'libs', include: ['*.jar']) */
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'net.koofr:java-koofr:1.2.8'
    compile ("org.restlet.jse:org.restlet.ext.httpclient:2.1.2") {
        exclude group: 'org.restlet', module: 'jse'
        exclude group: 'org.restlet.ext', module: 'ss1'
    }
    compile 'org.apache.httpcomponents:httpclient:4.3.5'
    compile 'org.restlet.jse:org.restlet.ext.jackson:2.1.2'


    android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/ASL2.0'
            exclude 'META-INF/services/org.restlet.engine.ClientHelper'
        }
    }

In manifest I have added user permission to allow internet in the application:

<uses-permission android:name="android.permission.INTERNET" />

and my main activity code is simple.

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                StorageApi api = DefaultClientFactory.create("app.koofr.eu", "*********", "******");
                Log.i("TEST","User Info: "+api.getUserInfo());
            } catch (StorageApiException e) {
                e.printStackTrace();
                Log.i("TEST","Mesaj: "+e.getMessage());
            }
        }
    });

Basically the exception message is the following:

Internal Connector Error (1002) - The connector encountered an unexpected condition which prevented it from fulfilling the request

But this didn't help me in any way to find a solution on my problem so I found some warning that I tryed to understand.

03-12 21:50:44.617    7027-7027/com.example.marian.digimusicstream W/System.err﹕ Starting the Apache HTTP client
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ Error while handling an HTTP client call
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ [ 03-12 21:50:44.619  7027: 7027 W/System.err ]
    android.os.NetworkOnMainThreadException
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:423)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.net.InetAddress.getLocalHost(InetAddress.java:396)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientCall.getLocalAddress(ClientCall.java:67)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientCall.<init>(ClientCall.java:90)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.ext.httpclient.internal.HttpMethodCall.<init>(HttpMethodCall.java:107)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.ext.httpclient.HttpClientHelper.create(HttpClientHelper.java:298)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientAdapter.toSpecific(ClientAdapter.java:159)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:111)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.Client.handle(Client.java:180)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1136)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handleOutbound(ClientResource.java:1225)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1044)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:950)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.get(ClientResource.java:658)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at net.koofr.api.v2.StorageApi.authenticate(StorageApi.java:150)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at net.koofr.api.v2.DefaultClientFactory.create(DefaultClientFactory.java:66)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.example.marian.digimusicstream.LoginActivity$1.onClick(LoginActivity.java:51)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.view.View.performClick(View.java:4763)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.view.View$PerformClick.run(View.java:19821)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5274)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
03-12 21:50:44.622    7027-7027/com.example.marian.digimusicstream W/System.err﹕ A recoverable error was detected (1002), attempting again in 2000 ms.

If there is someone that have any small ideea, I would apreciate. Thank you.

Marian Pavel
  • 2,726
  • 8
  • 29
  • 65
  • Is it a HTTP connection? Has it SSL? What is the proper host? starting with http:// or something.. – Laszlo Lugosi Mar 12 '15 at 20:15
  • TSL 1.2 using https, the link is correct, I am looking in DefaultClientFactory and in method I used I see: String token = api.authenticate("https://" + hostname + "/token", username, password); so it's automatically adding https:// – Marian Pavel Mar 12 '15 at 20:20

1 Answers1

2
android.os.NetworkOnMainThreadException

Do not make network calls on the UI thread!
Put anything which is potentially time consuming in a new thread so you don't freeze your UI.
See this question for more info.

Community
  • 1
  • 1
florianmski
  • 5,603
  • 1
  • 17
  • 14