这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
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
18 changes: 13 additions & 5 deletions app/src/main/java/com/termux/api/TorchAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
public class TorchAPI {
private static Camera legacyCamera;

// this is needed to prevent some device camera implementations from inadvertently toggling
// the LED state if same request is sent subsequent times
private static boolean isEnabled = false;


@TargetApi(Build.VERSION_CODES.M)
public static void onReceive(TermuxApiReceiver apiReceiver, final Context context, final Intent intent) {
boolean enabled = intent.getBooleanExtra("enabled", false);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
toggleTorch(context, enabled);
} else {
// use legacy api for pre-marshmallow
legacyToggleTorch(enabled);
if (enabled != isEnabled) {
isEnabled = enabled;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
toggleTorch(context, enabled);
} else {
// use legacy api for pre-marshmallow
legacyToggleTorch(enabled);
}
}
ResultReturner.noteDone(apiReceiver, intent);
}
Expand Down