Wednesday 30 August 2023

Fix 'Your Windows License Will Expire Soon' Error

So, you are busy working on an official assignment, a college report or just enjoying an action-packed thriller on your PC. Suddenly, you see a message pop “Your windows license will expire soon”. What to do now? The message just keeps bugging you.

Don’t worry, as this error troubles users all across the globe. This can happen when you are using a pirated version of Windows OS. Or if you have just updated Windows 8 to Windows 10, you may face this problem.

Before diving into the solutions for this error, let us learn a little more about the causes.

Causes of the Error

The primary cause of this error is an expired OS license of Windows 7/9/8.1/10. Some users experience this error even when they have bought a new device, which had Windows OS pre-installed.

This can occur due to incorrect license key or if the key is rejected by the system. This key is embedded within the BIOS. You need to contact customer care in this case, who will help you out.

Another reason for the error is if the OS had been bought from a shady site. Many sites sell Windows OS products, but do not have an official partnership with Microsoft. 9 times out 10, these products are fake and are waste of money.

Types of Error

The error message can appear in different forms –

  • Your Windows license will expire soon but Windows is activated

This error appears on activated and non-activated Windows systems. It is an activation error commonly reported by Windows 10 users.

  • Your Windows license will expire soon HP, Dell, ASUS

Users owning a Dell, HP or ASUS device face this error. 


  • Your Windows license will expire soon

This is the most common message, which keeps popping up. When you use a temporary version of Windows, this will bug you.

Note: You will not be able to fix the issue till you purchase and install an original version of Windows 10/ 8.

How to fix this error?

When you face this error for the first time, shut down your PC and restart it again. If the error still pops up, try the following solutions – 

Method 1: Restart the Windows Explorer Process

The first method of fixing the “Your Windows License will expire Soon” message is to restart the Windows Explorer process in the Task Manager.   

Please follow the steps below –

  • Press Ctrl+Alt+Delete and select Task Manager to open task manager

fix your windows license will expire soon error

  • Next, in Task Manager under Process tab, find Window explorer, right click on it and select End Task

fix your windows license will expire soon error

  • Next, click on File and select Run New Task

fix your windows license will expire soon error

  • Now in the dialog box, type explorer.exe and click OK or press Enter.

fix your windows license will expire soon error

  • Next go to search Menu, type Command Prompt (CMD) and Select Run As Administrator

fix your windows license will expire soon error

  • Now in command prompt, type slmgr –rearm and press Enter

fix your windows license will expire soon error

  • At last, restart your computer

Note: Many users have got rid of this error using this method quickly  

Method 2: Group Policy Edit

Group Policy is a tool that can be used by a network administrator handling the Microsoft Active Directory. It is not usually operated by users as it is used for configuring network settings, passwords, startup programs and much more.

Tweaking the Group Policy can remove the “Your Windows License will expire soon” error. Here are the steps to do it –       

  • Press Window+R to open the Run Dialog box

fix your windows license will expire soon error

  • Next in the Run Dialog box, type gpedit.msc and press Enter or click OK.

fix your windows license will expire soon error

  • Next in Local Group Policy Editor window, on the left pane, navigate to Computer Configuration > Administrative Templates > Windows Components > Windows Update.

fix your windows license will expire soon error

  • Now in the right pane, double click on No auto-restart with logged on users for scheduled automatic updates installations option

fix your windows license will expire soon error

  • Now in the next window, select Enabled checkbox and click on Apply and OK to save changes

fix your windows license will expire soon error

Method 3: Edit Registry

The Windows Registry is the database of settings, values and options of the different software and hardware in your system. Making a few changes to the registry might renew your OS policy and resolve the issue.

Follow the steps below to modify the Windows Registry – 

  • Press Window + R to open the Run dialog box on your system

fix your windows license will expire soon error

  • Next, type regedit.exe on Run dialog box and press Enter or click OK

fix your windows license will expire soon error

  • Export the current Registry before modifying it. Click on File> Export

fix your windows license will expire soon error

  • Then, select All as the Export range and choose a file name. Save it in a safe location and remember it

