Home Blog Page 3

Sell Code and Earn Money

0

Are you a developer or designer looking for a way to earn money from your skills and expertise? If so, selling code and other digital products can be a great way to monetize your skills and turn your passion into a profitable business.

Here are a few tips on how to sell code and earn money:

  1. Find a market for your products: The first step in selling code and other digital products is to find a market for your products. This means identifying the needs and interests of your target audience and creating products that meet those needs. For example, if you are a WordPress developer, you might consider creating plugins or themes that meet the specific needs of WordPress users.
  2. Create high-quality products: In order to sell code and other digital products, you will need to create products that are of high quality and offer value to your customers. This means taking the time to test and debug your products, as well as including clear documentation and support.
  3. Choose a marketplace: Once you have identified a market for your products and created high-quality products, the next step is to choose a marketplace where you can sell your products. There are many online marketplaces available, such as Codecanyon, ThemeForest, and Envato Market, that allow you to sell your products to a global audience.
  4. Promote your products: In order to sell code and other digital products, you will need to promote your products to potential customers. This can involve creating marketing materials, such as landing pages or promotional emails, as well as using social media and other online marketing channels to reach your target audience.

best code-selling market

There are many online marketplaces where you can sell code and other digital products. Some popular options include:

  1. Codecanyon: Codecanyon is a marketplace for buying and selling scripts, plugins, and templates for a variety of platforms and technologies. It is owned and operated by Envato, a company that provides a platform for creative professionals to sell their digital products to a global audience.
  2. ThemeForest: ThemeForest is a marketplace for buying and selling website templates and themes for a variety of platforms, including WordPress, Joomla, and Drupal. It is owned and operated by Envato, and is a popular destination for developers and designers looking to sell their products to a global audience.
  3. Envato Market: Envato Market is a marketplace for buying and selling digital products, including scripts, plugins, and templates for a variety of platforms and technologies. It is owned and operated by Envato, and offers a wide range of products for web development, design, and other creative fields.
  4. GitHub Marketplace: GitHub Marketplace is a platform for buying and selling code and other digital products, specifically for developers. It allows developers to sell their products directly to other developers and is a popular destination for open-source projects and tools.

These are just a few examples of the many marketplaces available for selling code and other digital products. You can choose the marketplace that best meets your needs based on your target audience, the types of products you are selling, and your specific goals and objectives.

how to Choose a marketplace for selling code.

When choosing a marketplace for selling code and other digital products, there are a few key factors to consider:

  1. Target audience: The first thing to consider is your target audience. Different marketplaces cater to different types of buyers, so you will want to choose a marketplace that is frequented by your target audience. For example, if you are selling WordPress plugins, you might consider Codecanyon or ThemeForest, as these marketplaces are popular with WordPress users.
  2. Product type: You will also want to consider the types of products you are selling when choosing a marketplace. Some marketplaces specialize in specific product categories, such as scripts, plugins, or templates, while others offer a wider range of products. Choose a marketplace that is well-suited to the types of products you are selling.
  3. Fees and commissions: Another factor to consider is the fees and commissions charged by the marketplace. Some marketplaces charge a percentage of each sale as a commission, while others charge a flat fee. Make sure to compare the fees and commissions of different marketplaces to find the one that offers the best value for your business.
  4. Reputation and credibility: Finally, you will want to choose a marketplace that has a good reputation and is credible. Look for marketplaces that are well-established and have a track record of providing a good experience for both buyers and sellers.

By considering these factors, you can choose the marketplace that is best suited to your needs and goals for selling code and other digital products

how to promote for selling code.

To effectively promote your code and other digital products for sale, you can use a combination of the following strategies:

  1. Create a marketing website: A marketing website is a dedicated website that is used to promote and sell your products. You can create a marketing website using a platform such as WordPress or Wix, and use it to showcase your products and provide information about your business.
  2. Use social media: Social media platforms such as Facebook, Twitter, and LinkedIn are a great way to promote your products and reach a wider audience. Use social media to share updates about your products, post links to your marketing website, and engage with your followers and potential customers.
  3. Use email marketing: Email marketing allows you to send promotional emails to a list of subscribers who have opted in to receive updates from your business. Use email marketing to keep your customers and followers informed about new products, sales, and other special offers.
  4. Use paid advertising: Paid advertising, such as Google AdWords or Facebook Ads, allows you to target specific audiences and promote your products to a wider audience. Use paid advertising to reach potential customers who are actively searching for products like yours.
  5. Participate in online communities: Online communities, such as forums and discussion groups, are a great way to engage with potential customers and promote your products. Join relevant communities and participate in discussions to showcase your expertise and build your reputation as a trusted seller.

