New version of AppLinks.RegisterLink() didn't work on Android

VitalyVitaly USMember ✭✭

Example version of DeepLink is working, ok. This version is 2.3.9.****
But when I added in my project last this version 2.5.0.9.*** there rise new error
"Default FirebaseApp is not initialized in this process", so ok. I got google-services.json file, got key values for property builder and try again.
And it works without error but it does nothing indexing, I see nithing in google ok search popup.

Why new Application.Current.AppLinks.RegisterLink(appLink); needs Firebase library and why it doesn't work with this all?
Old versin 2.3.9.** are working at https://developer.xamarin.com/samples/xamarin-forms/deeplinking
but when you updating this to last it stay asking firebase, is this Firebase initialization correct? Why doesn't work?

My code

 protected override async void OnCreate(Bundle bundle)
    {
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle );

        global::Xamarin.Forms.Forms.Init(this, bundle);

        var options = new FirebaseOptions.Builder()
                .SetApplicationId("1:36385392236:android:c0d54c779ee347e4")
                .SetApiKey("AIzaSyAX-rofUTdK9Z3SGRlvheFBSjyA3AyQRSQ")
                .SetDatabaseUrl("https://imposing-vista-173407.firebaseio.com")
                 .SetGcmSenderId("1:36385392236:android:c0d54c779ee347e4")
                 .SetStorageBucket("fews33")
            .Build();

        FirebaseApp.InitializeApp(this, options);

        try
        {
            AndroidAppLinks.Init(this);
        }
        catch(Exception exc)
        {
            var t = exc.Message;
        }

        LoadApplication(new App(new SystemFolders(), new KeyboardManager(this), new SpeechRecognizerDroid(this), new YandexSpeechKit(ApiKey), new AudioPlayer(this)));
    }


  private async void HandleDoneButtonClicked()
    {
        var appLink = App.GetTestAppLink("купертино");

        try
        {
            Application.Current.AppLinks.RegisterLink(appLink);
        }
        catch (Exception exc)
        {
            var t = exc.Message;
        }

        await Navigation.PopModalAsync();
    }

Posts

  • VitalyVitaly USMember ✭✭

    Why it does not indexing? Without Firebase initialization it throw error

    {Java.Lang.NullPointerException: null reference
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
    at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance,
    Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in :0
    at Android.Runtime.JNIEnv.CallObjectMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <2e14bb2dd93a405e81838369ed72695b>:0
    at Firebase.AppIndexing.Builders.IndexableBuilder.SetDescription (System.String description) [0x00051] in :0
    at Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks.GetIndexable (Xamarin.Forms.IAppLinkEntry appLink, System.String url) [0x00021] in :0
    at Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks.IndexItemAsync (Xamarin.Forms.IAppLinkEntry appLink) [0x00016] in :0
    at Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks.RegisterLink (Xamarin.Forms.IAppLinkEntry appLink) [0x00000] in :0

    OR

    {Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process krista.datatron.datatron. Make sure to call FirebaseApp.initializeApp(Context) first.

  • VitalyVitaly USMember ✭✭

    My packages versions are

     <package id="Xamarin.Firebase.AppIndexing" version="42.1021.1" targetFramework="monoandroid71" />
     <package id="Xamarin.Firebase.Common" version="42.1021.1" targetFramework="monoandroid71" />
     <package id="Xamarin.Forms" version="2.5.0.91635" targetFramework="monoandroid71" />
     <package id="Xamarin.Forms.AppLinks" version="2.5.0.91635" targetFramework="monoandroid71" />
     <package id="Xamarin.GooglePlayServices.AppIndexing" version="42.1021.1" targetFramework="monoandroid71" />     
     <package id="Xamarin.GooglePlayServices.Base" version="42.1021.1" targetFramework="monoandroid71" />
     <package id="Xamarin.GooglePlayServices.Basement" version="42.1021.1" targetFramework="monoandroid71" />
     <package id="Xamarin.GooglePlayServices.Tasks" version="42.1021.1" targetFramework="monoandroid71" />
    
  • VitalyVitaly USMember ✭✭

    There modified source code from working
    https://github.com/xamarin/xamarin-forms-samples/blob/master/DeepLinking/Droid/MainActivity.cs

    and it is my that is not working
    https://github.com/vdchernikov/TestKrista/blob/master/DeepLinking/Droid/MainActivity.cs

    They differ only by versions of libraries and Firebase initializations

  • VitalyVitaly USMember ✭✭

    Have anybody tried my sample?

  • marcnegrimarcnegri CHMember ✭✭

    Hi @Vitaly

    Do you find a workaround regarding your issue ?
    Have you try to try catch your FirebaseApp.InitializeApp(this, options); ?

  • batmacibatmaci DEMember ✭✭✭✭✭

    hi, i am looking for this issue as well. did you guys find any solution for it?

  • VitalyVitaly USMember ✭✭
    edited December 2017

    Hi @batmaci @marcnegri unfortunately I didn't. I raised bug issue on xamarin.bugzilla
    also created new theme https://forums.xamarin.com/discussion/comment/308930 but didn't receive answer.

    So I was needed to return to native indexing with bridges between core and android|ios indexing class. This indexing is working now. You may get this example from their Monkey sample app.

    My native indexing code is for Android

        public Android.Gms.AppIndexing.Action GetAppIndexActionForModel(SearchableItem searchItem)
        {
            //// var url = $"http://monkeysapp.com/Home/Detail/{monkey.Name.Replace(" ", "%20")}";
            var url = searchItem.Url;
    
            var item = new Thing.Builder()
                .SetName(searchItem.Title)
                .SetDescription(string.Empty)
                .SetUrl(Android.Net.Uri.Parse(url))
                .SetType("http://schema.org/Article")
                .SetId(url)
                .Build();
    
            var thing = new Android.Gms.AppIndexing.Action.Builder(Android.Gms.AppIndexing.Action.TypeView)
                .SetObject(item)
                .SetActionStatus(Android.Gms.AppIndexing.Action.StatusTypeCompleted)
                .Build();
    
            return thing.JavaCast<Android.Gms.AppIndexing.Action>();
        }
    

    Android Activity's OnCreate() is catching intent with url from and automaticly passing it to App.xaml.cs OnLinkReceive...()

    Sure adding headers

    [Activity(Icon = "@drawable/AppIcon", Theme = "@style/MyTheme.Base", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] { Intent.ActionView },
    Categories = new[] {
        Intent.CategoryDefault,
        Intent.CategoryBrowsable
    },
    DataScheme = "http",
    DataHost = "datatron.ru",
    DataPathPrefix = "/question")]
    [IntentFilter(new[] { Intent.ActionView },
        Categories = new[]
        {
            Android.Content.Intent.CategoryDefault,
            Android.Content.Intent.CategoryBrowsable
        },
        DataScheme = "http",
        DataHost = "datatron.ru")]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    
  • batmacibatmaci DEMember ✭✭✭✭✭

    can you please share your bugzilla link that i can also follow?

Sign In or Register to comment.