firebase notify

331 views
Skip to first unread message

maurizio raiola

unread,
Aug 17, 2020, 2:44:19 PM8/17/20
to DroidScript
this post is not a criticism but an opportunity for reflection to improve this DS application that every day receives more and more acclaim from the android developer community. An important service that is missing in DroidScript is a plugin to receive firebase notifications, until today those who develop applications with DroidScript have no chance of being able to use this so important service, to date the only alternative is to use android studio, I hope that in the future the creators DS can give us this other chance, thank you and good luck

Dave

unread,
Aug 17, 2020, 4:52:38 PM8/17/20
to DroidScript
I'd be happy to add the necessary manifest entries if someone would like to build a DS plugin for receiving Firebase messages:-



Kallikratidas

unread,
Aug 17, 2020, 6:57:16 PM8/17/20
to DroidScript
This is not something difficult to make, but it is pointless too. It is pointless to make such a plugin, because Google Firebase supports javascript api for connecting to your Firebase project and work over the real-time database, cloud messaging or whatever you want. The only thing someone that wants to use Firebase cloud messaging, is to learn how to use the Firebase api. I have made lots of projects with Google Firebase in DS such as chats and some kind of games. The only problem I faced was when building the Apk. I had to add the network permition manually. 

ECEisLife

unread,
Aug 17, 2020, 8:43:49 PM8/17/20
to DroidScript
I agree to Kallikratidas

Firebase is not a problem to integrate into a DroidScript app. I have created many DroidScript apps also using firebase before and as simple as app.Script("firebase.min.js") will work of course you need the right config object and Network permission

The problem with most users who ask about this push notification, cloud messaging, real-time databases on firebase is that they don't know exactly how firebase works on the web. And since DroidScript js app is just like a web page with a virtual DOM, you can pretty use if not all then most of the web API's. 

maurizio raiola

unread,
Aug 18, 2020, 2:57:04 AM8/18/20
to DroidScript
thank you for your answer, but I believe that DroidScript users will not find any solution to the problem I posed, Dave's post does not talk about http and Javascript and how to implement cloud messaging firebase on DroidScript, even on this group there is no is no user who has posted a full tutorial on how to do it, why? because it is not possible to do it, if we talk about firebase db real-time I tell you that it is possible to work with DroidScript because I did it, while push messages need an https protocol and a permission from the browser that DroidScript for now does not can give, for this reason there will be a need for a native plugin that authorizes the user, it is also true that all my knowledge on firebase is not complete and if someone will be able to give me a clear answer with code and certain result I will be the first to apologize and to congratulate you, I look forward to hearing from you

maurizio raiola

unread,
Aug 18, 2020, 6:27:17 AM8/18/20
to DroidScript
Set up a JavaScript Firebase Cloud Messaging client app
The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API. This includes the browser versions listed in this support matrix and Chrome extensions via the Push API.
The FCM SDK is supported only in pages served over HTTPS. This is due to its use of service workers, which are available only on HTTPS sites. If you need a provider, Firebase Hosting is recommended for free HTTPS hosting on your own domain.

...this post is a google tutorial where it explains how to use cloud messages with javascript, to be used you will need an https page, what has been said is clear that with DROIDSCRIPT it will not be possible to use it, my DROIDSCRIPT SPK project says that the browser is not compatible with firebase security. if there will be any user of the DS group who can prove with facts what I assert, we will be very grateful, otherwise, if there is no answer on the matter, it is clear that there will be no solution to this problem.

Kallikratidas

unread,
Aug 18, 2020, 11:22:08 AM8/18/20
to DroidScript
First of all, would you like to share your project so that we can help you? 
Message has been deleted

maurizio raiola

unread,
Aug 18, 2020, 4:25:18 PM8/18/20
to DroidScript
var firebaseConfig = {
    apiKey: "AIzaSyAB5mr...",
    authDomain: "xxxxx.firebaseapp.com",
    databaseURL: "https://xxxxx.firebaseio.com",
    projectId: "xxxxx",
    storageBucket: "xxxxx.appspot.com",
    messagingSenderId: "...",
    appId: "1:yyyyy:web:xxxxx",
    measurementId: "G-xxxxx"
  };
  