By using these strategies, you can effectively promote your code and other digital products and increase your sales.

By following all these tips, you can successfully sell code and other digital products and earn money from your skills and expertise. With a little hard work and dedication, you can turn your passion for development and design into a profitable business.

if you want to read our other posts you can check our blog section

All about Android Toast

0

Toasts are a way to display short, temporary messages to the user in Android. They appear on the screen for a short period of time and then automatically disappear. Toasts are often used to provide feedback to the user, such as when an action has been completed successfully or an error has occurred.

To create a Toast in Android, you can use the Toast.makeText() method, which takes three arguments: the context, the message text, and the duration of the Toast. For example:

Toast.makeText(getApplicationContext(), "Toast message", Toast.LENGTH_SHORT).show();

This will create a Toast with the message “Toast message” that appears on the screen for a short period of time (specified by the duration argument).

You can customize the appearance and behavior of Toasts by using the Toast class directly and setting various properties, such as the duration, gravity, and animation. You can also create custom Toasts by creating a layout file and using the LayoutInflater class to inflate the layout and set it as the view for the Toast.

Toasts are useful for displaying brief messages to the user, but they should not be used for more important or persistent notifications. For these types of notifications, you should use a notification system such as the Android Notification API.

android custom toast:

Android custom Toasts are Toasts with a custom layout and appearance. By default, Toasts in Android use a simple layout with a message text and an icon, but you can create a custom layout for your Toasts to give them a more unique or customized look.

To create a custom Toast in Android, you can use the LayoutInflater class to inflate a custom layout file and set it as the view for the Toast. Here is an example of how you can create a custom Toast in Android using Java:

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

// Create a custom layout for the toast
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View toastLayout = inflater.inflate(R.layout.custom_toast, null);

// Set the custom layout as the view for the toast
TextView toastText = toastLayout.findViewById(R.id.toast_text);
toastText.setText("Toast message");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(toastLayout);

// Show the toast
toast.show();

This example creates a custom layout for the Toast using the LayoutInflater class, and sets the custom layout as the view for the Toast. You can customize the appearance of the Toast by modifying the layout file custom_toast.xml and the view elements it contains.

You can also customize the behavior of the Toast by setting various properties of the Toast object, such as the duration, gravity, and animation.

Note that you will need to replace R.layout.custom_toast with the resource ID of your custom layout file, and R.id.toast_text with the ID of the TextView element in the layout.

how to create android toast custom view –

To create a custom Toast in Android with a custom view, you can use the setView() method of the Toast class to set a custom view as the content of the Toast.

Here is an example of how you can create a custom Toast in Android with a custom view using Java:

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

// Create a custom view for the toast
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View toastLayout = inflater.inflate(R.layout.custom_toast_view, null);

// Set the custom view as the view for the toast
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(toastLayout);

// Show the toast
toast.show();

This example creates a custom view for the Toast using the LayoutInflater class, and sets the custom view as the view for the Toast. You can customize the appearance of the Toast by modifying the layout file custom_toast_view.xml and the view elements it contains.

You can also customize the behavior of the Toast by setting various properties of the Toast object, such as the duration, gravity, and animation.

Note that you will need to replace R.layout.custom_toast_view with the resource ID of your custom layout file.

how to change the android toast color?

To change the color of a Toast in Android, you can use the setTextColor() method of the TextView the element that contains the message text.

Here is an example of how you can change the color of a Toast in Android using Java:

import android.graphics.Color;
import android.widget.TextView;
import android.widget.Toast;

