0

公共类 MainActivity 扩展 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();
    }

}

}

我是这个 api 的新手。我有发布和获取文件,但我也不知道如何使用它。当我运行应用程序时,它说不幸停止。我使用过cloudsight api,但没有使用它的来源。你能建议一些关于如何使用它的解决方案或一些其他免费的图像识别 API。

4

2 回答 2

0

我也有同样的问题,前段时间。我做到了:

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. :)

于 2016-09-07T07:36:34.143 回答
0

您是否尝试在Manifest.xml中的应用程序标记上方授予 Internet 权限?如果没有,请添加以下行:

<uses-permission android:name="android.permission.INTERNET" />
于 2016-04-28T19:07:39.113 回答