fix: 修复谷歌上报的崩溃

This commit is contained in:
eggmanQQQ
2024-11-04 16:27:53 +08:00
parent 8cb8734b3f
commit 626d4885ac
5 changed files with 139 additions and 78 deletions

View File

@@ -4,8 +4,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -20,10 +18,8 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.chwl.app.application.App;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.trello.rxlifecycle3.components.support.RxFragment;
import com.chwl.app.R;
import com.chwl.app.application.App;
import com.chwl.app.common.AbsStatusFragment;
import com.chwl.app.common.LoadingFragment;
import com.chwl.app.common.NetworkErrorFragment;
@@ -37,6 +33,8 @@ import com.chwl.library.utils.SingleToastUtil;
import com.chwl.library.utils.UIUtils;
import com.chwl.library.utils.config.BasicConfig;
import com.chwl.library.utils.log.MLog;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.trello.rxlifecycle3.components.support.RxFragment;
import java.util.List;
import java.util.Stack;
@@ -600,18 +598,14 @@ public abstract class BaseFragment extends RxFragment implements KeyEvent.Callba
e.printStackTrace();
}
Context fragmentContext = requireContext();
if (dialogManager == null) {
dialogManager = new DialogManager(fragmentContext);
}
Activity topActivity = App.gStack.getTopActivity();
if (dialogManager == null && topActivity != null) {
dialogManager = new DialogManager(topActivity);
}
FragmentActivity fragmentActivity = requireActivity();
if (dialogManager == null && fragmentActivity != null) {
dialogManager = new DialogManager(fragmentActivity);
}
if (dialogManager == null) {
dialogManager = new DialogManager(activity);
dialogManager = new DialogManager(topActivity);
}
return dialogManager;

View File