var idAPP = app.GetDeviceId(); 
var cry = "111111";
var api_key="";
var crypt = app.CreateCrypt();
var encryptedId = crypt.Encrypt( idAPP, cry);

function OnStart(){
app.PreventWifiSleep ()
    app.SetOrientation( "Portrait" );
    app.PreventScreenLock( true )
    app.PreventScreenLock(!0)
   app.SetScreenMode( "Game" )
 

  /*********************************FIREBAE***************************************/ 
  
  
  app.Script("Firebase/Firebase_7.15.5/app.js");
  app.Script("Firebase/Firebase_7.15.5/database.js");
  app.Script("Firebase/Firebase_7.15.5/auth.js");
  app.Script("Firebase/Firebase_7.15.5/firebase.js");
  app.Script("Firebase/Firebase_7.15.5/functions.js");
  app.Script("Firebase/Firebase_7.15.5/messaging.js");
  
  

  firebase.initializeApp(firebaseConfig);
  
  db = firebase.database();
  auth = firebase.auth();
  messaging = firebase.messaging();
  
  messaging.requestPermission().then(function(){conslole.log("ok");})
  .catch(function(err){ console.log("error")})
 
  
  db.goOffline();
  CreateListeners();
  ConnectFFT();
  /**********************************FIREBASE**************************************/

  
    
}


function restart(){
//app.Alert('restart')
auth.onAuthStateChanged(OnAuth);
  //On connect/disconnect.
  db.ref(".info/connected").on("value", OnConnectionChange);    
    }


function CreateListeners(){
   
  auth.onAuthStateChanged(OnAuth);
  //On connect/disconnect.
  db.ref(".info/connected").on("value", OnConnectionChange);
  db.ref('uidcode').on("value", OnMessage); 
}





function Connect(){
    //app.Alert('connect')  
  auth.signInWithEmailAndPassword(idAPP+"@helloworld.com", encryptedId).catch(function (e){
});
}


function ConnectFFT()
{
    

  auth.createUserWithEmailAndPassword(idAPP+"@helloworld.com", encryptedId).then(OnAuth)
  .catch(error => {
     if(error.code=='auth/email-already-in-use')
          Connect();
       else if(error.code=='auth/invalid-email')
          console.log(Email address is invalid.);
        else if(error.code=='auth/operation-not-allowed')
          console.log(Error during sign up.);
        else if(error.code=='auth/weak-password')
          console.log('Password is not strong enough. Add additional characters including special characters and numbers.');
        else
          console.log(error.code);
  });
}

function OnAuth(user)
{
  if(user!=null){
  uid = auth.currentUser.uid;
    db.goOnline();
  } else {  
  db.goOffline();}
}
 
   
  function Listen()
{
   // app.HideProgress();
 //speech.Recognize();
}
  
 function OnSuccessSend(){};
 function OnFailedSend(){};

photo_2020-08-18_22-23-44.jpg


Kallikratidas

unread,
Aug 18, 2020, 7:41:55 PM8/18/20
to DroidScript
Well, this code is mostly written by me and you just copied it and added everything you wanted. I have no problem with this, but you could have said it already. Anyway, let me sometime to give  look. 

maurizio raiola

unread,
Aug 22, 2020, 10:09:12 AM8/22/20
to DroidScript
when i entered the post i was looking for a firebase plugin notifications for droidscript many people wrote that it was not necessary to use a plugin because programming with droidscript was not necessary, if i could not write a working code it was because i did not know firebase well, i have requested to post a code to understand where the problem was, but to date none of these people have yet posted a valid code to prove the opposite of what I said, I apologize to this community, but it is no longer clear to say that droidsccript really can't have this function?

Steve Garman

unread,
Aug 22, 2020, 10:19:38 AM8/22/20
to DroidScript
Maurizio

I believe you were right to say that this could not be done without a plugin and I think it is possible that such a plugin would need modifications to the DroidScript manifest, which Dave has stated that he would be prepared to do if someone tries to write such a plugin and gives him details of the manifest requirements.

