Browse Source

feat: 34 前台服务

tongmengxiao 4 months ago
parent
commit
eb874fc5ef
2 changed files with 39 additions and 13 deletions
  1. 3 0
      app/src/main/AndroidManifest.xml
  2. 36 13
      home/src/main/java/com/swago/home/HomeFragment.kt

+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -13,6 +13,9 @@
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.CAMERA"/>
     <uses-permission android:name="android.permission.CAMERA"/>
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
     <uses-permission android:name="android.permission.RECORD_AUDIO"/>
     <uses-permission android:name="android.permission.RECORD_AUDIO"/>
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

+ 36 - 13
home/src/main/java/com/swago/home/HomeFragment.kt

@@ -5,6 +5,7 @@ import android.content.Context
 import android.content.Intent
 import android.content.Intent
 import android.graphics.Color
 import android.graphics.Color
 import android.graphics.Typeface
 import android.graphics.Typeface
+import android.os.Build
 import android.widget.Toast
 import android.widget.Toast
 import androidx.viewpager.widget.ViewPager
 import androidx.viewpager.widget.ViewPager
 import com.alibaba.android.arouter.launcher.ARouter
 import com.alibaba.android.arouter.launcher.ARouter
@@ -106,20 +107,42 @@ class HomeFragment : BaseXFragment<FragmentHomeBinding>() {
         binding.ivLive.setOnClickListener(object :NoDoubleClickListener(){
         binding.ivLive.setOnClickListener(object :NoDoubleClickListener(){
             override fun onClick() {
             override fun onClick() {
                 binding.ivLive.isEnabled = false
                 binding.ivLive.isEnabled = false
-                PermissionX.init(this@HomeFragment)
-                    .permissions(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
-                    .request { allGranted, grantedList, deniedList ->
-                        if (allGranted) {
-                            ARouter.getInstance().build(ARouteConstant.Room.anchor).navigation()
-                        } else {
-                            binding.ivLive.isEnabled = true
-                            Toast.makeText(
-                                AppContext.getContext(),
-                                AppContext.getContext().getString(R.string.these_permissions_denied)+" $deniedList",
-                                Toast.LENGTH_LONG
-                            ).show()
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
+                    PermissionX.init(this@HomeFragment)
+                        .permissions(Manifest.permission.CAMERA,
+                            Manifest.permission.RECORD_AUDIO,
+                            Manifest.permission.FOREGROUND_SERVICE_CAMERA,
+                            Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
+                        .request { allGranted, grantedList, deniedList ->
+                            if (allGranted) {
+                                ARouter.getInstance().build(ARouteConstant.Room.anchor).navigation()
+                            } else {
+                                binding.ivLive.isEnabled = true
+                                Toast.makeText(
+                                    AppContext.getContext(),
+                                    AppContext.getContext().getString(R.string.these_permissions_denied)+" $deniedList",
+                                    Toast.LENGTH_LONG
+                                ).show()
+                            }
                         }
                         }
-                    }
+                } else {
+                    PermissionX.init(this@HomeFragment)
+                        .permissions(Manifest.permission.CAMERA,
+                            Manifest.permission.RECORD_AUDIO)
+                        .request { allGranted, grantedList, deniedList ->
+                            if (allGranted) {
+                                ARouter.getInstance().build(ARouteConstant.Room.anchor).navigation()
+                            } else {
+                                binding.ivLive.isEnabled = true
+                                Toast.makeText(
+                                    AppContext.getContext(),
+                                    AppContext.getContext().getString(R.string.these_permissions_denied)+" $deniedList",
+                                    Toast.LENGTH_LONG
+                                ).show()
+                            }
+                        }
+                }
+
             }
             }
         })
         })