Toast toast = Toast.makeText(getApplicationContext(), "Toast message", Toast.LENGTH_SHORT);
View toastView = toast.getView();
TextView toastText = toastView.findViewById(android.R.id.message);
toastText.setTextColor(Color.WHITE);
toast.show();

This example will change the color of the message text in the Toast to white. You can use any color value that is supported by the Android Color class, such as Color.RED, Color.BLUE, Color.GREEN, and so on.

Note that you may need to customize the layout of the Toast in order to access the TextView element that contains the message text. You can do this by creating a custom layout for the Toast using the LayoutInflater class, or by using the Toast.setView() method to set a custom view for the Toast.

how to change the android toast position?

To change the position of a Toast in Android, you can use the setGravity() method of the Toast class, which allows you to specify the gravity of the Toast relative to the screen.

Here is an example of how you can change the position of a Toast in Android using Java:

Toast toast = Toast.makeText(getApplicationContext(), "Toast message", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
toast.show();

This example will display the Toast at the top-left corner of the screen.

You can specify the gravity of the Toast using the constants defined in the Gravity class, such as Gravity.TOP, Gravity.BOTTOM, Gravity.LEFT, Gravity.RIGHT, and so on. You can also specify the horizontal and vertical offsets for the Toast using the two additional arguments to the setGravity() method.

Note that the position of the Toast may be affected by the current screen orientation and other system factors. You can use the setGravity() method to specify a general position for the Toast, but the actual position may vary.

android custom toast deprecated what is the alternative?

Answer –

The Toast class in Android has been deprecated in favor of the Android Toast API, which is part of the Android Notification API. The Android Toast API allows you to create and display Toasts in a more flexible and customizable way and is the recommended way to create Toasts in Android.

Here is an example of how you can create a custom Toast in Android using the Android Toast API:

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;

// Create a notification channel (required for Android 8.0 and higher)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(
            "channel_id",
            "Channel Name",
            NotificationManager.IMPORTANCE_DEFAULT
    );
    channel.setDescription("Channel Description");
    channel.enableLights(true);
    channel.setLightColor(Color.RED);
    channel.enableVibration(true);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(channel);
}

// Set up the notification content
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_

best android custom toast library-

There are several libraries available that offer additional features and customization options for Toasts in Android. Here are a few popular options:

  1. SuperToasts: SuperToasts is a library that allows you to create custom Toasts with a variety of customization options, such as custom layouts, animations, and background colors.
  2. Crouton: Crouton is a library that allows you to create custom Toasts with a variety of customization options, such as custom layouts, animations, and background colors. It also supports custom callbacks and lifecycle management.
  3. QuickToast: QuickToast is a library that offers a simple and easy-to-use API for creating custom Toasts with a variety of customization options, such as custom layouts, animations, and background colors.
  4. Toast-It: Toast-It is a library that allows you to create custom Toasts with a variety of customization options, such as custom layouts, animations, and background colors. It also supports custom callbacks and lifecycle management.

These are just a few examples of the many libraries available for custom Toasts in Android. You can choose the library that best meets your needs based on your requirements and preferences.

for more information, you can Visit Here. if you want to read our other posts you can check our blog section

image background remover library for android developers

0

If you’re an Android developer, then you know how difficult it can be to remove image backgrounds. But with this new library, it’s now a breeze! With just a few lines of code, you can easily remove image backgrounds from your Android app.

This library is perfect for developers who want to add images to their apps but don’t want to deal with the hassle of removing backgrounds. Simply call the library’s methods and pass in an image URL or file path, and the background will be automatically removed. You can also specify if you want the edges of the foreground object(s) to be smoothed out.

So if you’re looking for an easy way to add images to your Android app without all the hassle, check out this new background remover library today!

Gradle

Add it to your root build.Gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

dependencies {
     implementation 'com.github.GhayasAhmad:auto-background-remover:1.0.3'
}

Code:

Default

The default method for just removing the background from the subject from the bitmap without trimming the bitmap.

BackgroundRemover.bitmapForProcessing(
    bitmap,
    object: OnBackgroundChangeListener{
        override fun onSuccess(bitmap: Bitmap) {
            //do what ever you want to do with this bitmap
        }

        override fun onFailed(exception: Exception) {
            //exception
        }
    }
)

