Saturday, March 4, 2023

The How of Wi-Fi P2P Programming

 With the prevalence of Wi-Fi, it's now possible to share information without a SIM card using Wi-Fi Direct (also known as Wi-Fi P2P). 

You may refer to https://developer.android.com/guide/topics/connectivity/wifip2p for the details of Wi-Fi Direct (P2P). Or you can scroll down this page to find the appendix of this article for a brief introduction with 5W1H method. 

As a programmer, I once wondered how to create an app that uses this technology, and years ago I was able to make a simple app that could communicate between two phones. 

In 2023, I wanted to try communicating among three phones, but I couldn't find my old source code after changing laptops, so I had to start from scratch. 

However, I ran into some issues - for example, new privacy control policies caused the app to stop working. After several weekends of troubleshooting with my available phones, the app now runs smoothly most of the time. 

I'd like to share my findings with others who are curious about exploring this technology.


The sequential diagram of my App

 


A basic Wi-Fi P2P application should have MainActivity and the BroadcastReceiver classes. In general, the steps to develop a Wi-Fi P2P application are as following:

1. Add the following permissions to AndroidManifest.xml file

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<uses-permission

    android:name="android.permission.NEARBY_WIFI_DEVICES"

    android:usesPermissionFlags="neverForLocation" />

Explicit codes should be added into the JAVA code as shown in my findings below.

2. In MainActivity Java class, create a WifiP2pManager object, which is used to manage Wi-Fi P2P operations, and a WifiP2pManager.Channel object, which represents the channel used for communication with the Wi-Fi P2P framework

WifiP2pManager manager;

WifiP2pManager.Channel channel;

3. Register a broadcast receiver to receive Wi-Fi P2P intents

Do the following in MainActivity’s onCreate():

filter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);

filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);

filter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);

Handle above intents in the BroadcastReceiver: 

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {

    @Override

    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

        if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {

            // Wi-Fi P2P peers changed

        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

            // Wi-Fi P2P connection changed

        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {

            // Wi-Fi P2P device information changed (self)

        }

    }

};

Register the receiver in onResume(): 

registerReceiver(receiver, filter);


4. Initialize the WifiP2pManager and WifiP2pManager.Channel objects in onCreate()

manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);

channel = manager.initialize(this, getMainLooper(), null);


5. Discover other Wi-Fi P2P devices on the network

manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {

    @Override

    public void onSuccess() {

        // Discovery initiated successfully

    }


    @Override

    public void onFailure(int reasonCode) {

        // Discovery initiation failed

    }

});

6. Handle the list of discovered peers

manager.requestPeers(channel, new WifiP2pManager.PeerListListener() {

    @Override

    public void onPeersAvailable(WifiP2pDeviceList peerList) {

        // Handle the list of discovered peers

    }

});


Finding 1: the permission control is different among Android OS versions

This is the first headache point. Eventually, following code solves it on my 3 phones:

private void CheckPermission() {

if (ContextCompat.checkSelfPermission(this, Manifest.permission.CHANGE_WIFI_STATE)

!= PackageManager.PERMISSION_GRANTED) {

Log.i(TAG, "CHANGE_WIFI_STATE was not granted");

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CHANGE_WIFI_STATE}, 1);

}

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU ) {

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)

!= PackageManager.PERMISSION_GRANTED) {

Log.i(TAG, " <TIRAMISU: ACCESS_FINE_LOCATION not granted");

// Permission is not granted

ActivityCompat.requestPermissions(this,

new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 2);

}

}

else

{

if (checkSelfPermission(Manifest.permission.NEARBY_WIFI_DEVICES)

== PackageManager.PERMISSION_GRANTED) {

Log.i(TAG, "TIRAMISU+: NEARBY_WIFI_DEVICES granted");

// Permission is granted, proceed with using the NEARBY_WIFI_DEVICES permission

// ...

} else {

Log.i(TAG, "TIRAMISU+: NEARBY_WIFI_DEVICES not granted");

// Permission is not granted, request the location permission again

ActivityCompat.requestPermissions(this,

new String[]{Manifest.permission.NEARBY_WIFI_DEVICES}, 3);

}

}

}


Finding 2: IP for different group owners are the same (192.168.49.1)

At first I thought devices in the same WiFi network should have their own unique IP (this could be true because I can check from the WiFi Router). When I set 2 phones as group owner, their IPs are the same. Actually, every time when a group is formed, the client’s IP will change. My efforts were in vain in trying to get each device’s IP to be used for socket communication. 

Knowing this will save much time in developing your own App.


Finding 3: Client can only see the group owner

In a Wi-Fi P2P group, there will be only one group owner which the client can get its IP address. The clients cannot see each other. 


Finding 4: Set a group owner with createGroup

A group would be created after one device connected to the other with manager.connect(). However, there is no guaranty which will be the group owner. Of my 3 phones, Huawei Mate 20 Pro would be always the group owner even I manipulate the value of groupOwnerIntent. But once you call createGroup, the phone will become group owner and then the others can connect to it to be a client.


Finding 5: You cannot enable or disable your Wi-Fi function from WifiP2pManager

Meaning you can only manually turn on or turn off the phone’s Wi-Fi feature from the phone settings.


Finding 6: Connect success doesn’t mean the connection succeeded

manager.connect(channel, config, new WifiP2pManager.ActionListener() {

    @Override

    public void onSuccess() {

        DisplayStatus("Connecting...", ContextCompat.getColor(getApplicationContext(), R.color.Color_Info));

    }

    @Override

    public void onFailure(int i) {

    }

});

It simply means this command has been executed successfully, while the connection is established or not you have to check WIFI_P2P_CONNECTION_CHANGED_ACTION.


Finding 7: different behaviours when connect

