android环信发送语音,android 环信聊天视频问题

在Android系统中,发送视频文件时遇到10MB大小限制,且在Android 9.0设备上使用FileProvider打开视频会导致崩溃。解决办法是在项目的res/xml目录下创建file_paths.xml文件,并在AndroidManifest.xml中配置FileProvider,确保权限设置正确,以避免打开视频时的崩溃问题。
摘要由CSDN通过智能技术生成

1,发送视频不能大于10M 大约10M会发送不过去

2,android 8.0发送视频 可能正常打开 但是9.0打开会崩溃

为什么呢 经调研查实

FileProvider.getUriForFile(context, context.getPackageName() + “.fileProvider”, file);

报错

解决方案为 在自己项目res创建

xml包 xml下面新建 file_paths.xml

然后在 manifest 下面

android:name="android.support.v4.content.FileProvider"

android:authorities="**项目包名**.fileProvider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource

要在Android应用程序中集成环信的EaseIMKit发送语音,需要遵循以下步骤: 1. 在项目的build.gradle文件中添加环信库的依赖: ``` dependencies { // 环信IM SDK implementation 'com.hyphenate:chat-sdk:3.5.2' // 环信UI库 implementation 'com.hyphenate:chat-ui-sdk:3.5.2' } ``` 2. 在AndroidManifest.xml文件中声明必要的权限: ``` <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.VIBRATE" /> ``` 3. 在你的Activity中创建EaseChatFragment实例,并将其添加到布局中: ``` <fragment android:id="@+id/chat_fragment" android:name="com.hyphenate.easeui.ui.EaseChatFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/top_bar" android:background="@color/white" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:layout_anchor="@id/top_bar" app:layout_anchorGravity="bottom|center_horizontal" /> ``` 4. 在Activity中初始化EaseChatFragment,并设置相关属性: ``` private void initChatFragment() { // 获取EaseChatFragment实例 EaseChatFragment chatFragment = (EaseChatFragment) getSupportFragmentManager().findFragmentById(R.id.chat_fragment); // 设置聊天界面的标题 chatFragment.setTitle("Chat with xxx"); // 设置聊天对象的ID chatFragment.setArguments(getIntent().getExtras()); // 设置是否开启语音消息发送功能 chatFragment.setShowRecord(true); } ``` 5. 在EaseChatFragment中实现发送语音消息的逻辑: ``` // 在EaseChatFragment中重写onSendVoice方法 @Override public void onSendVoice(String filePath, int length) { // 创建语音消息 EMVoiceMessageBody messageBody = new EMVoiceMessageBody(new File(filePath), length); EMMessage message = EMMessage.createVoiceSendMessage(filePath, length, toChatUsername); // 发送语音消息 sendMessage(message); } ``` 以上就是使用环信的EaseIMKit实现Android发送语音消息的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值