Trim Image

Remove the empty part of the image from the bitmap. true for removing empty parts and falsefor not and by default it is false.

BackgroundRemover.bitmapForProcessing(
    bitmap,
    true,
    object: OnBackgroundChangeListener{
        override fun onSuccess(bitmap: Bitmap) {
            //do what ever you want to do with this bitmap
        }

        override fun onFailed(exception: Exception) {
            //exception
        }
    }
)

 

for more information, you can check this library on Github

Best Twitch Emote Maker for Android

0

Emojis are a form of text-based language used to convey emotions, ideas, and expressions through text, images, and sound. Most people use emoji messages to communicate with others within and outside of their social groups. Twitch is an online platform where video gamers broadcast their favorite games to an audience of thousands. People have used the communication tools available on Twitch to create and share emojis that represent their favorite games. Emoticons allow users to express themselves in many ways through images, words, and sounds. Many popular online games use emotes to let people know how they are feeling while they play. Fans of certain games will send congratulatory emojis to their favorite streamers after a particularly awesome run. Emoticons have become a form of expression for gamers and non-gamers alike.

Emoticons are used extensively on Twitch to represent the emotions associated with gaming. Games such as League of Legends and Fortnite tend to have a large number of avid fans within the millennial demographic. People create and share Twitch emojis to show excitement or despair over their gameplay experiences. Emoji usage on Twitch has become so common that many people associate certain emoji reactions with certain emotions. Certain reactions like ‘crying,’ ‘frowning’ or ‘with a wry smile’ are common responses used in Twitch emote creation. People have even invented new emojis that represent specific game mechanics within popular video games. These are called meta emotes and will usually focus on a particular aspect of the game that the streamer is discussing in their broadcast. Meta emotes allow fans to creatively express themselves via emoji without limiting their responses to the standard set of reactions suggested by default settings in most apps.

Twitch Emote Maker

 

Twitch Emote Maker is an image tool that allows you to convert any image into a twitch emote or Sub Badges. it will convert your image into an accurate emote size with maximum quality. I believe it will help people and save them time.

 if you want to read our other posts you can check our blog section

Calculate your age in 5 seconds

0
Human aging is a complex process that is subject to many factors. This includes genetics, diet, and lifestyle. In addition, the body’s internal organs age as well. Even after death, the body continues to age for some time. Knowing your true age is important because it impacts your health and well-being as you age. Determining your true age is not easy, but there are several ways to do so.
Your age is based on your date of birth. The calendar system used to determine your date of birth may be foreign to you. Years are added to the calendar system after WWI and WWII to keep up with increases in longevity. Since years are added to the calendar system, it can be difficult to accurately determine a person’s true age. For that reason, age calculators have been developed that use a more simplified calendar system. The one used here is based on the Gregorian calendar system used in most countries today.
Using this calculator, you can find out your current age by entering your date of birth. The calculator determines your age by multiplying your date of birth by four and adding one year to the result. For example: if a person was born on January 1st, 2018, their age would be 19 years old. Depending on when you were born, your calculator may incorrectly estimate your age. This is because different years add up to the same age for different people. In 2022, adding 2018 will add up to the same age for everyone who was born in 2018.
The calculator’s method is imperfect due to her explanation: Your body grows at different rates throughout your life. For example, during childhood, you grow faster than when you’re older. This is due to a process known as puberty; which happens when cells change into adulthood. After birth, your body grows at an average rate until adulthood- after which it slows down considerably. Some people grow slower than others- this is due to genetics and diet as much as anything else.
The calculator has several other issues that make it less than ideal as an age estimator. First, all ages are given in years- which can be off if the calendar system used is not the one in use today. Secondly, adding and subtracting years from ages can be confusing since years are added and subtracted from the calendar system instead of actual figures. To make matters worse, adding and subtracting decades instead of years does not work as intended either since decades add up to 100 compared to years that add up to 365 in the Gregorian system.
An easier way to estimate your age is by calculating how old you were when you were born. This works by assuming that each year between births adds 10 years to age. For example: if someone was born in 1990, their age at birth would be 20 years old when they were 19 years old in 2017 (2+10=12). Multiplying this by 10 again gives us 20*10=200 which rounded down gives us 19 years old when we were actually 18 years old in 2017 (19+9=28).
Age estimation techniques can be complicated- making them popular internet memes such as ‘7 Ages’. The one presented here is imperfect but practical since it uses a real-world calendar system created by human error. There are multiple ways to calculate your true age, but this one works best if you were born recently enough for year increments between births to work correctly in calculating your current age.
if you want to calculate your age and get to know your all details you can use this. Age Calculator App.
age calculator guru
The Age Calculator application gives you a simple user interface easy to use. Age Calculator Guru provides your total age details with your upcoming birthday.
These apps also provide some extra information such as total Years, total days, total hours, total min, and total seconds you have passed.

