Skip to content

Commit

Permalink
Fix deep link handling for fragments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jul 11, 2024
1 parent edba3e5 commit 711ff2c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion audio_service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.18.15

* Add deep link support for FlutterFragmentActivity (@jan-milovanovic)
* Add deep link support for FlutterFragmentActivity (@jan-milovanovic).

## 0.18.14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ protected String getCachedEngineId() {
public boolean shouldDestroyEngineWithHost() {
return false;
}

// Make this protected method public
@Override
public String getInitialRoute() {
return super.getInitialRoute();
}

// Make this protected method public
@Override
public boolean shouldHandleDeeplinking() {
return super.shouldHandleDeeplinking();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ public static synchronized FlutterEngine getFlutterEngine(Context context) {
}
}
}
} else if (context instanceof FlutterFragmentActivity) {
final FlutterFragmentActivity activity = (FlutterFragmentActivity)context;
Uri data = activity.getIntent().getData();
if (data != null) {
initialRoute = data.getPath();
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
initialRoute += "?" + data.getQuery();
} else if (context instanceof AudioServiceFragmentActivity) {
final AudioServiceFragmentActivity activity = (AudioServiceFragmentActivity)context;
initialRoute = activity.getInitialRoute();
if (initialRoute == null) {
if (activity.shouldHandleDeeplinking()) {
Uri data = activity.getIntent().getData();
if (data != null) {
initialRoute = data.getPath();
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
initialRoute += "?" + data.getQuery();
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions audio_service/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace 'com.ryanheise.audioserviceexample'
compileSdkVersion 33
compileSdkVersion 34

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,7 +35,7 @@ android {
defaultConfig {
applicationId "com.ryanheise.audioserviceexample"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- If targeting SDK 34 -->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/> -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>

<!-- For example_android_songs example -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down

0 comments on commit 711ff2c

Please sign in to comment.