create intent receiver to fix share issues

This commit is contained in:
akaessens 2020-09-27 12:46:19 +02:00
parent 85f68f35ac
commit a8baabdb5f
3 changed files with 80 additions and 57 deletions

View File

@ -11,20 +11,43 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".IntentReceiver">
<!-- Accepts open with -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*.facebook.com"
android:scheme="https" />
<data
android:host="facebook.com"
android:scheme="https" />
</intent-filter>
<activity android:name=".SettingsActivity"
<!-- Accepts share intents -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/action_settings">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".HelpActivity"
<activity
android:name=".HelpActivity"
android:label="@string/action_help">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".AboutActivity"
<activity
android:name=".AboutActivity"
android:label="@string/action_about">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
@ -32,39 +55,16 @@
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="stateVisible|adjustPan"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateVisible|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "https://*.facebook.com/events” -->
<data
android:host="*.facebook.com"
android:scheme="https" />
<!-- Accepts URIs that begin with "https://facebook.com/events” -->
<data
android:host="facebook.com"
android:scheme="https" />
</intent-filter>
<!-- Accepts share intents” -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>

View File

@ -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();
}
}

View File

@ -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();
}
}
}
/**