Posts

Detecting shut down and reboot in android

Hi, Have a great day frnds.. Now we going to look up the detecting shut down and reboot events in android. Here is the code: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ShutDownReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {             Log.i("event", "shutdown");         } else if (intent.getAction().equals(Intent.ACTION_REBOOT)) {             Log.i("event", "reboot");         }     } } Then apply in your activity, shutDownReceiver = new ShutDownReceiver(); filter.addAction(Intent.ACTION_REBOOT); filter.addAction(Intent.ACTION_SHUTDOWN); @Override     protected void onPause(...

Detecting Screen on and Screen Off via services

Hi buddies, have a happy Sunday. Today I'll explore about detecting screen on and screen off in android devices. I got your mind, can use also by Broad cast Receivers. Yes, you can. But how do you know, if app goes offline and screen off. First write the Broad cast receiver class for receiving results. ScreenReceiver.Java -------------------------- import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ScreenReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {             screenOff = true;             Log.i("screenLog", "screen off");         } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {           ...

Print the large string values in android log cat.

Hi, Have a happy Monday. In Android, sometimes we need to print the large numbers of strings value in log. But log can't accept whole value of the string. In this case, we need to split the logs. It's very simple android code, I attached below this blog. public static void logLargeString(String TAG, String msg) {         if (str.length() > 3000) {             Log.i(TAG, msg.substring(0, 3000));             logLargeString(TAG, msg.substring(3000));         } else {             Log.i(TAG, msg);         } } Just use it and enjoy...

Backward and Forward Asterisks

Hi, Have a happy Sunday. Today I'm going to explain, how to deal with asterisks problems. Just before the day, I've been attend the interview. Question: To print out Asterisk (*) in system console in specific order. ***** **** *** ** * This is backward asterisks, I'm failed to do that, because of less time, no test cases and unfortunate system freezes. Yeah, this is not accept by recruiters. It's very simple problem, I know. Anyway 15 minutes passes by. No clues. I'm going to give the answer by two ways here now. 1. Backward Asterisks 2. Forward Asterisks Solution: public class Asterisks{     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         Scanner scan = new Scanner(System.in);         System.out.println("Enter the number of rows : ");     ...

Vending Machine Task - Java

Hi, Happy Weekends. Most boring thing is every time you've been asked same questions or you've been requested to do same tasks in different ways. I faced a lot. In IT field, It's happens for everyone at least one time. Don't be sad, It's a good practice and helpful. We can also prove our self to do same works in different ways, It's a kind of practice. It's a kind of strategy. In earlier times, Most of times in interview, I getting the calculator tasks in Android. Yeah, I do successfully in each time. Here I come to explain the Vending Machine Task in Java. I've asked for this task for three times in a row now, each time differently. What is Vending Machine? A vending machine is a machine that dispenses items such as snacks, beverages, alcohol, cigarettes, lottery tickets to customers automatically, after the customer inserts currency or credit into the machine. How it's works? Vending machine is having a different product items with dif...