In my Android 10 phone, after connect() or createGroup() command is called, the BroadcastReceiver’s WIFI_P2P_CONNECTION_CHANGED_ACTION message is only received once with Connected, however in the Android 13 phone, the message is first received with Disconnected, then received again with Connected:

NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

Log.i(TAG, "WIFI_P2P_CONNECTION_CHANGED_ACTION: "+ networkInfo.isConnected());


Finding 8: Disconnect at startup

Somehow the Android OS may memorize the WifiP2P group. So after initialization of the App, I just disconnect the phone from any group:

manager.removeGroup(channel, disconnectListener);


Finding 9: Group information is only meaning to the group owner

You can check the group information like this:

manager.requestGroupInfo(channel,groupInfoListener);

WifiP2pManager.GroupInfoListener groupInfoListener = new WifiP2pManager.GroupInfoListener() {

    @Override

    public void onGroupInfoAvailable(WifiP2pGroup group) {

        //List<WifiP2pDevice> clients = (List<WifiP2pDevice>) group.getClientList();

        if (group != null) {

            Collection<WifiP2pDevice> clients = group.getClientList();

            int numClients = clients.size();

            Log.d(TAG, "onGroupInfoAvailable: Number of clients connected: " + numClients);

            Toast.makeText(getApplicationContext(), "Group size " + numClients, Toast.LENGTH_SHORT).show();

        }

        else {

            Log.d(TAG, "onGroupInfoAvailable: no group but size "+recvThreads.size());

            Toast.makeText(getApplicationContext(), "no group", Toast.LENGTH_SHORT).show();

            ResetData();

        }

    }

};


However, for the group owner phone, the client list size is 1 or 2 (total 3 phones); in client phone, the size is always 0. 


Finding 10: Sending payload with your phone’s identification

You can send the string information as this:

new SendStringTask(socket).execute(WELCOME_INFO);

private class SendStringTask extends AsyncTask<String, Void, Void> {

    private Socket socket;

    String ipAddressOutput;

    public SendStringTask(Socket sk) {

        ipAddressOutput = sk.getInetAddress().getHostAddress();

        socket = sk;

    }

    @Override

    protected Void doInBackground(String... params) {

        String msg = params[0];

        try {

            if (socket == null)

            {

                Log.i(TAG, "SendStringTask do nothing to " + ipAddressOutput);

                return null;

            }

            Log.i(TAG, "SendStringTask write with socket "+ socket);

            OutputStream outputStream = socket.getOutputStream();

            outputStream.write((myDeviceName+": "+msg).getBytes());

        } catch (IOException e) {

            Log.i(TAG, "SendStringTask IOException: "+ e.toString());

            e.printStackTrace();

        }

        return null;

    }

}


The 3 phones I used for testing: 

Huawei Mate 20 Pro (Android 10, API 29) 

Samsung A11 (Android 12, API 31)

Samsung A13 (Android 13, API 33)



Sample App


Details of the source codes can be found at https://github.com/happytong/FunWifiP2P. 

You can download the App with WiFiP2P here: https://play.google.com/store/apps/details?id=com.tongs.funpatternwifi



Appendix: Introduction of Wi-Fi P2P with 5W1H (by chatGPT)


Wi-Fi Direct or Wi-Fi Peer-to-Peer (P2P) is a wireless networking technology that allows devices to communicate directly with each other without the need for a traditional wireless access point or network infrastructure. With Wi-Fi P2P, devices can connect and communicate with each other, regardless of their operating system, manufacturer or device type. Here is an introduction to Wi-Fi P2P technology using the 5W1H framework:

What is Wi-Fi P2P technology?
Wi-Fi P2P technology is a wireless networking standard that enables two or more devices to connect and communicate with each other directly, without the need for a traditional Wi-Fi access point or network infrastructure. It is a fast, easy, and secure way to share files, media, and other data between devices.

Why is Wi-Fi P2P technology important?
Wi-Fi P2P technology is important because it enables devices to communicate directly with each other without the need for a traditional network infrastructure. This is useful in situations where there is no Wi-Fi access point available, or where it is not practical or desirable to connect to a network. Wi-Fi P2P also enables faster data transfer speeds and reduces battery consumption compared to traditional Wi-Fi connections.

Who uses Wi-Fi P2P technology?
Wi-Fi P2P technology is used by a wide range of devices, including smartphones, tablets, laptops, cameras, printers, and other consumer electronics. It is particularly useful for sharing files, photos, and videos between mobile devices, as well as for printing and scanning documents without the need for cables or network infrastructure.

Where is Wi-Fi P2P technology used?
Wi-Fi P2P technology can be used in a variety of settings, including homes, offices, public spaces, and outdoor environments. It is particularly useful in situations where there is no Wi-Fi access point available, such as in remote locations, outdoor events, or in areas with poor network coverage. Wi-Fi P2P can also be used for peer-to-peer gaming and other interactive applications.

When was Wi-Fi P2P technology developed?
Wi-Fi P2P technology was developed by the Wi-Fi Alliance, a nonprofit organization that develops and promotes Wi-Fi standards. The Wi-Fi Alliance introduced Wi-Fi Direct in 2010, which became the first Wi-Fi P2P standard. Since then, Wi-Fi P2P has become increasingly popular and is now widely supported by a variety of devices and operating systems.

How does Wi-Fi P2P technology work?
Wi-Fi P2P technology works by establishing a direct connection between two or more devices using Wi-Fi Direct. To establish a connection, one device needs to discover the other device and send a connection request. Once the connection is established, the devices can communicate directly with each other, without the need for a network infrastructure. Wi-Fi P2P also supports various security features, including WPA2 encryption and device authentication, to ensure that the connection is secure.

Saturday, February 18, 2023

Role descriptions with 5W1H

What is your role in your daily life? Here are some enlightening examples with 5W1H description which generated by OpenAi.

