Skip to content

Commit

Permalink
uni_links: Android: Migrate to v2 embedding APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker1024 committed Dec 27, 2020
1 parent cdd7a21 commit a190518
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
1 change: 0 additions & 1 deletion uni_links/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ android {
disable 'InvalidPackage'
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
Expand Down Expand Up @@ -43,6 +46,7 @@ private void handleIntent(Context context, Intent intent) {
}
}

@NonNull
private BroadcastReceiver createChangeReceiver(final EventChannel.EventSink events) {
return new BroadcastReceiver() {
@Override
Expand All @@ -63,9 +67,9 @@ public void onReceive(Context context, Intent intent) {
}

@Override
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
this.context = flutterPluginBinding.getApplicationContext();
register(flutterPluginBinding.getFlutterEngine().getDartExecutor(), this);
register(flutterPluginBinding.getBinaryMessenger(), this);
}

private static void register(BinaryMessenger messenger, UniLinksPlugin plugin) {
Expand All @@ -77,7 +81,7 @@ private static void register(BinaryMessenger messenger, UniLinksPlugin plugin) {
}

/** Plugin registration. */
public static void registerWith(PluginRegistry.Registrar registrar) {
public static void registerWith(@NonNull PluginRegistry.Registrar registrar) {
// Detect if we've been launched in background
if (registrar.activity() == null) {
return;
Expand All @@ -92,7 +96,7 @@ public static void registerWith(PluginRegistry.Registrar registrar) {
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding flutterPluginBinding) {}
public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
Expand All @@ -105,7 +109,7 @@ public void onCancel(Object o) {
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
if (call.method.equals("getInitialLink")) {
result.success(initialLink);
} else if (call.method.equals("getLatestLink")) {
Expand All @@ -122,7 +126,7 @@ public boolean onNewIntent(Intent intent) {
}

@Override
public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) {
public void onAttachedToActivity(@NonNull ActivityPluginBinding activityPluginBinding) {
activityPluginBinding.addOnNewIntentListener(this);
this.handleIntent(this.context, activityPluginBinding.getActivity().getIntent());
}
Expand All @@ -132,7 +136,7 @@ public void onDetachedFromActivityForConfigChanges() {}

@Override
public void onReattachedToActivityForConfigChanges(
ActivityPluginBinding activityPluginBinding) {
@NonNull ActivityPluginBinding activityPluginBinding) {
activityPluginBinding.addOnNewIntentListener(this);
this.handleIntent(this.context, activityPluginBinding.getActivity().getIntent());
}
Expand Down
14 changes: 9 additions & 5 deletions uni_links/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="uni_links_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="flutterEmbedding" android:value="2"/>
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand All @@ -53,5 +50,12 @@
android:pathPrefix="/path/subpath" />
</intent-filter>
</activity>
<activity
android:name=".EmbeddingV1Activity"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.unilinksexample;

import android.os.Bundle;

import androidx.annotation.Nullable;

import io.flutter.app.FlutterActivity;
import name.avioli.unilinks.UniLinksPlugin;

public class EmbeddingV1Activity extends FlutterActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UniLinksPlugin.registerWith(registrarFor("name.avioli.unilinks.UniLinksPlugin"));
}
}

This file was deleted.

0 comments on commit a190518

Please sign in to comment.