fix your windows license will expire soon error

  • It is important to do this. If something goes wrong, you can just execute this file and the older settings of the Registry will be restored on your system   
  • Next, go to search Menu, type Command Prompt (CMD) and Select Run As Administrator

fix your windows license will expire soon error

  • Now in command prompt, type the following command and press Enter
reg add “HKLM\Software\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform” /v NoGenTicket /t REG_DWORD /d 1 /f

fix your windows license will expire soon error

Method 4: Find the Product Key using Command Prompt

You can use the command prompt to locate the product key of the Windows version. You can re-enter the key to renew your OS license. 

Find the key using these steps – 

  • Go to search Menu, type Command Prompt (CMD) and Select Run as Administrator

fix your windows license will expire soon error

  • Next in command prompt, type the following command and press Enter
wmic path SoftwareLicensingService get OA3xOriginalProductKey
  • This command will show your product key on the screen, note it down

  • Now, press Window + I and click on Update & security option

  • Then, first click the Activation option and then click on Change product key

  • Enter your product key (which you noted down) and then click on Next button

Using these steps, your Windows version will be activated again.  

Method 5: Disable Two Windows Services

Windows services enable the creation and execution of other processes. You can fix the license error by disabling these two services – 

  • Disable Windows License Manager Service
  • Disable Windows Update Service

First, press Window+R to open Run dialog box. Next in the Run dialog box.

Next  type services.msc and press Enter to open Service Manager.

fix your windows license will expire soon error

Disable Windows License Manager Service

  • Next locate Windows License Manager Service and double click on it

fix your windows license will expire soon error

  • Next in the Properties window set the Startup type to Disabled and click on Stop button (if service status is running) to stop the service

fix your windows license will expire soon error

  • Now click on Apply and OK to save changes

Disable Windows Update Service

  • Next, locate Windows Update and double click on it

fix your windows license will expire soon error

  • In the Properties window, make sure the Startup type is set to Disabled. Then, click on the Stop button to stop the service (if you find the service still running)

  • Now click on Apply and OK to save changes

These steps are sure to resolve the license error. If the message persists, enable the services again.

Method 6: Using Activation Troubleshooter

The Microsoft Activation Troubleshooter is useful for verifying the originality of a Windows version and if it is being used in more than one device. You can use this to solve common activation errors. But the Activation Troubleshooter is useful only if you are using Windows 10 version 1607 or above. 

Here are the steps to use the feature –

  • Press Window + I and click on the Update & Security option

  • Now, on the left pane click on the Activation option
  • All the activation errors will be displayed here
  • Launch the Activation Troubleshooter by clicking on Troubleshoot, and you will be on your way
  • The Troubleshooter will detect the current activation errors on your system and fix them automatically
  • After the entire process is over, click on the Close button

Check Your Date and Time

Every license has a date and time of activation/ expiry. So, check to see whether your system’s date and time has been messed up, as this might be the reason for the license error. For this, you have to go to the Date and Time settings and check.  

Follow these steps given below –

  • Go to the Search Menu, type Date & Time Settings and press Enter or click on Open

fix your windows license will expire soon error

  • Now under Date and Time, turn on options Set time automatically and Set time zone automatically

  • Now Restart your computer and check if the issue has been resolved


Reference link:

https://www.stechies.com/fix-your-windows-license-will-expire-soon-error/#:~:text=The%20primary%20cause%20of%20this,is%20embedded%20within%20the%20BIOS.

Monday 21 August 2023

A type-safe HTTP client for Android and Java

Retrofit

Introduction

Retrofit turns your HTTP API into a Java interface.

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

The Retrofit class generates an implementation of the GitHubService interface.

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();

GitHubService service = retrofit.create(GitHubService.class);

Each Call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote webserver.

Call<List<Repo>> repos = service.listRepos("octocat");

Use annotations to describe the HTTP request:

  • URL parameter replacement and query parameter support
  • Object conversion to request body (e.g., JSON, protocol buffers)
  • Multipart request body and file upload

API Declaration

Annotations on the interface methods and its parameters indicate how a request will be handled.

REQUEST METHOD

