From a8baabdb5fc1d35cca4b34514ea436fd744a6a16 Mon Sep 17 00:00:00 2001
From: akaessens <24660231+akaessens@users.noreply.github.com>
Date: Sun, 27 Sep 2020 12:46:19 +0200
Subject: [PATCH] create intent receiver to fix share issues
---
app/src/main/AndroidManifest.xml | 74 +++++++++----------
.../nofbeventscraper/IntentReceiver.java | 34 +++++++++
.../akdev/nofbeventscraper/MainActivity.java | 29 +++-----
3 files changed, 80 insertions(+), 57 deletions(-)
create mode 100644 app/src/main/java/com/akdev/nofbeventscraper/IntentReceiver.java
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 79ac4f3..a58cbd8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,61 +11,61 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/akdev/nofbeventscraper/IntentReceiver.java b/app/src/main/java/com/akdev/nofbeventscraper/IntentReceiver.java
new file mode 100644
index 0000000..3bbc507
--- /dev/null
+++ b/app/src/main/java/com/akdev/nofbeventscraper/IntentReceiver.java
@@ -0,0 +1,34 @@
+package com.akdev.nofbeventscraper;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+
+public class IntentReceiver extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ /*
+ * Get data from intent: if launched by other application
+ * via "share to" or "open with"
+ */
+ Intent intent = getIntent();
+ setResult(RESULT_OK, intent);
+
+ String data = intent.getDataString();
+ String extra = intent.getStringExtra(Intent.EXTRA_TEXT);
+
+ String input = (data != null) ? data : extra;
+
+ Intent main = new Intent(this, MainActivity.class);
+ main.putExtra("InputLink", input);
+
+ this.startActivity(main);
+
+ finish();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java
index 113d575..1e58984 100644
--- a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java
+++ b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java
@@ -75,6 +75,15 @@ public class MainActivity extends AppCompatActivity {
events.clear();
events.addAll(getSavedEvents());
adapter.notifyDataSetChanged();
+
+ Intent intent = getIntent();
+ String data = intent.getStringExtra("InputLink");
+
+ if (data != null) {
+ intent.removeExtra("InputLink");
+ edit_text_uri_input.setText(data);
+ startScraping();
+ }
}
/**
@@ -196,27 +205,7 @@ public class MainActivity extends AppCompatActivity {
}
});
- /*
- * Get data from intent: if launched by other application
- * via "share to" or "open with"
- */
- Intent intent = getIntent();
- if (intent.getAction() != null) {
- // only use this intent once, not every onCreate (e.g. rotation)
- intent.setAction(null);
- Uri data = intent.getData();
- String shared_text = intent.getStringExtra(Intent.EXTRA_TEXT);
- if (data != null) {
- // opening external fb link
- edit_text_uri_input.setText(data.toString());
- startScraping();
- } else if (shared_text != null) {
- //share to nofb
- edit_text_uri_input.setText(shared_text);
- startScraping();
- }
- }
}
/**