第一步.
点击此处下载
第二步
新建自己的Demo,导入IMKit和IMLib两个Module,添加依赖
第三步.
初始化,并在清单文件中进行配置
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
//初始化
RongIM.init(this);
//token值
String token1 ="sTltJPOv/r0kihB1hmeZvw8qgkkWdAJViRK14/KzM38yWaGUkIg8DC7v5YqATLjy5FEuJAiT0K0+Gn1XxPU3UQ==";
//连接融云
RongIM.connect(token1, new RongIMClient.ConnectCallback() {
@Override
public void onTokenIncorrect() {
}
@Override
public void onSuccess(String s) {
Log.d("app", "onTokenIncorrect: "+s);
}
@Override
public void onError(RongIMClient.ErrorCode errorCode) {
}
});
}
}
第四步
新建ConversationActivity,什么也不用写
它的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/conversation"
android:name="io.rong.imkit.fragment.ConversationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
第五步
新建ConversationListActivity,同样什么都不用写
它的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/conversationlist"
android:name="io.rong.imkit.fragment.ConversationListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
第六步
在需要调用聊天界面的地方写一行代码
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RongIM.getInstance().startPrivateChat(MainActivity.this, "9527", "标题");
}
});
}
}
最重要的,开始进行配置
在IMLib的AndroidManifest.xml中
<meta-data
android:name="RONG_CLOUD_APP_KEY"
android:value="换成自己的APP key" />
在应用的 App Module 的 AndroidManifest.xml 文件中,添加 FileProvider 相关配置,修改 android:authorities 为 “您的应用的包名称.FileProvider”。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="您的应用包名.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/rc_file_path" />
</provider>
融云 SDK 是通过隐式调用的方式来实现界面跳转的。因此您需要在 AndroidManifest.xml 中,您的会话列表 Activity 下面配置 intent-filter,其中,android:host 是您应用的包名,需要手动修改,其他请保持不变。
<activity
android:name=".ConversationListActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="com.jx.test.rongyundemo"
android:pathPrefix="/conversationlist"
android:scheme="rong" />
</intent-filter>
</activity>
<activity android:name=".ConversationActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="com.jx.test.rongyundemo"
android:pathPrefix="/conversation/"
android:scheme="rong" />
</intent-filter>
</activity>