Every method must have an HTTP annotation that provides the request method and relative URL. There are eight built-in annotations: HTTPGETPOSTPUTPATCHDELETEOPTIONS and HEAD. The relative URL of the resource is specified in the annotation.

@GET("users/list")

You can also specify query parameters in the URL.

@GET("users/list?sort=desc")

URL MANIPULATION

A request URL can be updated dynamically using replacement blocks and parameters on the method. A replacement block is an alphanumeric string surrounded by { and }. A corresponding parameter must be annotated with @Path using the same string.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId);

Query parameters can also be added.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);

For complex query parameter combinations a Map can be used.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);

REQUEST BODY

An object can be specified for use as an HTTP request body with the @Body annotation.

@POST("users/new")
Call<User> createUser(@Body User user);

The object will also be converted using a converter specified on the Retrofit instance. If no converter is added, only RequestBody can be used.

FORM ENCODED AND MULTIPART

Methods can also be declared to send form-encoded and multipart data.

Form-encoded data is sent when @FormUrlEncoded is present on the method. Each key-value pair is annotated with @Field containing the name and the object providing the value.

@FormUrlEncoded
@POST("user/edit")
Call<User> updateUser(@Field("first_name") String first, @Field("last_name") String last);

Multipart requests are used when @Multipart is present on the method. Parts are declared using the @Part annotation.

@Multipart
@PUT("user/photo")
Call<User> updateUser(@Part("photo") RequestBody photo, @Part("description") RequestBody description);

Multipart parts use one of Retrofit's converters or they can implement RequestBody to handle their own serialization.

HEADER MANIPULATION

You can set static headers for a method using the @Headers annotation.

@Headers("Cache-Control: max-age=640000")
@GET("widget/list")
Call<List<Widget>> widgetList();
@Headers({
    "Accept: application/vnd.github.v3.full+json",
    "User-Agent: Retrofit-Sample-App"
})
@GET("users/{username}")
Call<User> getUser(@Path("username") String username);

Note that headers do not overwrite each other. All headers with the same name will be included in the request.

A request Header can be updated dynamically using the @Header annotation. A corresponding parameter must be provided to the @Header. If the value is null, the header will be omitted. Otherwise, toString will be called on the value, and the result used.

@GET("user")
Call<User> getUser(@Header("Authorization") String authorization)

Similar to query parameters, for complex header combinations, a Map can be used.

@GET("user")
Call<User> getUser(@HeaderMap Map<String, String> headers)

Headers that need to be added to every request can be specified using an OkHttp interceptor.

SYNCHRONOUS VS. ASYNCHRONOUS

Call instances can be executed either synchronously or asynchronously. Each instance can only be used once, but calling clone() will create a new instance that can be used.

On Android, callbacks will be executed on the main thread. On the JVM, callbacks will happen on the same thread that executed the HTTP request.

Retrofit Configuration

Retrofit is the class through which your API interfaces are turned into callable objects. By default, Retrofit will give you sane defaults for your platform but it allows for customization.

CONVERTERS

By default, Retrofit can only deserialize HTTP bodies into OkHttp's ResponseBody type and it can only accept its RequestBody type for @Body.

Converters can be added to support other types. Six sibling modules adapt popular serialization libraries for your convenience.

  • Gsoncom.squareup.retrofit2:converter-gson
  • Jacksoncom.squareup.retrofit2:converter-jackson
  • Moshicom.squareup.retrofit2:converter-moshi
  • Protobufcom.squareup.retrofit2:converter-protobuf
  • Wirecom.squareup.retrofit2:converter-wire
  • Simple XMLcom.squareup.retrofit2:converter-simplexml
  • JAXBcom.squareup.retrofit2:converter-jaxb
  • Scalars (primitives, boxed, and String): com.squareup.retrofit2:converter-scalars

Here's an example of using the GsonConverterFactory class to generate an implementation of the GitHubService interface which uses Gson for its deserialization.

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .addConverterFactory(GsonConverterFactory.create())
    .build();

GitHubService service = retrofit.create(GitHubService.class);

CUSTOM CONVERTERS

