SolutionsDev

Here, you can find codes and help, and also make requests for custom code.

Latest Blog Posts

Sending Firebase Cloud Messaging (FCM) Notifications Using Google Apps Script and Web App

Sending Firebase Cloud Messaging (FCM) Notifications Using Google Apps Script and Web App

Firebase Cloud Messaging (FCM) is a powerful tool that allows you to send notifications to users. In this blog, we will walk through how to create a web app using Google Apps Script that allows you to send FCM notifications by calling a URL with parameters.

Prerequisites 

  • A Firebase Project.
  • Service Account credentials (client email, private key, and project ID).
  • Basic understanding of Google Apps Script.

Steps to Implement the Solution

Here’s how you can set up and deploy a Google Apps Script web app that sends FCM notifications by simply accessing a URL.


1. Set Up Firebase and Generate Service Account Credentials

Before diving into the code, ensure you have set up Firebase and have your service account credentials ready.

  • Go to the Firebase Console.
  • Select your project.
  • Navigate to Project Settings > Service Accounts.
  • Click Generate New Private Key and download the JSON file.
  • Note down the client_email, private_key, and project_id.

2. Update the Script

Below is the JavaScript code that we will use. This script contains two main functions:

  • myFunction(): This function generates a JWT access token using your Firebase service account credentials.
  • sendMsg(): This function sends an FCM notification using the generated access token.

Script:

var clientemail = "your client email";
var privateKey = "your private key";
var project = "your project id";


function myFunction() {

  var header = `{
    "alg":"RS256",
    "typ":"JWT"
  }`;
  var time = new Date().getTime()/1000;
  var expiration = time + 3600;


var payload = "{'iss':'"+ clientemail+"','scope': 'https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/firebase.messaging','aud' : 'https://oauth2.googleapis.com/token','exp':"+expiration+",'iat' :"+ time+"}";


var base64Header = Utilities.base64Encode(header).replace(['+','/','='],['-','_','']);
// console.log(payload);
var base64Payload = Utilities.base64Encode(payload).replace(['+','/','='],['-','_','']);

var signatureInput = base64Header+"."+base64Payload;

var signature = Utilities.computeRsaSha256Signature(signatureInput,privateKey);

var base64UrlSignature = Utilities.base64Encode(signature).replace(['+','/','='],['-','_','']);

var jwt = base64Header+'.'+base64Payload+'.'+base64UrlSignature;


var payload2 = {
       'grant_type' : 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    'assertion' : jwt

  };
 
  var url ='https://oauth2.googleapis.com/token';
  // Options for the POST request
  var options = {
    'method' : 'post',
    'contentType': 'application/json',
//    'headers': headers,
    'muteHttpExceptions':true,
    'payload' : JSON.stringify(payload2)
  };
 
  // Make the POST request
  var response = UrlFetchApp.fetch(url, options);

// console.log(response.getContentText());

var json = JSON.parse(response.getContentText());


console.log(json["access_token"]);

return json["access_token"];
 
}


function sendMsg(title,msg) {
 
  var message = {
    "message": {
      "topic": "all",
      "notification": {
        "title": title,
        "body": msg
      },
      "data":{
      }
    }
  };


  var options = {
    headers: {
     
      "Content-Type": "application/json; charset=UTF-8",
      "Authorization": "Bearer " + myFunction()
    },
     method:"post",
    payload: JSON.stringify(message),
   muteHttpExceptions :true
  }

console.log(options)

  var resp = UrlFetchApp.fetch('https://fcm.googleapis.com/v1/projects/' + project + '/messages:send', options);

console.info(resp.getContentText())
if(resp.getContentText().includes("error"))
  return JSON.parse(resp.getContentText())["error"]["message"];
return "Message sent successfully";
}



function doGet(e){

    try{
      var title = e.parameter.title;
      var msg = e.parameter.msg;
    }catch{
      var title = "test";
      var msg = "test msg";
    }

   return ContentService.createTextOutput().append(sendMsg(title,msg)).setMimeType(ContentService.MimeType.TEXT);
}

