昨天突然想在Android下调用图灵机器人API实现聊天的功能。说干就干,虽然过程中遇见一些问题,但最后解决了的心情真好。
API接口是(key值可以在图灵机器人网站里注册得到)
www.tuling123.com/openapi/api?key=1702c05fc1b94e2bb4de7fb2e61b21a3&info=hello
最后hello是讲的话,访问这个网站会访问一个JSON格式的内容。
text关键字就是访问的内容,只要把这个关键字的内容截取下列就行了。
下面开始写代码。
首先布个局,丑丑的别介意。
一个TextView在上面,用来显示内容,一个EditView在下面用来输入内容,然后一个按钮实现点击事件。
1
2 xmlns:tools="http://schemas.android.com/tools"
3 android:id="@+id/rl"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:background="@drawable/background1"
7 tools:context=".MainActivity" >
8
9
11 android:layout_width="match_parent"
12 android:layout_height="wrap_content"
13 android:textColor="#ff0000"
14 android:textIsSelectable="true"
15 android:textSize="25sp" />
16
17 <