@@ -19,7 +19,6 @@ import com.chwl.app.R
import com.chwl.app.base.BaseViewBindingFragment
import com.chwl.app.common.widget.dialog.DialogManager
import com.chwl.app.common.widget.dialog.DialogManager.OkCancelDialogListener
import com.chwl.app.databinding.RoomGameActivityBinding
import com.chwl.app.databinding.RoomGameFragmentBinding
import com.chwl.core.auth.AuthModel
import com.chwl.core.pay.event.GetWalletInfoEvent
@@ -113,9 +112,14 @@ class BaiShunGameWebFragment : BaseViewBindingFragment<RoomGameFragmentBinding>(
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
if (!isLoadError) {
binding.webView.isVisible = true
try {
if (!isLoadError) {
binding?.webView?.isVisible = true
}
}catch (e:Exception){
}
}
override fun onReceivedSslError(

View File

@@ -64,8 +64,8 @@ public class AddLocalMusicListSpecialActivity extends BaseMvpActivity<IAddLocalM
mMusicPick = registerForActivityResult(new ActivityResultContracts.OpenDocument(), uri -> {
try {
if (uri != null) {
if (MyUriUtils.INSTANCE.needCopy(context,uri,".mp3")){
File file = MyUriUtils.INSTANCE.copyFile(this, uri,".mp3");
if (MyUriUtils.INSTANCE.needCopy(context,uri)){
File file = MyUriUtils.INSTANCE.copyMp3File(this, uri);
if (file != null) {
LocalMusicBean localMusicBean = getLocalMusicBean(file);
ArrayList<LocalMusicBean> beans = new ArrayList<>();

View File

@@ -12,17 +12,14 @@ import java.io.FileOutputStream
object MyUriUtils {
fun getName(context: Context, uri: Uri): String? {
var fileName: String? = null
val projection = arrayOf(MediaStore.MediaColumns.DISPLAY_NAME)
val cursor: Cursor? = context.contentResolver.query(
uri,
projection,
null,
null,
null
)
fun getName(context: Context, uri: Uri, isImg: Boolean = true): String {
var fileName = ""
try {
val projection = arrayOf(MediaStore.MediaColumns.DISPLAY_NAME)
val cursor: Cursor? = context.contentResolver.query(
uri, projection, null, null, null
)
cursor?.use {
if (it.moveToFirst()) {
fileName =
@@ -30,13 +27,39 @@ object MyUriUtils {
}
}
} catch (e: Exception) {
fileName = ""
}
if (fileName == "") {
val type = getFileType(context, uri)
var fileEnd: String
if (isImg) {
if (type == "image/gif") {
fileEnd = ".gif"
} else if (type == "image/png") {
fileEnd = ".png"
} else if (type == "image/jpeg") {
fileEnd = ".jpeg"
} else if (type == "image/bmp") {
fileEnd = ".bmp"
} else if (type == "image/webp") {
fileEnd = ".webp"
} else {
fileEnd = ".jpg"
}
} else {
fileEnd = ".mp3"
}
fileName = "file_${System.currentTimeMillis()}$fileEnd"
}
return fileName
}
fun copyFile(context: Context, uri: Uri ): File? {
fun copyFile(context: Context, uri: Uri): File? {
try {
val fileName = getName(context, uri) ?: "defName_${System.currentTimeMillis()}.jpg"
val fileName = getName(context, uri,true)
val outPutDir = context.getExternalFilesDir(null) ?: return null
@@ -52,57 +75,59 @@ object MyUriUtils {
}
return outPutFile
} ?: return null
}catch (e:Exception){
} catch (e: Exception) {
return null
}
}
fun needCopy(context: Context, uri: Uri,end:String = ".jpg"): Boolean {
try {
val fileName = getName(context, uri) ?: "defName_${System.currentTimeMillis()}$end"
fun copyMp3File(context: Context, uri: Uri): File? {
try {
val fileName = getName(context, uri,false)
val outPutDir = context.getExternalFilesDir(null) ?: return false
val outPutDir = context.getExternalFilesDir(null) ?: return null
val outPutFile = File(outPutDir, fileName)
val outPutFile = File(outPutDir, fileName)
return !outPutFile.exists()
}catch (e:Exception){
if (!outPutDir.exists()) {
outPutDir.mkdirs()
}
context.contentResolver.openInputStream(uri)?.use { inS ->
FileOutputStream(outPutFile).use { outS ->
inS.copyTo(outS)
}
return outPutFile
} ?: return null
} catch (e: Exception) {
return null
}
}
fun needCopy(context: Context, uri: Uri): Boolean {
try {
val fileName = getName(context, uri,false)
val outPutDir = context.getExternalFilesDir(null) ?: return false
val outPutFile = File(outPutDir, fileName)
return !outPutFile.exists()
} catch (e: Exception) {
return false
}
}
fun copyFile(context: Context, uri: Uri ,end:String = ".jpg"): File? {
try {
val fileName = getName(context, uri) ?: "defName_${System.currentTimeMillis()}$end"
val outPutDir = context.getExternalFilesDir(null) ?: return null
val outPutFile = File(outPutDir, fileName)
if (!outPutDir.exists()) {
outPutDir.mkdirs()
}
context.contentResolver.openInputStream(uri)?.use { inS ->
FileOutputStream(outPutFile).use { outS ->
inS.copyTo(outS)
}
return outPutFile
} ?: return null
}catch (e:Exception){
return null
}
}
fun getFileType(context: Context, uri: Uri): String {
var type = ""
try {
context.contentResolver?.let {
type = it.getType(uri).toString()
}
}catch (e:Exception){
try {
context.contentResolver?.let {
type = it.getType(uri).toString()
}
} catch (e: Exception) {
}
return type
}
@@ -140,7 +165,7 @@ object MyUriUtils {
return true
}
}
}catch (e:Exception){
} catch (e: Exception) {
}
return false
@@ -174,7 +199,7 @@ object MyUriUtils {
dir.mkdirs()
}
file.copyTo(dir, true)
}catch (e:Exception){
} catch (e: Exception) {
}
}

View File

@@ -93,7 +93,7 @@ abstract class PickImageActionNew protected constructor(
}
fun copyFile(context: Context, uri: Uri): File? {
val fileName = getName(context, uri) ?: "defName.jpg"
var fileName = getName(context, uri)
val outPutDir = context.getExternalFilesDir(null) ?: return null
@@ -112,13 +112,14 @@ abstract class PickImageActionNew protected constructor(
}
fun getName(context: Context, uri: Uri): String? {
var fileName: String? = null
val projection = arrayOf(MediaStore.MediaColumns.DISPLAY_NAME)
val cursor: Cursor? = context.contentResolver.query(
uri, projection, null, null, null
)
fun getName(context: Context, uri: Uri,isImg:Boolean = true): String {
var fileName = ""
try {
val projection = arrayOf(MediaStore.MediaColumns.DISPLAY_NAME)
val cursor: Cursor? = context.contentResolver.query(
uri, projection, null, null, null
)
cursor?.use {
if (it.moveToFirst()) {
fileName =
@@ -126,7 +127,44 @@ abstract class PickImageActionNew protected constructor(
}
}
} catch (e: Exception) {
fileName=""
}
if (fileName == "") {
val type = getFileType(context, uri)
var fileEnd: String
if (isImg) {
if (type == "image/gif") {
fileEnd = ".gif"
}else if (type == "image/png") {
fileEnd = ".png"
}else if (type == "image/jpeg") {
fileEnd = ".jpeg"
}else if (type == "image/bmp") {
fileEnd = ".bmp"
}else if (type == "image/webp") {
fileEnd = ".webp"
} else {
fileEnd = ".jpg"
}
} else {
fileEnd=".mp3"
}
fileName = "img_${System.currentTimeMillis()}$fileEnd"
}
return fileName
}
fun getFileType(context: Context, uri: Uri): String {
var type = ""
try {
context.contentResolver?.let {
type = it.getType(uri).toString()
}
}catch (e:Exception){
}
return type
}
}