how to use cloudsight api in android app for image recognition

712 Views Asked by At

public class MainActivity extends AppCompatActivity {

private static final String API_KEY = "b8fo0q33XyuCTm0qbr6XCg";

static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
static final JsonFactory JSON_FACTORY = new JacksonFactory();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button myBtn = (Button) findViewById(R.id.button);
    TextView t=(TextView) findViewById(R.id.text);

}

public void onClick(View v) {

    try {
        CSApi api = new CSApi(
                HTTP_TRANSPORT,
                JSON_FACTORY,
                API_KEY
        );
        CSPostConfig imageToPost = CSPostConfig.newBuilder()
                .withRemoteImageUrl("https://questions4thoughts.files.wordpress.com/2008/11/50rupees.png")
                .build();

        CSPostResult portResult = api.postImage(imageToPost);

        System.out.println("Post result: " + portResult);
        try{
            Thread.sleep(30000);

            CSGetResult scoredResult = api.getImage(portResult);

           // t.setText(scoredResult);
        }
        catch (InterruptedException e){
            e.getCause();
        }



    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

}

}

i am new to this api. i have post and get files also i dont know how to use it. when i am running the app it says unfortunately stop. i have used cloudsight api but there no source for using it. Can u suggest some solution on how to use it or some other free api for image recognition.

2

There are 2 best solutions below

1
On

Did you try giving internet permission above the application tag in Manifest.xml? if not, add the following line :

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

i've the same issue, few time ago. And i did it :

new Thread() {
@Override
public void run() {
   //your code here
   }
}.start();

it works perfect, so i share it to you. but for the first time you will received status "not completed", because cloudsight needs 6-12 second until complete. so try to run the thread until you get status complete. Hope you success. :)