1、"打开方式”列表中出现你的APP图标。新建一个独立的activity
<!--外部应用发送文件-->
<activity
android:name=".chat.mine.SendExternalFileActivity"
android:screenOrientation="locked">
<!--使用三方应用打开-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="*/*" />
</intent-filter>
<!--分享暂不用,需要处理链接数据 -->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.SEND" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <data android:mimeType="*/*" />-->
<!-- </intent-filter>-->
</activity>
2、在onCreate()中获取路径(暂只针对文件发送)
/***
* 获取文件路径
* @param savedInstanceState
*/
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
fileUri = uri;
String str = Uri.decode(uri.getEncodedPath());
if (str != null) {
String[] strings = str.split("/");
StringBuffer sb = new StringBuffer();
for (int i = 0; i < strings.length - 1; i++) {
sb.append(strings[i] + "/");
}
mFilePath = sb.toString();
mFileName = strings[strings.length - 1];
}
if (!LoginUtils.getInstance().isLogin(getContext())) {
ToastUtils.showToast("请先登录后再次操作");
IntentUtils.getInstance().toActivity(getContext(), LoginActivity.class);
SendExternalFileActivity.this.finish();
}
}
3、发送文件(使用的是腾讯的IM发送消息)
messageListAdapter.setOnPositionClick(new OnPositionClick() {
@Override
public void onPositionClick(int position) {
/**点击事件*/
if (fileUri != null) {
MessageInfo fileMessage = MessageInfoUtil.buildFileMessage(fileUri);
ConversationInfo info = conversationData.get(position);
TIMConversation mConversation = TIMManager.getInstance().getConversation(info.isGroup() ? TIMConversationType.Group : TIMConversationType.C2C, info.getId());
if (mConversation !=null) {
DialogUtils.getInstance().chooseCheckMan(SendExternalFileActivity.this, "温馨提示", "发送到" + info.getTitle() + "\n" + mFileName, new ChooseCheckMan() {
@Override
public void onCheck() {
mConversation.sendMessage(fileMessage.getTIMMessage(), new TIMValueCallBack<TIMMessage>() {
@Override
public void onError(int i, String s) {
ToastUtils.showToast("发送失败");
}
@Override
public void onSuccess(TIMMessage timMessage) {
ToastUtils.showToast("发送成功");
SendExternalFileActivity.this.finish();
/**进入此会话中*/
// ChatHelper.getInstance().startChatActivity(getContext(), conversationList.get(position));
}
});
}
});
}
}
}
});
|