Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CrashUtils工具类上报异常 回调不掉用 bug #1737

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Config {
lib_base : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/base"),
lib_common : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/common"),
lib_subutil : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/subutil"),
lib_utilcode : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utilcode", remotePath: "com.blankj:utilcodex:$Config.versionName"),
lib_utilcode : new ModuleConfig(isApply: true , useLocal: false, localPath: "./lib/utilcode", remotePath: "com.blankj:utilcodex:$Config.versionName"),
lib_utildebug : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug"),
lib_utildebug_no_op : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug-no-op"),
/*Don't delete this line*/
Expand Down
2 changes: 1 addition & 1 deletion lib/utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gradle:
implementation 'com.blankj:utilcodex:1.31.1'

// Not in maintenance
implementation 'com.blankj:utilcode:1.30.6'
implementation 'com.blankj:utilcode:1.30.7'
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1997,29 +1997,22 @@ private static void startActivity(final Context context,
private static boolean startActivity(final Intent intent,
final Context context,
final Bundle options) {
if (!isIntentAvailable(intent)) {
Log.e("ActivityUtils", "intent is unavailable");
return false;
}
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
context.startActivity(intent, options);
} else {
context.startActivity(intent);
try {
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
context.startActivity(intent, options);
} else {
context.startActivity(intent);
}
} catch (Exception e) {
Log.e("ActivityUtils", "An exception occurred in startActivity, error message: " + e.getLocalizedMessage());
return false;
}
return true;
}

private static boolean isIntentAvailable(final Intent intent) {
// return Utils.getApp()
// .getPackageManager()
// .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
// .size() > 0;
return true;
}

private static boolean startActivityForResult(final Activity activity,
final Bundle extras,
final String pkg,
Expand All @@ -2036,15 +2029,16 @@ private static boolean startActivityForResult(final Intent intent,
final Activity activity,
final int requestCode,
@Nullable final Bundle options) {
if (!isIntentAvailable(intent)) {
Log.e("ActivityUtils", "intent is unavailable");
try {
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
activity.startActivityForResult(intent, requestCode, options);
} else {
activity.startActivityForResult(intent, requestCode);
}
} catch (Exception e) {
Log.e("ActivityUtils", "An exception occurred in startActivityForResult, error message: " + e.getLocalizedMessage());
return false;
}
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
activity.startActivityForResult(intent, requestCode, options);
} else {
activity.startActivityForResult(intent, requestCode);
}
return true;
}

Expand Down Expand Up @@ -2079,18 +2073,19 @@ private static boolean startActivityForResult(final Intent intent,
final Fragment fragment,
final int requestCode,
@Nullable final Bundle options) {
if (!isIntentAvailable(intent)) {
Log.e("ActivityUtils", "intent is unavailable");
return false;
}
if (fragment.getActivity() == null) {
Log.e("ActivityUtils", "Fragment " + fragment + " not attached to Activity");
return false;
}
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
fragment.startActivityForResult(intent, requestCode, options);
} else {
fragment.startActivityForResult(intent, requestCode);
try {
if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
fragment.startActivityForResult(intent, requestCode, options);
} else {
fragment.startActivityForResult(intent, requestCode);
}
} catch (Exception e) {
Log.e("ActivityUtils", "An exception occurred in fragment.startActivityForResult, error message: " + e.getLocalizedMessage());
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public void uncaughtException(@NonNull final Thread t, @NonNull final Throwable
final String crashFile = dirPath + time + ".txt";
UtilsBridge.writeFileFromString(crashFile, info.toString(), true);

if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}
if (onCrashListener != null) {
onCrashListener.onCrash(info);
} else if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}

}
};
}
Expand Down