0

I'm creating Xamarin.Forms App and it has a service that runs in the background monitoring if any messages arrive. If a message arrives, the service should open the App. I tried to open the App using Intent (Dependency Service) and I also tried using Xamarin.Essentials. Neither way worked. My last attempt was with Xamarin.Essentials and gave the following error: [Error][1] [1]: https://i.stack.imgur.com/5jPGf.png

This is my code using Intent (Dependency Service):

//Intent (Dependency Service)
   string teste = "com.saferit.saferproject";
   openAppManager = DependencyService.Get<IAppHandler>();
   openAppManager.Initialize(teste);
   openAppManager.LaunchApp();

[enter image description here][2] [2]: https://i.stack.imgur.com/lLx3g.png

This is my native code for Android

public void LaunchApp()
    {
        Intent intent = new Intent();
        intent.SetClassName(Package, "activity");
        intent.AddFlags(ActivityFlags.NewTask);
        Xamarin.Forms.Forms.Context.StartActivity(intent);
    }

[Complete Native Code][3] [3]: https://i.stack.imgur.com/G4zOV.png

This is my AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.saferit.saferproject" android:installLocation="preferExternal">
    <uses-sdk android:minSdkVersion="27" android:targetSdkVersion="29" />
    <!--<application android:label="SaferProject.Android"></application>-->
  <application android:label="com.saferit.saferproject" android:icon="@drawable/logo">
    <activity android:icon="@drawable/logo" android:label="com.saferit.saferproject" android:name="com.saferit.saferproject">
      <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:scheme="com.saferit.saferproject" />
      </intent-filter>
    </activity>
  </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

This is my attempt using Xamarin.Essential:

  //Xamarin.Essentials
  var appname = "com.saferit.saferproject://";
  var supportsUri = await Launcher.CanOpenAsync(appname);
  if (supportsUri)
     await Launcher.OpenAsync(appname);

Looking for here at stackoverflow I found this question: Open Notification list page when user clicks on navigation

I tried to implement it on my App but I also couldn't get it to work. In all three cases the errors are very similar. I think the problem is in the configuration of the URI of my App. Can someone help me?

  • You can open the application using notification. I have attached the sample application https://github.com/RenjitGit/StackQA/tree/main/StackQAXFNotification for your reference. But from Android Q has limitation to open application from background without user interaction. Clicking on notification can open the app (https://stackoverflow.com/a/59421118/8892050). – Ranjit Feb 14 '21 at 15:29
  • I'm sorry, Ranjit. The day I saw your answer, I was feeling bad .. I found out that I was infected with COVID-19 and, since then, I haven't logged into StackOverflow anymore. I got really bad and my wife and kids took it too. Thank goodness, everything is fine now. Your tip for opening the App using notifications was perfect and it was exactly what I was needing. I apologize a thousand again ... Thanks so much! – A. Serra Mar 18 '21 at 04:00
  • Good to hear that you are doing well. Thanks for your response. – Ranjit Mar 19 '21 at 16:20

0 Answers0