Please take note of the pattern for each role, especially the "How" section which highlights the methods to achieve the role's responsibilities and obligations. In general, the key points are communication and learning.



Describe the role of boss in a company with 5w1h

Who is the boss in a company?

The boss in a company is typically the highest-ranking individual who oversees the operations of the organization, manages employees, makes key decisions, and is accountable for the overall success of the company.

What does the boss do in a company?

The boss has several key responsibilities in a company, including:

  • Setting goals and objectives for the organization
  • Developing strategies and plans to achieve those goals
  • Managing and leading employees to ensure they are productive and engaged
  • Making important decisions related to hiring, firing, promotions, and compensation
  • Allocating resources effectively to maximize profitability and efficiency
  • Representing the company to external stakeholders, such as customers, investors, and regulatory bodies.

Why is the role of the boss important in a company?

The role of the boss is crucial in ensuring that the company operates efficiently, achieves its goals, and remains competitive in its industry. The boss sets the tone for the organization's culture and is responsible for creating a positive work environment that fosters productivity, creativity, and innovation.

When does the boss perform their duties?

The boss is typically working during regular business hours, but may also work outside of normal hours to accommodate the needs of the business or their employees.

Where does the boss operate in a company?

The boss can operate in various locations within a company, depending on the size and structure of the organization. They may have an office, a desk in an open-plan workspace, or even work remotely.

How does the boss interact with others in a company?

The boss interacts with a variety of stakeholders within the company, including employees, customers, suppliers, and investors. They may communicate with others through meetings, email, phone calls, or in person. Effective communication is essential for the boss to lead and manage the organization successfully.


Describe the role of a supervisor in a company with 5w1h

Who is a supervisor in a company?

A supervisor in a company is an individual who is responsible for overseeing a team or group of employees, ensuring that they meet performance standards, and achieving the objectives of the company.

What does a supervisor do in a company?

The role of a supervisor in a company includes:

  • Managing and leading a team of employees to ensure they are productive and efficient.
  • Monitoring employee performance and providing feedback on their work.
  • Developing and implementing processes and procedures to improve efficiency and quality.
  • Providing guidance and support to employees on work-related issues.
  • Communicating with management about the performance of the team and any issues that arise.
  • Ensuring that the team complies with company policies and regulations.
  • Identifying training and development needs of team members and providing necessary training.

Why is the role of a supervisor important in a company?

The role of a supervisor is critical to the success of a company, as they are responsible for managing the employees who directly contribute to the company's operations. Supervisors ensure that employees are productive, efficient, and work in a safe and healthy environment. They also facilitate effective communication between employees and management, and can improve employee engagement and job satisfaction.

When does a supervisor perform their duties?

A supervisor typically performs their duties during regular business hours, but may also work outside of normal hours to accommodate the needs of the business or their employees.

Where does a supervisor operate in a company?

A supervisor can operate in various locations within a company, depending on the size and structure of the organization. They may have an office, a desk in an open-plan workspace, or even work remotely.

How does a supervisor interact with others in a company?

A supervisor interacts with a variety of stakeholders within the company, including employees, customers, suppliers, and management. They may communicate with others through meetings, email, phone calls, or in person. Effective communication is essential for the supervisor to lead and manage the team successfully.


Describe the role of an employee in a company with 5w1h

Who is an employee in a company?

An employee in a company is an individual who works for the organization and is compensated for their time and effort.

What does an employee do in a company?

The role of an employee in a company includes:

  • Carrying out assigned tasks and responsibilities to contribute to the overall objectives of the company.
  • Following company policies and procedures, as well as any relevant laws and regulations.
  • Communicating effectively with supervisors and coworkers to ensure the smooth operation of the business.
  • Participating in training and development programs to improve their skills and knowledge.
  • Maintaining a safe and healthy work environment by following company guidelines for safety and health.
  • Contributing to a positive work culture by displaying professionalism and a positive attitude.

Why is the role of an employee important in a company?

The role of an employee is essential to the success of a company, as they are responsible for carrying out the day-to-day operations of the organization. Employees who perform their jobs effectively can help the company achieve its objectives, improve efficiency, and contribute to a positive work culture.

When does an employee perform their duties?

An employee typically performs their duties during regular business hours, but may also work outside of normal hours to accommodate the needs of the business or their team.

Where does an employee operate in a company?

An employee can operate in various locations within a company, depending on the nature of their job. They may work in an office, a factory, a store, or even remotely.

How does an employee interact with others in a company?

An employee interacts with a variety of stakeholders within the company, including coworkers, supervisors, customers, and management. They may communicate with others through meetings, email, phone calls, or in person. Effective communication is essential for the employee to carry out their job successfully and contribute to a positive work environment.


Describe the role of a friend with 5w1h

Who is a friend?

A friend is a person whom one knows and with whom they have a bond of mutual affection and trust.

What does a friend do?

The role of a friend includes:

  • Providing emotional support and being a source of comfort during challenging times.
  • Sharing experiences, interests, and hobbies to strengthen the bond of friendship.
  • Listening actively and offering advice or guidance when needed.
  • Celebrating achievements and milestones together.
  • Respecting each other's boundaries and providing a safe and non-judgmental space for each other.
  • Being trustworthy and dependable in times of need.

Why is the role of a friend important?

The role of a friend is crucial in maintaining good mental health and well-being. Friends offer a sense of belonging, companionship, and social support, which can help reduce stress and improve overall quality of life.

When does a friend perform their duties?

A friend is available to provide emotional support and companionship whenever needed, but the extent of their availability may depend on their personal circumstances.

Where does a friend operate?

A friend operates in various locations, depending on the nature of the relationship. Friends can spend time together in person, over the phone, or through online communication.

How does a friend interact with others?

A friend interacts with others in a friendly and compassionate manner. They communicate openly and honestly, and provide a non-judgmental and supportive environment for others. Effective communication is essential for maintaining a strong and healthy friendship.


