Comments (18)
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.
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.
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
-
Generate FCM token on the TWA side
-
on the startURL place the FCM token as a url parameter. for example
www.site.com?fcmtoken=abcd
-
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.
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.
@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.
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.
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.
@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.
#25 adds notification delegation. Does the diff help you?
from svgomg-twa.
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.
Is the problem that you are getting the Chrome icon when receiving the notification?
from svgomg-twa.
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.
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.
ill try that and let you know when thats done, thanks for the tip!
from svgomg-twa.
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.
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.
(if you want any more help, could you please create a new issue on Android Browser Helper?)
from svgomg-twa.
(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)
- TWA top url bar not hiding HOT 2
- Unable to instantiate service androidx.browser.trusted.TrustedWebActivityService HOT 4
- how to use fcm push notification on TWA apk HOT 1
- Does TWA notification delegation handle sound also? HOT 9
- My TWA is crashing multiple times. HOT 7
- [Question] Adsense in PWA/TWA HOT 3
- Setting Notifications to true still asks for permission from user HOT 7
- Hide div in twa in-app browser HOT 1
- Running the TWA from a Chromebook just opens the URL in the browser and not a standalone window HOT 5
- TWA app can't run independently without running chrome browser first HOT 1
- Android TV app HOT 1
- open new a tab (url) inside of TWA by browser which is not inside of TWA HOT 1
- Update Android SDK studio to version 30 HOT 1
- Facebook Comments Plugin Not Working in The TWA HOT 1
- How to prevent app from going into background when a class 0 SMS (flash SMS) pops up thus preventing UPI verification.
- Android generating 404 errors on TWA website
- TWA asset ink is updated but address bar is visible HOT 4
- Android Browser Helper version HOT 2
- Multiple TWAs created for the same domain but google search only indexes one TWA HOT 1
- notifications only display when the phone is unlocked
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svgomg-twa.