Explanation of the Code:

  • myFunction(): This function creates a JWT token using Firebase credentials (clientemail and privateKey), which is then used to generate an access token for authentication.
  • sendMsg(): This function sends the FCM message to all devices subscribed to the "all" topic. The message payload includes the title and body of the notification.
  • doGet(): This function allows you to pass title and msg as URL parameters, so you can easily trigger a notification by visiting a URL.

3. Deploy the Script as a Web App

To deploy the script as a web app, follow these steps:

Step 1: Save the Script

  • Once the script is written, go to File > Save to save your project.

Step 2: Deploy the Web App

  • Click on Deploy > New deployments > Select Type: Web App.
  • Under Execute as, choose Me.
  • Under Who has access, select Anyone.
  • Click Deploy and note down the generated web app URL.

4. Send Messages via URL

You can now send FCM messages by accessing the deployed web app URL with query parameters for the title and message. For example:

perl
https://script.google.com/macros/s/your-web-app-id/exec?title=Hello&msg=Welcome to FCM Notifications

This URL will trigger the doGet() function, which sends a notification with the title Hello and the message Welcome to FCM Notifications to all devices subscribed to the all topic.


5. Testing and Debugging

  • Open the URL in a browser with different titles and messages to test if the FCM messages are sent successfully.
  • Use the Firebase Console to verify whether notifications are received by the devices.

Conclusion

Using Google Apps Script as a web app to send Firebase Cloud Messaging notifications is an efficient way to handle notifications without the need for complex server-side solutions. By simply accessing a URL with query parameters, you can send notifications to all devices subscribed to a specific FCM topic.

Now you have an easy-to-deploy, lightweight system for sending notifications via FCM. This method is ideal for lightweight applications or automation needs.

 Resolving Sketchware App Closing Issue: A Step-by-Step Guide

Resolving Sketchware App Closing Issue: A Step-by-Step Guide

Introduction: 

 App closing issues can be frustrating for developers, but with the right approach, they can be resolved efficiently. In this blog post, we'll guide you through the process of identifying and fixing app closing problems in Sketchware-built applications. 

 Step 1: Create a Blank Testing Screen 

 Begin by creating a blank screen in your Sketchware app specifically designed for testing purposes. Add a button on this screen that will lead to the main screen of your application. This needs for check where and which error occurs.

Step 2: Change Launch Activity 

 Navigate to the Modify Android manifest and change the launch activity to the newly created testing screen. This step is crucial for isolating and identifying the source of the app closing issue. 


 Step 3: Build and Test 

 Build the application and launch it. If the app closes and reopens with an error, this is a positive indication that the issue lies within the app's logic or components. These type of errors can be solved by coding knowledge.

 Step 4: Verify Package Name 

 If the app still doesn't open or if you encounter persistent issues, double-check your package name. Ensure that it starts with a lowercase character, following the convention like "com.comp.appname," not "Com.comp.appname." 

 Step 5: Problem Solved 

 By systematically going through these steps, you should have identified and resolved the app closing issue in your Sketchware-built application. Regularly testing and debugging your app can help prevent such problems in the future. Also you can change launch screen to main screen after solving issues.

 Conclusion: 

 Closing issues in Sketchware apps can be intricate, but with a methodical approach, they can be resolved effectively. By creating a dedicated testing screen, changing the launch activity, and verifying the package name, you can identify and fix app closing problems. Stay vigilant, and your Sketchware app will run smoothly without unexpected closures.

Sketchware: Adding Dependencies or Local Libraries

Sketchware is a powerful platform for Android app development, but sometimes you need to enhance its capabilities by adding external libraries. This guide will walk you through the process of adding dependencies or local libraries to your Sketchware project.
Step 1: Navigate to Maven Repository
Go to Maven Repository using your preferred web browser.Utilize the search bar to find the library you need.
Step 2: Access the Repository
Click on the library you've chosen to view its details.
Step 3: Check the Latest Version
Identify and note the latest version of the library.
Step 4: Open Sketchware and Add the Library
Open your Sketchware project.Access the "Library" section and click on "Add Local Library."

