Skip to content

Commit

Permalink
Merge pull request #391 from jinanzhuan/sdk3.0
Browse files Browse the repository at this point in the history
adapter androidQ.
  • Loading branch information
githubzhaoliang committed Jun 10, 2020
2 parents 9289465 + 48f01ce commit fa2b39f
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 62 deletions.
15 changes: 11 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.hyphenate.chatuidemo"
android:versionCode="66"
android:versionName="3.6.7">
android:versionCode="67"
android:versionName="3.6.8">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -65,15 +65,18 @@

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!--捕获屏幕所需权限-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
android:name=".DemoApplication"
android:allowBackup="true"
android:icon="@drawable/em_logo_uidemo"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:requestLegacyExternalStorage="false"
android:label="@string/app_name">

<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<!--<uses-library android:name="org.apache.http.legacy" android:required="false"/>-->

<!-- 适配Android 7.0, 需要将下方的com.hyphenate.chatuidemo替换为你的app包名 -->
<provider
Expand Down Expand Up @@ -561,6 +564,10 @@
</receiver>
<!-- Mi推送配置 end-->

<!--捕获屏幕service-->
<service android:name=".conference.SRForegroundService"
android:enabled="true"
android:foregroundServiceType="mediaProjection"/>
</application>

</manifest>
2 changes: 1 addition & 1 deletion app/src/main/java/com/hyphenate/chatuidemo/DemoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void init(Context context) {
demoModel = new DemoModel(context);
EMOptions options = initChatOptions(context);
// options.setRestServer("a1-hsb.easemob.com");
// options.setIMServer("39.107.54.56");
// options.setIMServer("116.85.43.118");
// options.setImPort(6717);

//use default options if options is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == ScreenCaptureManager.RECORD_REQUEST_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScreenCaptureManager.getInstance().start(resultCode, data);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Intent service = new Intent(this, SRForegroundService.class);
service.putExtra("code", resultCode);
service.putExtra("data", data);
startForegroundService(service);
}else {
ScreenCaptureManager.getInstance().start(resultCode, data);
}

}
} else if (requestCode == REQUEST_CODE_INVITE) {
final String[] members = data.getStringArrayExtra("members");
Expand Down Expand Up @@ -801,6 +809,7 @@ private void exitConference() {

if (ScreenCaptureManager.getInstance().state == ScreenCaptureManager.State.RUNNING) {
ScreenCaptureManager.getInstance().stop();
stopForegroundService();
}

// Stop to watch the phone call state.
Expand All @@ -823,6 +832,16 @@ public void onError(int error, String errorMsg) {
});
}

/**
* 停止服务
*/
private void stopForegroundService() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Intent service = new Intent(this, SRForegroundService.class);
stopService(service);
}
}

private void startAudioTalkingMonitor() {
EMClient.getInstance().conferenceManager().startMonitorSpeaker(300);
}
Expand Down Expand Up @@ -909,6 +928,7 @@ private void unpublish(String publishId) {
if (!TextUtils.isEmpty(conference.getPubStreamId(EMConferenceStream.StreamType.DESKTOP))
&& publishId.equals(conference.getPubStreamId(EMConferenceStream.StreamType.DESKTOP))) {
ScreenCaptureManager.getInstance().stop();
stopForegroundService();
}
}
EMClient.getInstance().conferenceManager().unpublish(publishId, new EMValueCallBack<String>() {
Expand Down Expand Up @@ -1202,6 +1222,7 @@ public void run() {
DeskShareWindow.getInstance(getApplicationContext()).dismiss();
if (ScreenCaptureManager.getInstance().state == ScreenCaptureManager.State.RUNNING) {
ScreenCaptureManager.getInstance().stop();
stopForegroundService();
}
// 退出当前界面
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ class ConferenceInviteActivity : BaseActivity() {
contactList.addAll(result.data)
}
} while (result!!.cursor != null && !result.cursor.isEmpty())

//获取管理员列表
try {
val adminList = EMClient.getInstance().groupManager().getGroupFromServer(groupId, true)?.adminList
if (adminList != null) {
contactList.addAll(adminList)
}
} catch (e: HyphenateException) {
e.printStackTrace()
}
}

runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.hyphenate.chatuidemo.conference;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;

import com.hyphenate.chatuidemo.R;
import com.superrtc.mediamanager.ScreenCaptureManager;

import java.util.Objects;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class SRForegroundService extends Service {
private int resultCode;
private Intent resultData;
private MediaProjectionManager projectionManager;
private MediaProjection mMediaProjection;

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//启动前置服务
createNotificationChannel();
resultCode = intent.getIntExtra("code", -1);
resultData = intent.getParcelableExtra("data");

this.projectionManager = (MediaProjectionManager)getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mMediaProjection = projectionManager.getMediaProjection(resultCode, Objects.requireNonNull(resultData));

ScreenCaptureManager.getInstance().start(resultCode, resultData, mMediaProjection);
return super.onStartCommand(intent, flags, startId);
}

private void createNotificationChannel() {
Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); //获取一个Notification构造器
Intent nfIntent = new Intent(this, ConferenceActivity.class); //点击后跳转的界面,可以设置跳转数据

builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0)) // 设置PendingIntent
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.em_logo_uidemo)) // 设置下拉列表中的图标(大图标)
//.setContentTitle("SMI InstantView") // 设置下拉列表里的标题
.setSmallIcon(R.drawable.em_logo_uidemo) // 设置状态栏内的小图标
.setContentText(getString(R.string.share_screen_ongoing)) // 设置上下文内容
.setWhen(System.currentTimeMillis()); // 设置该通知发生的时间