Describe a job with 5W1H

Job: Software Engineer

Who: A software engineer is a professional who designs, develops, and maintains software applications and systems. They work with a team of developers, project managers, and other IT professionals to build and maintain software products.

What: The main responsibility of a software engineer is to create software solutions that meet the requirements of clients or end-users. They typically work with programming languages, such as Java, Python, or C++, and use various tools and technologies to build applications, including databases, frameworks, and libraries.

When: Software engineers work in a fast-paced, dynamic environment where deadlines are often tight. They may work on multiple projects simultaneously and need to manage their time effectively to meet project milestones.

Where: Software engineers can work in a variety of settings, including technology companies, software development firms, financial institutions, and government agencies. They may work in an office setting or remotely, depending on the company and job requirements.

Why: Software engineers are in high demand due to the increasing reliance on technology in all industries. They are responsible for building the software products that power many aspects of our daily lives, from mobile apps to e-commerce platforms to healthcare systems.

How: To become a software engineer, one typically needs a bachelor's degree in computer science or a related field, as well as proficiency in programming languages and experience with software development tools and methodologies. Ongoing professional development is also important to stay up to date with emerging technologies and best practices in the industry.


Describe a general job with 5W1H

Job: Sales Representative

Who: A sales representative is a professional who is responsible for selling products or services to customers. They may work for a variety of companies across different industries, including retail, healthcare, finance, and technology. Sales representatives may work alone or as part of a team, and they interact with customers, other sales professionals, and management.

What: The main responsibility of a sales representative is to sell products or services to customers by building relationships, presenting products, and negotiating deals. They typically use a variety of techniques to reach out to potential customers, including cold calling, email, and social media. Sales representatives need to have a good understanding of the products or services they are selling, as well as the needs and preferences of their customers.

When: Sales representatives may work regular business hours, but they may also need to work evenings, weekends, or holidays, depending on the industry and the needs of the customer. They may need to meet sales targets or quotas, and they may work in a commission-based environment where their pay is based on their sales performance.

Where: Sales representatives can work in a variety of settings, including retail stores, call centers, and corporate offices. They may also work remotely, especially if they are selling products or services online or over the phone.

Why: Sales representatives are important for any company that wants to sell products or services. They are responsible for building relationships with customers, understanding their needs, and providing solutions that meet those needs. They help generate revenue for the company and contribute to the overall success of the business.

How: To become a sales representative, one typically needs a high school diploma or equivalent, although a college degree may be preferred in some industries. Sales representatives need excellent communication and interpersonal skills, as well as the ability to persuade and negotiate. They also need to be comfortable working with technology and be willing to learn new skills and techniques to improve their sales performance.


Describe the role of a husband with 5W1H

Role: Husband

Who: A husband is a male partner in a marriage, who is committed to supporting and caring for his wife. He may work in a variety of professions and industries, and his role in the marriage may vary depending on cultural norms, personal values, and individual circumstances.

What: The main responsibility of a husband is to be a supportive and caring partner to his wife. He may provide emotional support, help with household tasks, or contribute to the family's finances. He may also take an active role in parenting, help with decision-making, or support his wife's career aspirations.

When: The role of a husband is ongoing and requires consistent effort and attention. He may need to balance the demands of his career, family responsibilities, and personal life, and may need to adapt to changing circumstances over time.

Where: The role of a husband is primarily played within the context of the marriage and family, although it may extend to other areas of life, such as social and professional relationships.

Why: The role of a husband is important for maintaining a healthy and fulfilling marriage. A supportive and caring husband can help his wife feel loved and valued, and can contribute to a strong and positive family dynamic. He can also model positive behaviors and values for his children and the wider community.

How: To be an effective husband, one must prioritize communication, empathy, and respect in the relationship. This may involve active listening, offering emotional support, sharing responsibilities, and being flexible and adaptable. Husbands may also seek out resources and support, such as counseling or community groups, to help them navigate challenges and build a strong and healthy relationship with their wife.


Describe the role of a wife with 5W1H

Role: Wife

Who: A wife is a female partner in a marriage who is committed to supporting and caring for her husband. She may work in a variety of professions and industries, and her role in the marriage may vary depending on cultural norms, personal values, and individual circumstances.

What: The main responsibility of a wife is to be a supportive and caring partner to her husband. She may provide emotional support, help with household tasks, or contribute to the family's finances. She may also take an active role in parenting, help with decision-making, or support her husband's career aspirations.

When: The role of a wife is ongoing and requires consistent effort and attention. She may need to balance the demands of her career, family responsibilities, and personal life, and may need to adapt to changing circumstances over time.

Where: The role of a wife is primarily played within the context of the marriage and family, although it may extend to other areas of life, such as social and professional relationships.

Why: The role of a wife is important for maintaining a healthy and fulfilling marriage. A supportive and caring wife can help her husband feel loved and valued, and can contribute to a strong and positive family dynamic. She can also model positive behaviors and values for her children and the wider community.

How: To be an effective wife, one must prioritize communication, empathy, and respect in the relationship. This may involve active listening, offering emotional support, sharing responsibilities, and being flexible and adaptable. Wives may also seek out resources and support, such as counseling or community groups, to help them navigate challenges and build a strong and healthy relationship with their husband.

Friday, July 15, 2022

How Can You Enjoy a Job

 

不积跬步,无以至千里。

A journey of a thousand miles begins with a single step.

--- Laozi

 

Most people retire from the job market, some become employers after work for some time. There is no right or wrong choice, it is the result of one’s personality and the opportunity of business.

 

Like or dislike

People often get annoyed when what they are doing is not what they like to do. When looking for a job, the first step is to decide what kind of job to take up, this is the period when you can determine your choices based on your likes or dislikes.