Step 5: Download the Library
Paste the dependency information using the format: Url:name:version Example: com.unity3d.ads:unity-ads:4.9.0Click on "Download" and choose either DX or D8 (D8 is recommended).

Step 6: Start the Download
Click on "Start" to initiate the download process.

Step 7: Locate the Downloaded Library
Once downloaded, find the library in your project files. It will be named as name_version.
Step 8: Confirm the Library Integration
Click on the check mark icon (✅) to confirm the successful addition of the library.

Step 9: You're Done!
Congratulations! You have successfully added a library to your Sketchware project. Now you can harness the additional features and functionalities provided by the external library in your app development journey. Happy coding!

Track Your AppLovin Revenue with the AppLovin Revenue Checker App

Introduction

In the competitive world of mobile app development, maximizing your revenue is essential. AppLovin is a popular mobile advertising platform that offers monetization opportunities for app developers. To keep a close eye on your earnings through AppLovin, we introduce the "AppLovin Revenue Checker App." This app simplifies the process of tracking your revenue by allowing you to enter your report key and view your earnings hassle-free. The best part? It's completely ad-free!


Full tutorial: https://youtu.be/kKLYgBId4Ac


Key Features of the AppLovin Revenue Checker App


1. User-Friendly Interface: The AppLovin Revenue Checker App is designed with simplicity in mind. Upon opening the app, users are greeted with an intuitive interface that's easy to navigate.


2. Report Key Entry: To get started, all you need to do is enter your AppLovin report key. This is a one-time setup, so you don't have to repeat the process every time you use the app.


3. Date Selection: Once your report key is saved, you can select any date you want to view your revenue for that specific day.


4. Quick Load: With just a tap of a button, the app loads your revenue data for the selected date. No unnecessary waiting or complicated steps involved.


5. Ad-Free Experience: We understand that ads can be intrusive and distracting. That's why the AppLovin Revenue Checker App is completely ad-free. Your focus remains on your earnings.


6. Secure and Private: We take your data privacy seriously. Your report key and revenue information are securely stored on your device. We do not collect, store, or share any of your data.


How to Use the AppLovin Revenue Checker App


Using the app is a breeze. Here's a simple step-by-step guide:


1. Download and Install: https://shrs.link/9JQokv (Affiliate Link)

2. Enter Your Report Key: Upon first launch, enter your AppLovin report key. This step is a one-time process.



3. Select Date: Choose the date for which you want to check your revenue.

4. Load Revenue: Press the "click to load" button. Your earnings for the selected date will be displayed.

Why Choose the AppLovin Revenue Checker App


1. Efficiency: The app simplifies revenue tracking, saving you time and effort.


2. Ad-Free: No annoying ads to disrupt your experience.


3. Privacy: Your data is kept safe and private on your device.


4. No Account Required: You don't need to create an account or log in, keeping the process straightforward.


5. Reliable: The app provides accurate revenue data from AppLovin.


Conclusion


In the competitive app development industry, keeping a close eye on your earnings is vital. The AppLovin Revenue Checker App streamlines this process, making it easier than ever to track your AppLovin revenue. With its user-friendly interface, one-time setup, ad-free experience, and data privacy, it's the perfect companion for app developers seeking to optimize their monetization efforts. Download the AppLovin Revenue Checker App today and take control of your earnings.


Introducing New Blocks for Sketchware: Supercharge Your Recycler View!

Exciting news for the Sketchware community! We're thrilled to announce that we've taken a giant leap forward in enhancing your app development experience. Say hello to Blocks for Sketchware for the RecyclerView, an exciting new addition that opens up a world of possibilities for your projects. With an array of powerful features, it's time to unlock the full potential of your app's user interface.


⬇️Download Recycler View Blocks⬇️ (Affiliate Link)

⬇️Download Demo apk⬇️ (Affiliate Link)