Like you, I would be delighted if someone can prove me wrong by producing a DroidScript SPK that can work with Firebase notifications.

maurizio raiola

unread,
Aug 22, 2020, 10:44:37 AM8/22/20
to DroidScript
Hi Steve, I have read many of your interventions and I have always thought that you are a real and sincere person. today we have not solved our problem but what you say heartens me because it repays me for the many days and many sleepless nights looking for a solution that has never arrived because it will never arrive. The reason for my resentment is because I think this group should be a lifeline for those who have chosen to use droidscript, while sometimes it is not. The work of the programmer is very difficult, and only with mutual and sincere help will it be possible to reach the objectives. Steve I to solve the problem I thought of making php do the work by sending a get request from the DS app to the php server and vice versa, another solution is to use db realtime for the connection and activate the notification in DS with notify = app.CreateNotification (). good job

Symbroson

unread,
Aug 22, 2020, 10:45:21 AM8/22/20
to DroidScript
I've not used firebase anywhere before but according to the tutorials I've found in 20 seconds of research this should be fairly easy to implement

both say the manifest requires

      <intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>

I really don't know if that's the whole story and I can't try it myself.

If anyone wants to please follow my plugin tutorials here and see if you can get your notifications working or if you need Dave to add the intent to the DS manifest

note that recently I was able to create plugins with intellij as well - so you don't necessarily need to download and install AndroidStudio if you already have Intellij

maurizio raiola

unread,
Aug 22, 2020, 11:01:31 AM8/22/20
to DroidScript
Thanks for your answer, I have already built an app with androidstudio using firebase notify and it works very well, I wanted to use DS because for some jobs it is very fast. The debate arose because someone in the group said that it was possible without using a plugin and I was not convinced, now I will try to build a plugin to use firebase notify on DS, if anyone would like to help me I would be very grateful

Kallikratidas

unread,
Aug 22, 2020, 12:08:45 PM8/22/20
to DroidScript
I still believe that no plugin is need for this purpose. What is this plugin going to include exactly or offer that DS already can't offer? Are you going to coppy all of the firebase functions, methods and sources? What if firebase next versions change some rules or any of current rules? Google mass many changes to very api really frequently. Will this plugin be up-to-date in every GoogleFirebase release? And finally, everything provided by google's api is working apart from the Firebase messages. What if it can work just by adding a  permition or by modifying the build.json file? 

Steve Garman

unread,
Aug 22, 2020, 12:17:19 PM8/22/20
to DroidScript
What it offers is communicating with an app that is not running.

Because Google now offer a formal way to accept a firebase push notification it is reasonable to expect future versions of Android to continue to work with it.

Nobody is trying to hack anything here.

Symbroson

unread,
Aug 22, 2020, 12:25:53 PM8/22/20
to DroidScript
maurizio If you already have successfully created an app with the requested features then please do as Dave and Steve suggested and write a message to Dave and give him details what the requirements are to implement it to DroidScript.


maurizio raiola

unread,
Aug 22, 2020, 12:37:39 PM8/22/20
to DroidScript
OK, I'll write to dave to give him my idea of how to implement Firebase notifications with DS

maurizio raiola

unread,
Aug 22, 2020, 12:43:33 PM8/22/20
to DroidScript
to work on DS Firebase notify dot would work with google web scripts but needs, for security problems, to communicate with an https protocol, DS does not manage ssl on its browser, for this reason firebase fails, the plugin should create the necessary native permissions, while dB realtime is built to work without using web security

Dave

unread,
Aug 24, 2020, 4:42:19 PM8/24/20
to DroidScript
DS can do https client connections no problem (it uses the Chrome browser engine)... just use the xmlHttpRequest object as normal.

As I said earlier, someone just needs to write a firebase push notification plugin (I don't have time) and I'll modify the DS manifest as required.  It can't be done in pure JS as the push messages need to wake up the app when it is closed and this is done via Google Play using intents and requires a manifest entry.

Reply all
Reply to author
Forward
0 new messages