how to upload image to imgur anonymously

0

Imgur is a popular image hosting service that allows users to easily upload and share images on the web. If you’re looking for a simple and convenient way to upload images to Imgur from your Android device, the Imgur Upload – Image to Imgur app is worth checking out.

The Imgur Upload – Image to Imgur app is a free app that can be downloaded from the Google Play Store. With this app, you can easily upload images to Imgur and share them with others. Simply select the image you want to upload and the app will handle the rest, providing you with a link to your uploaded image.

One of the great things about the Imgur Upload – Image to Imgur app is its simplicity. The app has a clean and intuitive interface that makes it easy for anyone to use, even if you’re new to image hosting services. The app also supports multiple image formats, so you can upload any type of image you want.

In addition to uploading images, the Imgur Upload – Image to Imgur app also lets you view and manage your Imgur account. You can view your uploaded images, delete images, and even add tags to your images to make them easier to find.

Overall, the Imgur Upload – Image to Imgur app is a great tool for anyone who uses Imgur to host images on their Android device. It’s simple, convenient, and free, making it an excellent choice for uploading and managing images on Imgur. So if you want to easily upload images to Imgur from your Android device, be sure to give the Imgur Upload – Image to Imgur app a try.

It’s far also simple to act with others anonymously on the net. People have things that they’d never have in the real world. If you’re enthusiastic about specific topics and engage with people who are passionately opposed to the views, the online debate that ensues will turn into cruel. Take a deep breath and move out. If you absolutely will not do this, take humor. Still humor. Thing but viciousness.

follow the steps and upload the image to Imgur anonymously –

Step 1 – grave an android phone and Download Imgur Upload – Image to Imgur App from this link

upload image to imgur

Step- 2 and final Step – choose an image and upload it.

We know that Imgur is the best online image-sharing and image-hosting service. Many people upload their images to Imgur. Imgur Upload – Upload Image to Imgur is a tool app that helps you upload any image to Imgur and gives the image link instantly. Thus, you can save time uploading images to Imgur.
In this application, use the Imgur API to upload images that are officially provided by Imgur LLC.
Features –
1- You can upload an image and get an image link on Imgur
2- You can copy the image link and use it anywhere
3- You can share the image link by clicking the share button
4- You can delete the image from the server
5- It uses a local database to store URL lists, so no data is lost when you leave the app.
6- You can upload your photo via a camera
7- You can upload your image via local storage

How to Solve You must complete the advertising ID declaration before releasing an app that targets Android 13

0

Many people are very worried about the new Google update advertising ID declaration before releasing an app that targets Android 13 and doesn’t understand how to solve this issue. No need to worry today I will show you how to set up this Advertising ID and publish your one properly and get your one approved without any hassle.

let’s see how to solve the (You must complete the advertising ID declaration before releasing an app that targets Android 13 ) issue in your google play console Account. to solve this issue follow the steps below –

