// Manifest.xml 内容
<!-- begin imlib request -->
<service
android:name="io.rong.push.PushService"
android:process="io.rong.push" > <!-- Waring: The name of the push process can not be changed!!! -->
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="io.rong.push" />
</intent-filter>
</service>
<service
android:name="io.rong.push.CommandService"
android:process="io.rong.push" > <!-- Waring: The name of the push process can not be changed!!! -->
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="io.rong.command" />
</intent-filter>
</service>
<receiver
android:name="io.rong.push.PushReceiver"
android:process="io.rong.push" > <!-- Waring: The name of the push process can not be changed!!! -->
<intent-filter>
<action android:name="io.rong.imlib.action.push.heartbeat" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<activity
android:name="io.rong.imkit.tools.SelectPictureActivity"
android:screenOrientation="portrait" />
<activity
android:name="io.rong.imkit.tools.PreviewPictureActivity"
android:screenOrientation="portrait" />
<activity
android:name="io.rong.imkit.tools.RongWebviewActivity"
android:screenOrientation="portrait" />
<activity
android:name="io.rong.imkit.widget.provider.TakingPicturesActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait" />
<service
android:name="io.rong.imlib.ipc.RongService"
android:process=":ipc" >
</service>
<service android:name="io.rong.imlib.ReConnectService" />
<receiver android:name="io.rong.imlib.ConnectChangeReceiver" />
<receiver android:name="io.rong.imlib.ipc.PushMessageReceiver" >
<intent-filter>
<action android:name="io.rong.push.message" />
</intent-filter>
</receiver>
<receiver
android:name="io.rong.imlib.HeartbeatReceiver"
android:process=":ipc" />
<meta-data
android:name="RONG_CLOUD_APP_KEY"
android:value="p5tvi9dst1t34" />
<!-- end -->
//融云 api 各种请求 get&post
注册
登录获得token
登录(过时)
获得token,需要先登录(过时)
获取群组列表
获取我加入的群组列表
根据群组id 获得群组信息
更新群组信息
加入群组
退出群组
获取好友列表
发送好友邀请
处理好用请求
删除好友
按名称查询用户
// 最简单的案例
//Application 初始化:
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
RongIM.init(this);
}
}
//Activity
private String token = "X7Mn+e8kHKAW+tlz519Bc9MeXVx6EF51PNIFnVhhXfAWzIPQmrnG5uhgHEqyAIqMXt3Og2sGtv3/ami9xPsAxg==";
//启动连接
RongIM.connect(token, new RongIMClient.ConnectCallback() {
/**
* Token 错误,在线上环境下主要是因为 Token 已经过期,您需要向 App Server 重新请求一个新的
* Token
*/
@Override
public void onTokenIncorrect() {
Log.i("my", "--onTokenIncorrect");
}
/**
* 连接融云成功
* @param userid
* 当前 token
*/
@Override
public void onSuccess(String userid) {
Log.i("my", "--onSuccess" + userid);
}
/**
* 连接融云失败
* @param errorCode
* 错误码,可到官网 查看错误码对应的注释
*/
@Override
public void onError(RongIMClient.ErrorCode errorCode) {
Log.i("my", "--onError" + errorCode);
}
});
// 启动会话列表界面
RongIM.getInstance().startConversationList(this);
// 启动会话界面
RongIM.getInstance().startPrivateChat(this, "y1235", "title");
// 通用案例
RongCloudEvent.init(this);//初始化
Thread.setDefaultUncaughtExceptionHandler(new RongExceptionHandler(this));//异常
RongIM.registerMessageType(AgreedFriendRequestMessage.class);//注册消息的类型
RongIM.registerMessageTemplate(new ContactNotificationMessageProvider());//注册消息的模板
RongIM.registerMessageTemplate(new RealTimeLocationMessageProvider());
//@ 消息模板展示
RongContext.getInstance().registerConversationTemplate(new NewDiscussionConversationProvider());
/**
* 登录 demo server
*
* @param email
* @param password
* @param callback 1 关羽 2,张飞
* @return
*/
public AbstractHttpRequest<User> loginToken(String email, String password, ApiCallback<User> callback) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("password", password));
//nameValuePairs.add(new BasicNameValuePair("env", "1"));
ApiReqeust<User> apiReqeust = new DefaultApiReqeust<User>(ApiReqeust.POST_METHOD, URI.create(HOST + DEMO_LOGIN_EMAIL_TOKEN), nameValuePairs, callback);
AbstractHttpRequest<User> httpRequest = apiReqeust.obtainRequest(new GsonParser<User>(User.class), mAuthType);
NetworkManager.getInstance().requestAsync(httpRequest);
return httpRequest;
}
... ... ... ...
很多常用方法,可以看 DemoApi.java
RongCloudEvent.java 包含许多时间回调方法。☆☆☆☆☆