Skip to content

Commit 4580710

Browse files
committed
修复录制锁屏10秒后无反应的问题。
1 parent d964a5b commit 4580710

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ https://github.com/yrom/ScreenRecorder
2626

2727
- 保证可以录屏
2828

29+
## <font color="red">不允许</font>电量优化
30+
- 防止在锁屏上10秒之后<b>无法录屏</b>
2931

3032
# 本项目佛系维护,提交需求看心情适配。

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
66
<uses-permission android:name="android.permission.RECORD_AUDIO" />
77
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
8+
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
89

910
<application
1011
android:allowBackup="false"

app/src/main/java/net/yrom/screenrecorder/MainActivity.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import android.os.Environment;
4040
import android.os.Handler;
4141
import android.os.Looper;
42+
import android.os.PowerManager;
4243
import android.os.StrictMode;
4344
import android.preference.PreferenceManager;
4445
import android.provider.Settings;
@@ -113,7 +114,6 @@ protected void onCreate(Bundle savedInstanceState) {
113114
SpinnerAdapter codecsAdapter = createCodecsAdapter(mAvcCodecInfos);
114115
mVideoCodec.setAdapter(codecsAdapter);
115116
restoreSelections(mVideoCodec, mVieoResolution, mVideoFramerate, mIFrameInterval, mVideoBitrate);
116-
117117
});
118118
Utils.findEncodersByTypeAsync(AUDIO_AAC, infos -> {
119119
logCodecInfos(infos, AUDIO_AAC);
@@ -413,11 +413,26 @@ private void cancelRecorder() {
413413
stopRecorder();
414414
}
415415

416+
417+
private boolean hasLoadBatPermission() {
418+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
419+
return true;
420+
}
421+
PowerManager powerManager = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
422+
return powerManager.isIgnoringBatteryOptimizations(this.getPackageName());
423+
}
424+
416425
@TargetApi(M)
417426
private void requestPermissions() {
418427
if (!Settings.canDrawOverlays(this)) {
419428
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
420429
startActivity(intent);
430+
return;
431+
}
432+
if (!hasLoadBatPermission()) {
433+
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
434+
this.startActivity(intent);
435+
return;
421436
}
422437
String[] permissions = mAudioToggle.isChecked()
423438
? new String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ KEYPATH=ScreenRecorder-master.keystore
1616
KEYPASS=fwtbdoblhklgbr
1717
KEYSTOREALIAS=ScreenRecorder-master
1818
app_name=ScreenRecorder
19-
app_version_name=1.0.0
20-
app_version_code=1
19+
app_version_name=1.1.0
20+
app_version_code=2

0 commit comments

Comments
 (0)