/*以下是对Android 8.0的适配*/
//普通notification适配
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setChannelId("share_screen_id");
}
//前台服务notification适配
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel("share_screen_id", "shareScreen", NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
}

Notification notification = builder.build(); // 获取构建好的Notification
notification.defaults = Notification.DEFAULT_SOUND; //设置为默认的声音
startForeground(110, notification);

}

@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.hyphenate.chatuidemo.domain;

import android.net.Uri;

public class VideoEntity {
public int ID;
public String title;
public String filePath;
public int size;
public int duration;
public Uri uri;
}
52 changes: 42 additions & 10 deletions app/src/main/java/com/hyphenate/chatuidemo/ui/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import android.app.Activity;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -49,9 +54,12 @@
import com.hyphenate.util.EMLog;
import com.hyphenate.util.EasyUtils;
import com.hyphenate.util.PathUtil;
import com.hyphenate.util.UriUtils;
import com.hyphenate.util.VersionUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -219,15 +227,34 @@ public void run() {
if (data != null) {
int duration = data.getIntExtra("dur", 0);
String videoPath = data.getStringExtra("path");
File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
try {
FileOutputStream fos = new FileOutputStream(file);
Bitmap ThumbBitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
ThumbBitmap.compress(CompressFormat.JPEG, 100, fos);
fos.close();
sendVideoMessage(videoPath, file.getAbsolutePath(), duration);
} catch (Exception e) {
e.printStackTrace();
String uriString = data.getStringExtra("uri");
EMLog.d(TAG, "path = "+videoPath + " uriString = "+uriString);
if(!TextUtils.isEmpty(videoPath)) {
File file = new File(PathUtil.getInstance().getVideoPath(), "thvideo" + System.currentTimeMillis());
try {
FileOutputStream fos = new FileOutputStream(file);
Bitmap ThumbBitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
ThumbBitmap.compress(CompressFormat.JPEG, 100, fos);
fos.close();
sendVideoMessage(videoPath, file.getAbsolutePath(), duration);
} catch (Exception e) {
e.printStackTrace();
EMLog.e(TAG, e.getMessage());
}
}else {
Uri videoUri = UriUtils.getLocalUriFromString(uriString);
File file = new File(PathUtil.getInstance().getVideoPath(), "thvideo" + System.currentTimeMillis());
try {
FileOutputStream fos = new FileOutputStream(file);
MediaMetadataRetriever media = new MediaMetadataRetriever();
media.setDataSource(getContext(), videoUri);
Bitmap frameAtTime = media.getFrameAtTime();
frameAtTime.compress(CompressFormat.JPEG, 100, fos);
fos.close();
sendVideoMessage(videoUri, file.getAbsolutePath(), duration);
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
Expand Down Expand Up @@ -357,7 +384,12 @@ public boolean onExtendMenuItemClick(int itemId, View view) {
* select file
*/
protected void selectFileFromLocal() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Intent intent = new Intent();
if(VersionUtils.isTargetQ(getActivity())) {
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
}else {
intent.setAction(Intent.ACTION_GET_CONTENT);
}
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");

Expand Down
Loading

0 comments on commit fa2b39f

Please sign in to comment.