After you have decided to take up a job, it is your responsibility to do it well – whether or not you like or dislike the job no longer matters.

Note that your likes and dislikes may change without you realizing it. It does not take one moment for friends to become enemies – it is the result of a string of events that eventually leads to this change in a relationship.  When you work in a company, if you work hard and get recognition from your colleagues and your boss, you will feel good and may start to like the job more.

Once you have joined a company, put your heart and soul into it during the contracted period, either throughout probation or after confirmation. By doing so, you will learn the most from your job and make your time worthwhile. Your boss will notice your commitment to work, and a good impression will be left on him (or her).

 

Understand the hiring process

We have discussed where you may look for a job, but we also need to understand the hiring process. In general:

1.    The business department gives the required details to the human resource department (HR)

2.    HR publishes the advertisement

3.    You see the advertisement and submit your resume to HR

4.    HR shortlists the resumes

5.    HR contacts you for an interview if you are shortlisted

6.    HR and the business department interview you

7.    Contract is signed if all parties reach an agreement

From this, you can see how HR plays the most important role because it is involved in all the steps. For you, first, you need to pass HR’s filtering procedure.

There is a lot of valuable information online you can find on how to create your resume, here I will not repeat it. The key point is that HR may not necessarily know the actual technology or business requirements but they have the right to discard your resume. When you create your resume, do it from the viewpoint of HR first, so that you can get the opportunity to be interviewed by the business department with whom you will work.

 

Know your limitations

Psychological studies show that most people tend to overestimate their capabilities. For example, 90% of the crowd think they are cleverer than others. In the stock market, only 10% of the investors make money, 70% of them make losses, 20% of them break even without considering the time and effort they have put in. 

When you are working, remind yourself to look for opportunities in your current situation. Do not look down at the current job and your colleagues. Your capability is highly likely to be the same as others, so what you can do is work harder, learn more, and seek to move to a higher level.

Remember, your career phase is the same as the learning phase such that you have to upgrade yourself. Imagine in your learning phase, you always stay at primary 3, after many years, your knowledge will remain at the same level.

 

Understand your emotional quotient

Animals are not typically aggressive and their actions could have been triggered by their perception of threat. On 30 November 2021, a man was doing his morning walk at the Singapore Botanic Garden when he encountered a bevy of about 20 otters. Unfortunately, he was mistaken for a runner who had passed by the otters and may have accidentally hit one of the otters. He was attacked and suffered more than 20 wounds, with some requiring stitches. Luckily, his friend “screamed and shouted at the animals, who stopped their actions momentarily. The duo ran towards a nearby visitor center with the otters giving chase for a short distance.”

- https://www.straitstimes.com/singapore/environment/i-actually-thought-i-was-going-to-die-man-who-was-attacked-by-otters-at

This is the real world. Human beings could be attacked innocently by animals with lower emotional intelligence. Think of the work environment - some people with a straight temper may be easily irritated, and some introverted staff may burst out suddenly. Think of a gathering among friends, the harmonious ambiance may suddenly be broken because someone mentions something unpleasant. In most cases, losing one’s temper does not make the situation better. In general, containing your negative feelings in the working environment is helpful to your career.

There is a lot of information you can find online about emotional intelligence, about how to train yourself in self-management, self-awareness, social awareness, and relationship management. The following picture about otters tells you the key points to maintaining a good relationship with others.

 


  

Know your colleagues

 You may meet many different kinds of colleagues, here are 4 categories you may classify them into: 

A.   Active working with high efficiency

B.   Active working with low efficiency

C.   Passive working with high efficiency

D.   Passive working with low efficiency

Active and passive reflects the attitude, and efficiency reflects the skills. You need to find out your category for this job. If you find you are A and B, there is a high chance you are doing a job in your favourite area. If you are C and D, you probably need to consider changing jobs after some time if you still cannot switch to A and B.

Knowing your colleagues’ types may help you determine the way to best work with them. Minimize your time spent with D, tell C what to do, help B to improve his or her skills, cooperate with A. Remember, people’s categories may change over time as well.

 

Office politics

You may also know office politics. Yes, that’s also part of the real world. A company is a small society of the outside world. In every country, there is a government; in every government, there are people who play politics.

We often hear about dirty politics. However, not all politics are bad. A system with positive politics does good to the society, motivates people to behave well, and increases the efficiency of accomplishing the goals of the society.

Office politics is unavoidable, it is part of the company’s culture. But in most cases, it is an art of socializing and managing relationships. If you cannot handle it in one company, everything you try to do is out of tune, then you have to make a decision, change yourself or change the boss. If you do not realize your weakness or shortcomings, changing the boss will not solve the problem.

 

Set a goal for your job

A boat without a destination can never reach the shore. Working is progress that needs a goal to achieve. Without a goal, your life may look busy but in the end, you would not feel the sense of accomplishment – you will not feel satisfied. 

You need to set a goal for the job you will take up. The goal you set should have a deadline, which can be a 6-month goal, 1-year goal, or 5-year goal. Longer-term goals are not necessary because, in this ever-changing world, we are unable to predict the future after 5 years.

After the deadline, be sure to review and define the goal for the next period.

If you have not set a goal, do it now. It is never too late.

 

Be a happy person

When you are in a good mood, perhaps you are talking to your favorite person, time flies; if you are talking with a boring person, just one minute is too long. This is the layman’s explanation of Einstein’s Theory of Relativity. If you enjoy doing something, hard work will become less of a burden, because you will concentrate on it and do it well.

Feelings are mysterious. Something you disliked at first may be your favorite after some time. Smile when you are working, it will make you feel better.

Of course, you cannot pretend to be happy. You have to have accepted the current situation, yourself, and the external environment, and you need to have made a goal. Only then will you feel free and at peace to accomplish the goal.

