12 February, 2020

Removing xfreeservice.com adware from Chrome

Removing xfreeservice.com

and so on.
If your Google search results are filled with useless thumbnails and links are redirected through xfreeservice.com your Google Chrome is infected with a malicious javascript which probably came attached with one of the Chrome Extension.
  Problem: Google Search results have thumbnails in front of them and links are redirected 
through b.xfreeservice.com or c.xfreeservice.com. In some case, you are redirected to an entirely different page. Google search results are modified with affiliate links.

Solution: Remove any/all Chrome extensions that help with downloads.
Example: Downloader for Instagram, Video Downloader, Free Download Manager.

There are very detailed insights on xfreeservice.com being malware or not here. Needless to say, there's indeed some undesired behaviour.

The xfreeservice.com script is designed very well to ensure a Chrome user cannot always pinpoint it out.
If you open developers inspector in Google Search results infiltrated with xfreeservice.com links, the script hides all parts related to xfreeservice.com 
Moreover, if you just modified any of your extensions xfreeservice.com  will remain disabled for certain time. 

Work around for Broadcast receiver not working in Chinese mobiles

If you're having trouble with your Android app not responding to certain events in Mi, Oppo, Vivo or Letv devices it's not your fault.
This could include and is not limited to, service app not working properly, push notifications not working properly, application not opening up when intended. 
It is because of the extensive battery saver and the so-called saving the user from apps spamming their activity.

Here's the funniest part about it

We wrote to someone very senior at Xiaomi. He reverted that they manually whitelist a few apps, and the rest are by default disallowed from accessing the notifications folder. This was the response. "This usually happens because of whitelisting of apps that can access notifications folder. This is a feature to ensure the user is protected from spam and also helps to ensure RAM/battery usage optimization." We asked what the process was to get an app whitelisted, and did not get a response.  

This is coming from a post about GCM push notifications not working on Mi devices here.

Funny because Chinese mobile manufacturers like Xiaomi, Oppo and Vivo first flood their phones with bloatware nobody asks for and even shove their useless articles and sponsored apps to users and here we see them talking about how they want to protect the user from spam and RAM and battery consumption.

The only solution is to get extensive permissions from the user which will be done manually and cannot be programmed for easiness.
What all permissions?
First, we need a permission to auto-start the application and then the permission to display pop-up window. 
App Settings > Permissions > Auto-Start
App Settings > Other Permissions > Display Pop-up

The most convenient workaround is to ask the user to manually permit these setting and open the settings page for the end-user.
This can be done by making a settings button that opens up the settings page.

settings = (Button)findViewById(R.id.settings);
settings.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                Uri uri = Uri.fromParts("package", getPackageName(), null);

Useful links if you'd like to explore more.

04 February, 2020

How to Convert a String to Date in Java

How to Convert a String to Date in Java

Converting a string to a date in Java (or any programming language) is a fundamental skill and is useful to know when working on projects. Sometimes, it is easier to work with a string to represent a date, and then convert it to a date object for further use.

Date  API

The Date / Time API in Java works by default with the ISO 8601 format, which is (yyyy-MM-dd).By default all dates follow this format, and all strings that are converted should follow this if they are using the default formatter.


The date-time API provides parse () methods to parse a string that contains date information. To convert string objects to LocalDateTime objects, the string must represent a valid date or time according to ISO_LOCAL_DATE

Example, let's convert a String to a java.time.LocalDate:

LocalDate date = LocalDate.parse("2018-05-05");

Parse API with a Custom Formate

This format specifies three characters for the full day name of the week, one digit to represent the day of the month, three characters to represent the month, and four digits to represent the year.

String dateInString = "Mon, 05 May 1990";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, d MMM yyyy", Locale.ENGLISH);
LocalDate dateTime = LocalDate.parse(dateInString, formatter);

In this tutorial, we will show you how to convert a string to java.util.Date. Many Java are stuck in early date conversion, hope this summary guide will help you in some ways.

// String -> Date

    // Date -> String

Common Date and Time Patterns

  • y – Year (1998; 98)
  • M – Month in year (July; Jul; 10)
  • d – Day in month (1-31)
  • E – Day name in week (Friday, Sunday)
  • a Am/pm marker (AM, PM)
  • H – Hour in day (0-23)
  • h – Hour in am/pm (1-12)
  • m – Minute in hour (0-60)
  • s – Second in minute (0-60)

Adding Time Zone Information to java.util.Date

It is important to note that java.util.Date has no concept of time zone, and only represents the number of seconds passed since the Unix era - 1979-01-01T00: 00: 00Z.
But, when we print the date object directly, it will always be printed with the Java default system time zone.
In this last example, we'll look at how to format the date by adding time zone information:

Convert String to Date: Function

After this section I have shared a complete example to display the string in various date formats for date conversion. For those who want only one function for this conversion, here is the function code:

// Java program to convert String to Date 
import java.time.Instant; 
import java.time.format.DateTimeParseException; 
class GFG { 
        // Function tot convert String to Date 
        public static Instant getDateFromString(String string) 
               // Create an Instant object 
               Instant timestamp = null; 
               // Parse the String to Date 
               timestamp = Instant.parse(string); 
               // return the converted timestamp 
               return timestamp; 
        public static void main(String[] args) 
               // Get the String 
               String string = "2018-10-28T15:23:01Z"; 
               // Get the Date from String 
               try { 
                       Instant timestamp = getDateFromString(string); 
                       // Print the converted Date 
               // Throws DateTimeParseException 
               // if the string cannot be parsed 
               catch (DateTimeParseException e) { 
                       System.out.println("Exception: " + e);