If you need to communicate with an API that uses a content-format that Retrofit does not support out of the box (e.g. YAML, txt, custom format) or you wish to use a different library to implement an existing format, you can easily create your own converter. Create a class that extends the Converter.Factory class and pass in an instance when building your adapter.


For more reference: Retrofit (square.github.io)

Monday 14 August 2023

Navigation drawer layout with an event listener

 Hey, today I am going to discuss Drawer Layout. This means you will get knowledge about how to add drawer layout with an event listener. The navigation drawer can be implemented by using the Drawer Layout widget. In the layout of your activity, you should define the DrawerLayout element.

This is also known as the navigation drawer. This is a layout that displays the app’s main navigation options on the left edge of the right edge of the screen. Let's set up a basic navigation drawer based on the following steps with DrawerLayout.

What is the Drawer Layout?

As we discuss drawer layout acts as a top-level container for window content that allows for interactive drawer views to be pulled out from one or both vertical edges of the window. You can use it in your app either left edge or right edge. Mostly drawer layout is used on the left edge.

Create a Drawer Layout

Adding a navigation drawer, into the app is very simple. This is the top-level layout of the activity. You need to add this layout to your XML file. This XML file can be your activity file or fragment file.

Main XML Layouts

Let's take an example for the navigation drawer. First of all, add this XML snippet to your XML file.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

Header layout for the navigation drawer

Create a header layout for the navigation drawer now. This XML design will show on the top of the navigation drawer. You can customize with your own design patterns.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nav_header_desc"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="@string/nav_header_title"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nav_header_subtitle" />

</LinearLayout>

Menu for navigation layout

A most important segment of the navigation drawer is menu design. There are many two ways to design your menu, the first one is by using XML and second is dynamic via code. Sample for navigation menu like this by using XML.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_menu_camera"
            android:title="@string/menu_home" />
        <item
            android:id="@+id/nav_gallery"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/menu_gallery" />
        <item
            android:id="@+id/nav_slideshow"
            android:icon="@drawable/ic_menu_slideshow"
            android:title="@string/menu_slideshow" />
        <item
            android:id="@+id/nav_tools"
            android:icon="@drawable/ic_menu_manage"
            android:title="@string/menu_tools" />
    </group>

    <item android:title="Communicate">
        <menu>
            <item
                android:id="@+id/nav_share"
                android:icon="@drawable/ic_menu_share"
                android:title="@string/menu_share" />
            <item
                android:id="@+id/nav_send"
                android:icon="@drawable/ic_menu_send"
                android:title="@string/menu_send" />
        </menu>
    </item>

</menu>

How to access navigation layout by activity?

Now, these are the code snippets where you handle your drawer layout with an event listener. You can access your drawer layout activity as well as your drawer layout menu. You just need to create your drawer layout object in your activity to access all features of the drawer layout.

DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);

On navigation item select

Now, you need to add code for controlling your menu options. So, add the onNavigationItemSelected function in your activity.

@Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_home) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_tools) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

Drawer layout with an event listener

Finally, this is the code where you can detect your drawer layout is open or closed with an event listener.

drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                //Log.i(TAG, "onDrawerSlide");
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                Log.i(TAG, "onDrawerOpened");
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                Log.i(TAG, "onDrawerClosed");
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                //Log.i(TAG, "onDrawerStateChanged");
            }
        });

Final code for drawer layout with an event listener

package com.codingissue.example;

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import android.util.Log;
import android.view.View;

import androidx.core.view.GravityCompat;
import androidx.appcompat.app.ActionBarDrawerToggle;

import android.view.MenuItem;

import com.google.android.material.navigation.NavigationView;

import androidx.drawerlayout.widget.DrawerLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.Menu;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
        navigationView.setNavigationItemSelectedListener(this);

        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                //Log.i(TAG, "onDrawerSlide");
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                Log.i(TAG, "onDrawerOpened");
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                Log.i(TAG, "onDrawerClosed");
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                //Log.i(TAG, "onDrawerStateChanged");
            }
        });
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_home) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_tools) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

Conclusion

In the above post, we learn about the navigation drawer layout with an event listener. We also learned drawer layout can be adjusted on the left edge and right edge of the screen. We can detect navigation item click as well as navigation movement.