We know we have a 40-years career phase in general. Don’t waste time – it will never come back again. You have a dream, stick to the dream, find a job, and absorb new knowledge from the job while contributing to the company. Every job you do, there should be a target for that job, after you learn enough from that, you realize the target, then you may restart the process of the next job cycle.

This is the life that is under our control, a life with a goal.

Saturday, February 26, 2022

Life Is a Journey of Jobs

谋事在人, 成事在天

Man proposes, God disposes.

--- Romance of the Three Kingdoms by Luo Guanzhong

 

With this, we come to the end of this series. We started with a general definition, understanding the job as a task. A task is to accomplish a goal. So the first thing is to set a goal, then accomplish it.

For every person, and even every animal, to survive in this world is the first and final goal.

After centuries of evolution, human society has developed a system of structural hierarchy: governments, institutions, companies, international laws, rules… We are living under such a system, our life becomes structural: starting with a learning phase, then a career phase, and ending in a retirement phase.

Every phase has its different goals. In the learning phase, the goal is to learn basic skills and knowledge; in the career phase, the goal is to make money; in the retirement phase, the goal is to end our life gracefully. A goal in the previous phase is the basis of the next phase.

With the goals built in mind, people make the efforts to fulfill the goals and like cogs in a system, human society moves forward. Life is a journey of fulfillment of tasks. Enjoy life on this journey.

Every one of us is part of the torrent of the times. The fortunate or the unfortunate, the lucky or the unlucky, everything depends on ourselves, depends on how we behave ourselves and how we interact with each other.

This is the end of this series, but it may be a new start for you to thrive in the job market. If there is any sentence that ignites within you a new idea, don’t ignore the idea.

Do your retrospective study, and make your version of 5W1H of something, you will live a more exciting life!




Friday, February 18, 2022

Where Can You Find a Job

敢问路在何方?路在脚下。

Dare to ask where is the way? The road is on your feet!

                          --- Theme song of television show Journey to the West

 

Everything is online

In this age of information, everything can be found online. Companies build their websites, set up channels on social media platforms, and people can easily access all the information about their products and services. This is the way for the job seeker to get to know and understand the company’s business.

Besides traditional job advertisements in the newspaper, many Internet platforms provide information about job opportunities from companies all over the world.

Some platforms, like LinkedIn, build a bridge between individuals and companies. You can view the job opportunities provided by the companies and apply via simple operations through the LinkedIn App. Alternatively, you can also register and post your job-seeking information for others to view and contact you by.

Your information on the Internet is then important if you want to increase your chances of getting a job you want. Do build up a good profile for yourself and present yourself well across different platforms.

 

Networking 

When you have a problem, what will you do?

A.   Look for advice from the Internet (DIY: do it yourself)

B.   Look for advice from family and friends

C.   Look for advice from a paid consultant

Obviously, human nature will make you select C after options A and B have been exhausted. When a company advertises a job vacancy, it follows the same logic: nobody could solve the problem the company had so employers had to turn to the job market to employ you. However, this is only after they have failed to find people from “family and friends”, i.e. existing staff and other people they know.

This is the importance of networking. Try to get known to more people, let them know what you are doing and what you would like to do. This way, others may help introduce you when there is a job opportunity that suits your skills and interests. Of course, this is a bonus to your job searching effort. First and foremost, you need to build up your reputation so that other people are inclined towards helping you. If you do not behave with a good attitude, constantly job-hopping, at the end of the day, your friends will try to avoid you.

 

Break out of your zone of discomfort

Business magnate Elon Musk was the richest person in the world as of December 2021. He was born in a rich family in South Africa but had a miserable childhood from both his family and his secondary school. His mother was a victim of domestic violence since her honeymoon with his father. His father was "a terrible human being... Almost every evil thing you could think of, he has done." In secondary school, he was a target for bullies for a long time.

This tragic childhood forced him to leave the place for Canada, where his mother was born, once he turned 18. After one year in Canada making a living by doing odd jobs, he moved to the United States for his university studies. From then on, he became a millionaire and then a billionaire.

He decided to go to the United States because he once travelled there during his childhood and got to know that there was such a heavenly place compared to South Africa.

When you feel uncomfortable at your current job, try a new life at a different place. Do some research and make a short visit to those intended places, it may give you a better life.

 

Get out of your comfort zone

This does not mean you should stick to your comfort zone. The outside world is risky, and staying where you are familiar could be tempting. Millions of years ago, those who were curious about the external world were likely to be killed by tigers, lions, or snakes during their adventures. Only the genes of those that remained in the protected zones could be passed on to the future generations.

Most people fall into this trap and never try a different life. Comfort may kill you in the sense that you prevent yourself from potentially getting a better life. Stability is good because we don’t need to make excessive effort to make a living. However, in this ever-changing world, there is nothing that will remain the same forever. When you are eventually forced to change, you may not have enough time or the capability to learn a new skill set to adapt to the new world.

 

Start from the dream you had

Do you remember your dream of the future when you were a teenager? “Yes, that was childish,” you may say. If we can measure the size of a dream, it would be biggest when you were young. As you age, this dream becomes smaller and smaller.

This is because you gain a clearer understanding of the world as you grow older. You come to know about competition and learn where your boundary lies. Day by day, your original ambitions get diminished by the cruelty of reality. You gradually lose your passion to explore the outside world, to pick up skills for your ambitions.

But your dreams are where your future starts. Your dream will guide you to the future. Your future is somewhere that is unpredictable but better than the present. It would be tragic if you still lead the same life you lead currently 10 years later.

Look around yourself, there are people younger than you, there are people older than you:

      Now you are at the age of 25, your colleague now is at the age of 35, do you want to be living the same life 10 years later?

      Now you are at the age of 35, your colleague now is at the age of 45, do you want to be living the same life 10 years later?

      Now you are at the age of 45, your colleague now is at the age of 55, do you want to be living the same life 10 years later?

