|
6 | 6 | import static io.agora.rtc2.video.VideoEncoderConfiguration.STANDARD_BITRATE;
|
7 | 7 | import static io.agora.rtc2.video.VideoEncoderConfiguration.VD_640x360;
|
8 | 8 |
|
9 |
| -import android.app.Notification; |
10 |
| -import android.app.NotificationChannel; |
11 |
| -import android.app.NotificationManager; |
12 |
| -import android.app.Service; |
13 | 9 | import android.content.Context;
|
14 |
| -import android.content.Intent; |
15 |
| -import android.graphics.BitmapFactory; |
16 |
| -import android.graphics.Color; |
17 |
| -import android.os.Build; |
18 | 10 | import android.os.Bundle;
|
19 |
| -import android.os.IBinder; |
20 | 11 | import android.util.DisplayMetrics;
|
21 | 12 | import android.util.Log;
|
22 | 13 | import android.view.LayoutInflater;
|
|
34 | 25 |
|
35 | 26 | import androidx.annotation.NonNull;
|
36 | 27 | import androidx.annotation.Nullable;
|
37 |
| -import androidx.annotation.RequiresApi; |
38 |
| -import androidx.core.app.NotificationCompat; |
39 | 28 |
|
40 | 29 | import com.yanzhenjie.permission.AndPermission;
|
41 | 30 | import com.yanzhenjie.permission.runtime.Permission;
|
@@ -83,7 +72,6 @@ public class ScreenSharing extends BaseFragment implements View.OnClickListener,
|
83 | 72 | private RtcEngineEx engine;
|
84 | 73 | private final ScreenCaptureParameters screenCaptureParameters = new ScreenCaptureParameters();
|
85 | 74 |
|
86 |
| - private Intent fgServiceIntent; |
87 | 75 | private Spinner screenScenarioType;
|
88 | 76 |
|
89 | 77 | @Nullable
|
@@ -122,9 +110,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
122 | 110 | if (context == null) {
|
123 | 111 | return;
|
124 | 112 | }
|
125 |
| - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
126 |
| - fgServiceIntent = new Intent(getActivity(), ScreenSharing.MediaProjectFgService.class); |
127 |
| - } |
128 | 113 | try {
|
129 | 114 | RtcEngineConfig config = new RtcEngineConfig();
|
130 | 115 | /**
|
@@ -176,9 +161,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
176 | 161 |
|
177 | 162 | @Override
|
178 | 163 | public void onDestroy() {
|
179 |
| - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
180 |
| - getActivity().stopService(fgServiceIntent); |
181 |
| - } |
182 | 164 | /**leaveChannel and Destroy the RtcEngine instance*/
|
183 | 165 | if (engine != null) {
|
184 | 166 | engine.leaveChannel();
|
@@ -285,10 +267,6 @@ private void joinChannel(String channelId) {
|
285 | 267 | /**Set up to play remote sound with receiver*/
|
286 | 268 | engine.setDefaultAudioRoutetoSpeakerphone(true);
|
287 | 269 |
|
288 |
| - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
289 |
| - getActivity().startForegroundService(fgServiceIntent); |
290 |
| - } |
291 |
| - |
292 | 270 | DisplayMetrics metrics = new DisplayMetrics();
|
293 | 271 | getActivity().getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
294 | 272 | screenCaptureParameters.captureVideo = true;
|
@@ -490,9 +468,6 @@ private void leaveChannel() {
|
490 | 468 | fl_remote.removeAllViews();
|
491 | 469 | remoteUid = myUid = -1;
|
492 | 470 |
|
493 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
494 |
| - getActivity().stopService(fgServiceIntent); |
495 |
| - } |
496 | 471 | engine.leaveChannel();
|
497 | 472 | engine.stopScreenCapture();
|
498 | 473 | engine.stopPreview();
|
@@ -531,58 +506,4 @@ public void onNothingSelected(AdapterView<?> parent) {
|
531 | 506 |
|
532 | 507 | }
|
533 | 508 |
|
534 |
| - public static class MediaProjectFgService extends Service { |
535 |
| - @Nullable |
536 |
| - @Override |
537 |
| - public IBinder onBind(Intent intent) { |
538 |
| - return null; |
539 |
| - } |
540 |
| - |
541 |
| - @Override |
542 |
| - public void onCreate() { |
543 |
| - super.onCreate(); |
544 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
545 |
| - createNotificationChannel(); |
546 |
| - } |
547 |
| - } |
548 |
| - |
549 |
| - @Override |
550 |
| - public int onStartCommand(Intent intent, int flags, int startId) { |
551 |
| - return START_NOT_STICKY; |
552 |
| - } |
553 |
| - |
554 |
| - @Override |
555 |
| - public void onDestroy() { |
556 |
| - super.onDestroy(); |
557 |
| - stopForeground(true); |
558 |
| - } |
559 |
| - |
560 |
| - @RequiresApi(api = Build.VERSION_CODES.O) |
561 |
| - private void createNotificationChannel() { |
562 |
| - CharSequence name = getString(R.string.app_name); |
563 |
| - String description = "Notice that we are trying to capture the screen!!"; |
564 |
| - int importance = NotificationManager.IMPORTANCE_HIGH; |
565 |
| - String channelId = "agora_channel_mediaproject"; |
566 |
| - NotificationChannel channel = new NotificationChannel(channelId, name, importance); |
567 |
| - channel.setDescription(description); |
568 |
| - channel.enableLights(true); |
569 |
| - channel.setLightColor(Color.RED); |
570 |
| - channel.enableVibration(true); |
571 |
| - channel.setVibrationPattern( |
572 |
| - new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); |
573 |
| - NotificationManager notificationManager = (NotificationManager) |
574 |
| - getSystemService(Context.NOTIFICATION_SERVICE); |
575 |
| - notificationManager.createNotificationChannel(channel); |
576 |
| - int notifyId = 1; |
577 |
| - // Create a notification and set the notification channel. |
578 |
| - Notification notification = new NotificationCompat.Builder(this, channelId) |
579 |
| - .setContentText(name + "正在录制屏幕内容...") |
580 |
| - .setSmallIcon(R.mipmap.ic_launcher) |
581 |
| - .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) |
582 |
| - .setChannelId(channelId) |
583 |
| - .setWhen(System.currentTimeMillis()) |
584 |
| - .build(); |
585 |
| - startForeground(notifyId, notification); |
586 |
| - } |
587 |
| - } |
588 | 509 | }
|
0 commit comments