Watch complete Video : https://youtu.be/UiiLvc0-R4E


1. Movable and Swipe Able Items

Tired of static, unresponsive elements in your app? Now, you can make your RecyclerView items come to life. With movable and swipeable items, you can create interactive and engaging user experiences like never before.


2. Real-Time Item Updates

Keep your content fresh and dynamic with real-time item updates. Whether it's news feeds, chat messages, or any other data-driven content, your app can now reflect changes instantly.


3. Scrollable Management

Effortlessly manage your Recycler View's scroll behavior. Customize the scrolling experience to fit your app's unique requirements, ensuring a seamless and intuitive user journey.


4. Automatic Item Width Adjustment

No more worrying about the right item width. The automatic item width adjustment takes the hassle out of designing your RecyclerView, making it easier to create aesthetically pleasing layouts.


5. Access to the Positions of the First and Last Visible Items

Get a grip on what your users see. With access to the positions of the first and last visible items, you can tailor your app's behavior to provide the most relevant content.


6. Versatile Layout Changes: Vertical, Horizontal, Grid, and Staggered

Flexibility is key in app development, and our Blocks for Sketchware offer just that. Switch between vertical, horizontal, grid, and staggered layouts effortlessly to give your app a fresh and unique look.


7. The Ability to Find Views by Position and Use Them from Anywhere

Unleash the full potential of your app by finding views based on their position and using them anywhere in your project. This feature opens up endless possibilities for personalization and customization.In a world where user experience is everything, these new Blocks for Sketchware for the RecyclerView are a game-changer. Your app development process just got a whole lot easier, more dynamic, and infinitely more exciting.


Don't miss out on this opportunity to revolutionize your app development with these incredible features. Sketchware has just become an even more powerful tool in your arsenal. Get started today and watch your app come to life like never before!

Firebase Realtime Database: Set Region Implementation Guide

Creating a Custom Region Firebase Realtime Database in JavaScript: A Step-by-Step Guide.

1. create javascript as you want.

2. implement latest version libraries.
    <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>

3. Copy configuration from project settings > general > apps > config.

4. Implement in your javascript.

5. Here, in the database URL, the region is mentioned.

Note : libraries must be latest.

Demo,
  <!DOCTYPE html>
<html>
<head>
  <title>Firebase Realtime Database Example</title>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
</head>
<body>
  <h1>Firebase Realtime Database Example</h1>

  <script>
    // Initialize Firebase
    var firebaseConfig = {
      apiKey: "YOUR_API_KEY",
      authDomain: "YOUR_AUTH_DOMAIN",
      databaseURL: "YOUR_DATABASE_URL",
      projectId: "YOUR_PROJECT_ID",
      storageBucket: "YOUR_STORAGE_BUCKET",
      messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
      appId: "YOUR_APP_ID"
    };
    firebase.initializeApp(firebaseConfig);

    // Get a reference to the database
    var database = firebase.database();

    // Fetch data from the database
    database.ref("data").on("value", function(snapshot) {
      var data = snapshot.val();
      console.log(data); // Do something with the fetched data
    });

    // Update data in the database
    var newData = {
      name: "John Doe",
      age: 25,
      email: "johndoe@example.com"
    };
    database.ref("data").set(newData);
  </script>
</body>
</html> 


Changing Status Bar Text Color to Black in Sketchware: A Step-by-Step Guide

 Here, we will explain how to change status bar text color to black step by step.

1. Open sketchware app and first of all create a app if not.


2. Go to advance settings and set primary dark color to white (any color ). It will be status Bar's background color.


3. Open Show Source Code from right side.

4. Select styles.xml file.

5. Copy last item of Theme.Material.Light.DarkActionBar .

6. Open on create activity and add XML block from more blocks.



7. Set refrence as what you copied.


8. Add source '<item name="android:windowLightStatusBar">true</item>'.


9. Set command to 'add'.


10. Set file name to 'styles.xml'.


Done. Now Build your apk file .


Note that : This change will be for all screens.

Total Pageviews

Followers

Contact Us