Your future starts from your heart, starts from today. Think about the future, think about what you can do, revive your dreams, your new job is under your feet now.

Saturday, February 5, 2022

Who Provides a Job

 I am no bird; and no net ensnares me: I am a free human being with an independent will.

---- Jane Eyre by Charlotte Brontë

In society, some people work for other people; we can simply call this relationship as employment – the employees work for the employers. In this section, let us look at the “employer” in detail.

 

Who is the employer

Generally speaking, an employer is the owner of a business who provides work opportunities for others.

There are many types of business units. You have the government service department, big enterprises like public-listed corporations and small businesses like a retail store in the shopping center.

For convenience, we will just use “company” as a general business unit, meaning that when we say “employer”, they can be government officers to the civil servants, the human resource department of a corporation, or the shop owner to the salesperson.

 

Know your first employer

When you take up your first job, you are switching from the learning phase to the career phase. For most people, the first job does not last for long. This may be because you may not be comfortable when entering the career phase – you are still exploring the job market and trying to adapt to the new environment. However, you still need to take this opportunity to get to know your first employer. By doing this, you will be able to better adapt to your future employers and work with greater freedom later in your career phase. This is a necessary step you need to take, even if you may not want to create your own business to become an employer.

You need to find out the answer to the following questions:

 What is this business? What is the future of the business (in 5 years, 10 years, etc.)?

 What is the market for this company? What comparative advantage does this company have that differentiates it from the others?

 What is the culture of this company?

 Is the boss trying to boost employees’ morale to promote productivity or just to make use of the staff?

Bear these questions in mind as you work and try to answer them within 2-3 months after you have joined the company. These 2-3 months are normally the probation period in the employment contract, during which you can terminate the job with immediate notice without receiving a penalty.

From the answers, you will decide if you want to stay there or not.

My first job was working as a technician to develop a road light control system. Four fresh graduates worked under the boss who had just quit university one year before. It was a project-based development and we did not have a marketing staff. We were free most of the time, and playing computer games became routine when the boss was absent. If you check the above question list, you would find that there was little reason to stay in such a company for long.

 

What is the most important factor to confirm a job

Is there a perfect job? There may be but these are often difficult to find. A job needs your attention, your effort, your concentration, and your cooperation with your colleagues. This means you have to make a commitment and contribute to the job first, only then will you be able to harvest the fruits of your labor.

So there is no easy job, but when you consider a job, what is the most important factor?

Unfortunately, there is no definite answer to this. One man’s meat is another’s poison. If we look at some specific angles, however, there is something we may have a clearer answer to.

If you have chosen an industry, you can consider finding a “good” company to work for in the short term (e.g. for the next 1-3 years). In this context, I would say your direct boss (i.e. your supervisor) is the most important factor.

Focus on your supervisor during the probation period to see if you want to continue the job after that. Observe his or her attitude to your fellow colleagues – how he or she interacts with and promotes cooperation among the team, how he or she handles customers’ complaints… Consider these, and if you feel like your supervisor is good to work with, then you can confirm your stay with the company after the probation period.

If the company is big, you may consider looking to your supervisor’s boss for answers as well.

 

There's more than one way to skin a cat

If you never write, a pen is nothing to you. When you write, a pen is a tool for you to use; if the pen runs out of ink or is not comfortable to write with, you can throw it away and buy a new one.

The same relationship applies to you and your employer. Without employment, you don’t care who or what the employer is. The employer only matters to you when you are employed. But you don’t have to stick to one company. You have the right to terminate a service according to the employment contract you signed.


Note the company is not a charity, as an employee you should contribute and dedicate yourself to its business. Apply for a job only after you have conducted sufficient research on the company – you will not waste time trying out a company you would not work for that way.

 

What should an employer do

Once upon a time, I was an employer myself. I was a co-founder for a blooming company – the market niche was there, what we had to find was potential customers to help sell our services. However, frequent business socializing and the constant pressure of the next payment of rentals and employees’ salaries deteriorated my health. The business is now obsolete today.

It is not easy for the employer. The employer should be able to look far into the future to make sure the business has a future. In simpler terms, the employer needs to have a vision. Only by creating one can he progressively re-organize the company to adapt to the business evolution while maintaining its core foundations.

The employer then has to be kind to the employees if he or she really wants to realize their vision. The employees determine the strength of the company and are essential to making the employer’s vision come true. The employer should understand that happiness breeds productivity – it is a virtuous cycle. The vicious cycle is contrary: when one feels bad, everything he or she does becomes inefficient and may even go wrong. Hence, a boss who knows how to motivate the employees will benefit far more than those who exploit employees as tools.

If you are a boss and not aware of this, stop and ask yourself: in retrospect, was there anything I’ve done wrong? Did any staff I had valued leave due to management problems? Will my ambitions be delayed without a productive and collaborative team?

Thursday, February 3, 2022

When Should You Take Up a Job


工欲善其事, 必先利其器

A workman must first sharpen his tools if he is to do his work well

--- Confucius

 

The trends of human lifespan

