From bc3af7e6bc31d1758d5637f74d36f1cd074c4487 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 18 Jun 2016 00:12:58 +0200 Subject: [PATCH] launch the app on Hardware camera button click --- app/src/main/AndroidManifest.xml | 10 ++++++++++ .../camera/HardwareShutterReceiver.java | 15 +++++++++++++++ .../simplemobiletools/camera/MainActivity.java | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/simplemobiletools/camera/HardwareShutterReceiver.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 23406996..0cc25bb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,5 +46,15 @@ android:name=".AboutActivity" android:label="@string/about" android:screenOrientation="portrait"/> + + + + + + + diff --git a/app/src/main/java/com/simplemobiletools/camera/HardwareShutterReceiver.java b/app/src/main/java/com/simplemobiletools/camera/HardwareShutterReceiver.java new file mode 100644 index 00000000..b77298a0 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/camera/HardwareShutterReceiver.java @@ -0,0 +1,15 @@ +package com.simplemobiletools.camera; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class HardwareShutterReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Intent mainIntent = new Intent(context.getApplicationContext(), MainActivity.class); + mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(mainIntent); + } +} diff --git a/app/src/main/java/com/simplemobiletools/camera/MainActivity.java b/app/src/main/java/com/simplemobiletools/camera/MainActivity.java index 4a9eeb6c..d054f07e 100644 --- a/app/src/main/java/com/simplemobiletools/camera/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/camera/MainActivity.java @@ -112,7 +112,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen private void handleIntent() { final Intent intent = getIntent(); - if (intent != null) { + if (intent != null && intent.getAction() != null) { if (intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) { isImageCaptureIntent = true; hideToggleModeAbout();