GithubHelp home page GithubHelp logo

Comments (18)

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024 1

seems its working! One last thing, based on your commit, you can set the badge and notification icon right? well that option doesnt work for me, it just shows the chrome icon (on the status bar), and when expanding the bar i get a blank icon. any idea? I have tried with svg, png assets

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

Firebase Cloud Message for Web should work as expected inside a TWA. You can find more information here: https://firebase.google.com/docs/cloud-messaging/js/receive

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

They do work as expected, the problem is when saving the token to a certin user when you have a log in on your website, because you cannot access local storage, so there is no way(at least native) we can connect the generated token to the user. But I think I just found a workaround

If anybody is having this issue here is what I came up with. It may not be the best solution but it works

  1. Generate FCM token on the TWA side

  2. on the startURL place the FCM token as a url parameter. for example www.site.com?fcmtoken=abcd

  3. when accessing to your app, the request will have the user and the query parameter, so you can handle it on your backend, in my case is RoR, so i just get the current_user + params[:fcmtoken]

In case you got something cleaner please le me know, because I don't really like this approach, but is what i've got.

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

Hi @Dvelezs94

I'm not sure I understand what is not working. Can you provide more details? It seems you are generating the FCM token on the Native side. Is that correct?

Andre

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

@andreban yes that is correct, and because the TWA code cannot access the PWA code, the token cannot be shared except if you implement some hacky method like the one I mentioned in the previous comment

The reason Im generating the token in the TWA side is because i want to have native notifications, not web notifications

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

Gotcha - Chrome 75 will enable notification delegation. There's more information on how to enable it and how it works here.

On this case, it would be possible to use the Web APIs, but delegate showing the notification itself to native.

This can already be tested using Chrome Canary.

Would this help on your case?

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

the problem with that is, browsers other than chrome will not receive the notifications, thats why native is much better at this point :/. I didn't know that capability tho, it seems interesting, but until other browsers support that feature, its hard for me to go with it

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

@andreban im pretty new to android development, so can you please help me on this part?

I am trying out your suggestion, but idk how to exactly put that "service" in my android manifest file

Here is my AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.placeholder">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="${launcherName}"
        android:supportsRtl="true"
        android:theme="@style/Theme.TwaSplash">

        <meta-data
            android:name="asset_statements"
            android:value="${assetStatements}" />

        <activity android:name="android.support.customtabs.trusted.LauncherActivity"
            android:label="${launcherName}">
            <meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="${defaultUrl}" />

            <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"/>
                <data android:scheme="https"
                    android:host="${hostName}"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Thanks in advance

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

#25 adds notification delegation. Does the diff help you?

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

I tried it and i receive the notification, but as if it was from the browser, not from the app. So basically I get the same result as if I didn't have that option. So im not sure what that does exactly

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

Is the problem that you are getting the Chrome icon when receiving the notification?

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

I see the difference now, it is more native-like. The problem is still that the notification doesnt arrive if chrome wasn't opened recently. and I dont think its a resource issue because I have a huawei mate 20, So do you know a way to get the notification, even when the app or the browser have been closed for a while? - thats why I think implementing native notifications would be much more efficient

from svgomg-twa.

andreban avatar andreban commented on August 16, 2024

Interesting - notifications should definitely arrive. Could you try disabling battery optimisations and check if the notifications arrive in that case?

I've seen phones with more radical battery optimisations killing background services before and I wonder if that's the case.

(Not sure if this doc helps explain how to disable those)

from svgomg-twa.

Dvelezs94 avatar Dvelezs94 commented on August 16, 2024

ill try that and let you know when thats done, thanks for the tip!

from svgomg-twa.

7even-ux avatar 7even-ux commented on August 16, 2024

Hi. I would like to pass FCM token in the url. My code doesnt work everytime, i think needs a delay but i cant handle it. Any hint wwould be much apreciated.
`public class LauncherActivity
extends com.google.androidbrowserhelper.trusted.LauncherActivity {
public static String x = null;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//RegisterToTopic for FCM
FirebaseMessaging.getInstance().subscribeToTopic("all");
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener() {
@OverRide
public void onComplete(@nonnull Task task) {
// Get new FCM registration token
x = task.getResult();
}
});
}

@Override
protected Uri getLaunchingUrl() {
    // Get the original launch Url.
    Uri uri = super.getLaunchingUrl();
       // Append the extra parameter to the launch Url
    return uri
            .buildUpon()
            .appendQueryParameter("z", String.valueOf(x))
            .build();
}

}`

from svgomg-twa.

PEConn avatar PEConn commented on August 16, 2024

Hey,

So first things first, you'll want to use android-browser-helper instead of this repo - it's the newer version we're doing active development on.

OK, so yeah it seems a reasonable assumption that there's some race condition - sometimes the TWA launches before the firebase connection has been made.

Our code currently isn't set up so that you can delay starting the TWA particularly easily, but you should be able to make it work with something a bit hacky like this:

public class MyLauncherActivity extends LauncherActivity {
  private static class DelayedTwaLauncher extends TwaLauncher {
    @Override
    public void launch(TrustedWebActivityIntentBuilder twaBuilder,
                         CustomTabsCallback customTabsCallback,
                         @Nullable SplashScreenStrategy splashScreenStrategy,
                         @Nullable Runnable completionCallback,
                         FallbackStrategy fallbackStrategy) {
    if (firebase has finished loading) {
      super.launch(twaBuilder, customTabsCallback, splashScreenStrategy, fallbackStrategy);
    } else {
      // Save the parameters to some variables.
      // Don't do anything else.
    }
  }

  public void actuallyLaunch() {
    if (we didn't call super.launch before) {
      super.launch(the parameters you saved before);
    }
  }

  @Override
  protected TwaLauncher createTwaLauncher() {
    return delayedTwaLauncher;
  }
}

So basically what you're doing is creating a DelayedTwaLauncher which overrides the bahaviour of the TwaLauncher class. If launch is called before your firebase connection is ready, we don't do anything and just save launch's parameters. Once your firebase connection is ready, call actuallyLaunch, which launches the TWA.

If the firebase connection finishes before launch is called, just call super.launch.

from svgomg-twa.

PEConn avatar PEConn commented on August 16, 2024

(if you want any more help, could you please create a new issue on Android Browser Helper?)

from svgomg-twa.

7even-ux avatar 7even-ux commented on August 16, 2024

(if you want any more help, could you please create a new issue on Android Browser Helper?)

Thank you for your help. Unfortunately i cant handle it. I made a new issue on Android Browser Helper. Maybe there i will achive it.

from svgomg-twa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.