Human lifespan continues to increase due to the improvement of sanitation, medical care, and advancement of science and technology. In 1990-1995, the global life expectancy was 64.56. Now in 2020-2025, it is 73.16. The following picture (https://ourworldindata.org/life-expectancy) gives more details on global life expectancy over the past 200+ years:


Three phases of a life

We can roughly segment the human life into three phases:

      Learning phase (age 0 - 25)

      Career phase (age 25 - 65)

      Retirement phase (age 65+)

When we were born, we were so weak that we were not capable of doing anything. Our parents take care of everything for us – they nurture us, clothe us, feed us, and send us to schools to learn skills and knowledge. This is the learning phase. We assume the first 25 years of our human lives are in the learning phase.

Then we will find a job to make a living, to support the family. We will build up our own family and have our children. This is the career phase. This phase is the most important phase in which human beings as a species inherit from one generation to the next. We assume the statutory retirement age is 65, so 40 years of your life are in the career phase.

As we grow older year by year, the body starts to deteriorate like how a machine gets rusty. We gradually lose competency in the work market, and eventually have no choice but to quit our jobs. This is the retirement phase.

Of course, there are exceptions. The above age range cannot reflect the practices of the whole mankind – it only illustrates a picture of the life of the common folk.  Many notable figures live out their lives following a different timeline. For example, Donald Trump and Joe Biden  were elected into US presidency at the age of 71 and 79 respectively; billionaire Li Ka-Shing retired at the age of 90; Chairman & CEO of Berkshire Hathaway, Warren Buffett, is now 91 years old; and its vice Chairman Charles Munger is now 97 years old this year (2021).

Few of us will come to lead a life like theirs. Most of us retire at age 65 and live up to age 80. By this timeline, half of our lives will be in the career phase. Is it too long, or too short? What does that mean to your whole life?

It means that this 40 years of your lifetime, during which you create value to this world, is a result of your first 25 years’ learning phase, and it also defines the standard of living in your last 15 years of retirement phase, e.g., how much money you could spend each month, how well you would live with your family and how happy you would pass every day.

 

Critical periods of language development

Have you ever noticed, as we age, it becomes harder and harder to pick up new skills? Scientists have found that speaking a language is a nature that can only be learned before a young age like 7. If one does not learn a language during these “critical periods of language development”, one cannot speak or even understand human languages in the later stages of life. This was the key finding from studies on people raised by animals like wolves, e.g., Wild Child of Aveyron.

There are people in isolated places who live an primordial lifestyle. Scientists find that some languages don’t even have quantitative concepts. For example, studies show that the Piraha people of the Amazon “were not able to do the one-to-one correspondence when the numbers were greater than two or three.” (University of Miami. "You can't do the math without the words: Amazonian tribe lacks words for numbers." ScienceDaily. ScienceDaily, 21 February 2012.)

So make full use of the learning phase, it will be easier for you to pick up a skill and master it. In your career phase, the company may give you stable jobs for many years, and you may stop developing yourself during this long period. However, there is no permanent job in the world. At the end of the day, you will be kicked out because you don’t have the upgraded skills that the company needs.

 

Your first job

Many countries provide compulsory and free education for primary schools and secondary schools. If you live in such countries, you have no rush to find an employment job during this period. After that, you have the choice to further your education in universities or go for a job.

Some people would have no hesitation to find a job after secondary education at a typical age of 18 -- this could be a reason why in many countries, the age of attaining legal adulthood is 18. That is a natural choice for people in the following scenarios:

      Academic performance is not good

      Want to make money as soon as possible

      Cannot afford the cost of university

      No preference and there is a job opportunity so just take it

However, higher education has its pay off. Most of the companies give the basic salary according to the educational level. For example, monthly $1800 for a secondary school graduate while $3500 for a degree holder.

Once you take up a job, your career phase starts. But if you are still in school, and take up a part-time job, then you have an overlapped phase with both the learning phase and career phase.

 

Change a job

After you take up a job, you have a new role in your life, and you are making money to support yourself, and perhaps your family as well. However, this new role needs an alteration of your mindset. You need time to adapt to the new role, adapt to the new environment.

Very often, especially in your first job, you may quit the job because:

      the situation is not satisfactory

      the job does not meet your expectations

      the job does not suit your skillset

      too much time is spent on the transport

      you do not like the company’s culture or environment

      you are unable to work with the boss or the colleague

      you feel dissatisfied with the salary etc.

You may then start to look for the next job. Some may, however, choose to go back to school to continue the learning phase for the following reasons:

      To improve their skill set

      To learn new knowledge in a different industry

      To get a certificate of higher education for higher starting pay

 

Haste makes waste

In ancient China, there was a farmer, who was eager to help the plants grow faster. When the shoots broke out of the soil, he helped uproot them so they looked taller. This of course killed the plants.

This is the story behind the Chinese idiom: 拔苗助长 (Ba Miao Zhu Zhang). This lesson learnt is this: haste makes waste. Everything happens as they should, speeding up the procedure would cause a breakdown and result in a premature failure.

Before you look for a new job, make sure you have the required capability for it. If not, try to learn first, don’t be impatient.

 

Power of inertia

Do you remember Newton’s first law of motion? If there is no external force, a moving object will remain at its constant velocity and a stationary object will remain at rest. This is also called the law of inertia. 

When this law applies to your career, the result is obvious: if you are not forced to improve, you will slowly stagnate.. You may not even realize it until it is too late.

In the 19th century, there was a famous 6-year rebellion in England referred to as the Luddites. Due to the industrial revolution, weavers and artisans lost their jobs; they struggled and in the end, went out smashing the mechanized looms. More than 10,000 troops were deployed to suppress the Luddites.

In 1956, the invention of containers revolutionized the shipping industry, and the world’s supply chain became enormously efficient. However, many dockworkers in the port lost their jobs. They went on strike but it was all in vain – they eventually had to learn new skills for the new industry.

Remote working was once hailed by the futurists, but when the world was suddenly attacked by COVID-19, the world was forced to speed up the procedure. In one night, companies had to allow working from home as a default method.

As individuals, we are unable to stop the path of history. In this digital world, technology advances faster than ever, we have to adapt ourselves to the trend. We need to take an active attitude to learn from the daily tasks in our current jobs, and also keep an open mind to learning new technology.

If you are constantly preparing for the future every day, you will have no regrets in the future. When it is the time for you to change a career path, just do it!


 

How to draw countless lines without rendering delay in Android Phone

If you just call the drawing API to draw lines on the screen, you may be comfortable using it when the line number is small, you will see th...