To solve the “You must complete the advertising ID declaration” error when releasing an app that targets Android 13, you will need to follow these steps:

  1. Make sure you have included the meta-data element with the android:name attribute set to "com.google.android.gms.ads.AD_MANAGER_APP" in the application element of your app’s manifest file. This is required to declare that your app uses the Google Mobile Ads SDK.
  2. Make sure you have included the meta-data element with the android:name attribute set to "com.google.android.gms.ads.APP_ID" and the android:value attribute set to your app’s AdMob app ID in the application element of your app’s manifest file. This is required to identify your app to the AdMob service.
  3. Make sure you have added the ACCESS_NETWORK_STATE and INTERNET permissions to your app’s manifest file. These permissions are required for the Google Mobile Ads SDK to function properly.
  4. Make sure you have properly initialized the Google Mobile Ads SDK in your app. You can do this by calling the MobileAds.initialize() the method in your app’s onCreate() method, passing in your app’s AdMob app ID as an argument.
  5. If you are using a third-party ad network in addition to AdMob, make sure you have declared the third-party ad network in the application element of your app’s manifest file using the meta-data element with the android:name attribute set to "com.google.android.gms.ads.third_party_id_provider" and the `android: value

Also you can follow the steps below –

step 1

add the permission ( com.google.android.gms.permission.AD_ID ) in your App Manifest File.

<manifest>
 <uses-permission android:name="com.google.android.gms.permission.AD_ID"/> 
<application>
 <!-- not here --> 
</application> 
</manifest>

Step 2

make compileSdkVersion 33 and targetSdkVersion 33

android {
    compileSdkVersion 33
   
    defaultConfig {
        applicationId "droidrocks.com.mypaintart"
        minSdkVersion 24
        targetSdkVersion 33
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            debugSymbolLevel 'SYMBOL_TABLE'
        }
    }
 }

 

Step 3

go to Menu and Click on App Content > Advertising ID > Start  – (follow the image below)

You must complete the advertising ID declaration before releasing an app that targets Android 13

Step 4

Click on “Yes” and check the –  – (follow the image below)

You must complete the advertising ID declaration before releasing an app that targets Android 13 You must complete the advertising ID declaration before releasing an app that targets Android 13

Step 5

publish your app and wait for approval from google play. hope this will solve your problem. for more information Visit Here

How to integrate Google Play in-app purchase Billing Library Programmatically into your Android App

0

In this article, I will show you how to integrate In-App Purchase for Subscription of Google Play in-app purchase Billing Library version 5+ into your Android App. in this tutorial I will follow the google official documentation

What will be required –

  • Android Studio to write this code
  • Google Play Console Account
  • A published App
  • Device or Emulator For Test

 Step 1

Add the Google Play Billing Library dependency to your app’s build.gradle file as shown:

dependencies {
    def billing_version = "5.0.0"

    implementation "com.android.billingclient:billing:$billing_version"
}

Step 2

Initialize a BillingClient with PurchasesUpdatedListener in the onCreate method

billingClient = BillingClient.newBuilder(this)
                .enablePendingPurchases()
                .setListener(
                        new PurchasesUpdatedListener() {
                            @Override
                            public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List list) {
                               if(billingResult.getResponseCode()==BillingClient.BillingResponseCode.OK && list !=null) {
                                   for (Purchase purchase: list){
                                       verifySubPurchase(purchase);
                                   }
                               }
                            }
                        }
                ).build();

        //start the connection after initializing the billing client
        establishConnection();

 

Step 3

Establish a connection With Google Play API

void establishConnection() {

       billingClient.startConnection(new BillingClientStateListener() {
           @Override
           public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
               if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                   // The BillingClient is ready. You can query purchases here.
                   showProducts();
               }
           }

           @Override
           public void onBillingServiceDisconnected() {
               // Try to restart the connection on the next request to
               // Google Play by calling the startConnection() method.
               establishConnection();
           }
       });
   }

 

Step 4

Show the products and make them available to Purchase

@SuppressLint("SetTextI18n")
    void showProducts() {

        ImmutableList productList = ImmutableList.of(
                //Product 1 = index is 0
                QueryProductDetailsParams.Product.newBuilder()
                .setProductId("sub_premium")
                .setProductType(BillingClient.ProductType.SUBS)
                .build(),

                //Product 2 = index is 1
                QueryProductDetailsParams.Product.newBuilder()
                .setProductId("test_id_shar")
                .setProductType(BillingClient.ProductType.SUBS)
                .build()

        );

        QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
                .setProductList(productList)
                .build();

        billingClient.queryProductDetailsAsync(
                params,
                (billingResult, productDetailsList) -> {
                    // Process the result
                    for (ProductDetails productDetails : productDetailsList) {
                        if (productDetails.getProductId().equals("sub_premium")) {
                            List subDetails = productDetails.getSubscriptionOfferDetails();
                            assert subDetails != null;
                            Log.d("testOffer",subDetails.get(0).getOfferToken());
                            txt_price.setText(subDetails.get(0).getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()+" Per Month");
                            txt_price.setOnClickListener(view -> {
                                launchPurchaseFlow(productDetails);
                            });
                        }

                        if (productDetails.getProductId().equals("test_id_shar")) {
                            List subDetails = productDetails.getSubscriptionOfferDetails();
                            assert subDetails != null;
                            Log.d("testOffer",subDetails.get(1).getOfferToken());
                            offer_btn.setText(subDetails.get(1).getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()+" Per Month");
                            offer_btn.setOnClickListener(view -> {
                                launchPurchaseFlow(productDetails);
                            });
                        }
                    }
                }
        );

    }

 

Step 5

Launch the purchase flow

void launchPurchaseFlow(ProductDetails productDetails) {
       assert productDetails.getSubscriptionOfferDetails() != null;
       ImmutableList productDetailsParamsList =
               ImmutableList.of(
                       BillingFlowParams.ProductDetailsParams.newBuilder()
                               .setProductDetails(productDetails)
                               .setOfferToken(productDetails.getSubscriptionOfferDetails().get(0).getOfferToken())
                               .build()
               );
       BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
               .setProductDetailsParamsList(productDetailsParamsList)
               .build();
       BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);
   }

 

Step 6

Process the purchases and Verify Payment

void verifySubPurchase(Purchase purchases) {

        AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams
                .newBuilder()
                .setPurchaseToken(purchases.getPurchaseToken())
                .build();

        billingClient.acknowledgePurchase(acknowledgePurchaseParams, billingResult -> {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                //user prefs to set premium
                Toast.makeText(StoreActivity.this, "You are a premium user now", Toast.LENGTH_SHORT).show();
                //Setting premium to 1
                // 1 - premium
                // 0 - no premium
                prefs.setPremium(1);
            }
        });

        Log.d(TAG, "Purchase Token: " + purchases.getPurchaseToken());
        Log.d(TAG, "Purchase Time: " + purchases.getPurchaseTime());
        Log.d(TAG, "Purchase OrderID: " + purchases.getOrderId());
    }

 

Step 7

Handling pending transactions

protected void onResume() {
        super.onResume();
        billingClient.queryPurchasesAsync(
                QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build(),
                (billingResult, list) -> {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                        for (Purchase purchase : list) {
                            if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED && !purchase.isAcknowledged()) {
                                verifySubPurchase(purchase);
                            }
                        }
                    }
                }
        );

    }

 

Step 8

Check Subscription, run this code while the app starting(the best way will be to use this below code inside your splash screen Activity)

void checkSubscription(){

    billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener((billingResult, list) -> {}).build();
    final BillingClient finalBillingClient = billingClient;
    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingServiceDisconnected() {

        }

        @Override
        public void onBillingSetupFinished(@NonNull BillingResult billingResult) {

            if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK){
                finalBillingClient.queryPurchasesAsync(
                        QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build(), (billingResult1, list) -> {
                    if (billingResult1.getResponseCode() == BillingClient.BillingResponseCode.OK){
                         Log.d("testOffer",list.size() +" size");
                         if(list.size()>0){
                             prefs.setPremium(1); // set 1 to activate premium feature
                             int i = 0;
                             for (Purchase purchase: list){
                                 //Here you can manage each product, if you have multiple subscription
                                 Log.d("testOffer",purchase.getOriginalJson()); // Get to see the order information
                                 Log.d("testOffer", " index" + i);
                                 i++;
                             }
                         }else {
                             prefs.setPremium(0); // set 0 to de-activate premium feature
                         }
                    }
                });

            }

        }
    });
}

if you want a video tutorial about Integrating the Google Play Billing Library check our YouTube Channel. you will find more awesome tutorials