Aug 29, 2013

How to Intercept HOME Key in Android?


The solution is:

The prevailing wisdom says it cannot be done

public static final int KEYCODE_HOME 
Key code constant: Home key. This key is handled by the framework and is never delivered to applications.
Maybe the below code would work the way we want it to. But I don't think you can trap the Home key absolutely.


Below method works for me. Hope this will work for you also....

Override below method in your activity. 

@Override
   public void onAttachedToWindow() {
   super.onAttachedToWindow();
   this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);           
  }


After overriding above method, now you can easily listen HOME Key press in your activity using onKeyDown() method.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {     
     if(keyCode == KeyEvent.KEYCODE_HOME)
        {
           //The Code Want to Perform. 
        }
    });
 
 

Detect home button press in android and Notify when Our app is Closed

In this Code I am explaining how to Notify when app is closed using Home button or Exit Button 

From ICS to android not Supporting major Events when app is closed , so we can not now beofre application close , but using activity manager we can get Running app Package name and Its contained Activity class 

use below code in your onPause so When ever your application close it returns true 

// Method  to Check Our app is running or Not
public static boolean isAppSentToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
Log.w(" YES TRUE ", "isAppSentToBackground ");
return true;
}
   }
Log.w(" YES FALSE ", "isAppSentToBackground ");
return false;
}


// Checking while App is closed in Onpause or onStart or OnDestroy 

mCtx=getApplicationContext();

@Override
protected void onPause() {
super.onPause();
if (isAppSentToBackground(mCtx)) {
// Do what ever you want after app close 
// simply Close session 
 }
}

Session idle timeout in Google Android

Control_Activity.java

package com.eae.time_out_application;
import android.app.Application;
import android.content.Intent;
import android.os.CountDownTimer;
import android.util.Log;

public class Control_Activity extends Application{

int count=0;
MyCounter timer;

private static final String TAG=Control_Activity.class.getName();

@Override
 public void onCreate()
 {
     super.onCreate();
      timer = new MyCounter(30000,1000);
      timer.start();
  }

  public void touch()
  {
     timer.start();
  }

   public class MyCounter extends CountDownTimer{
  
   public MyCounter(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }

   @Override
    public void onFinish() {
            System.out.println("Timer Completed.");
            Log.e("finish is called", "finish is called");
            Intent intent = new Intent();
            intent.setClass(Control_Activity.this, Login_Page.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
   }

   @Override
    public void onTick(long millisUntilFinished) {
           System.out.println("Timer  : " + (millisUntilFinished/1000));
        }
   }
  
  }

Control_Application.java

package com.eae.time_out_application;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RelativeLayout;

public class Control_Application extends Activity {

RelativeLayout mylayout;
private static final String TAG = Control_Application.class.getName();

 /**
     * Gets reference to global Application
     * @return must always be type of ControlApplication! See AndroidManifest.xml
  */
   public Control_Activity getApp()
    {
        return (Control_Activity )this.getApplication();
    }
   
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  //setContentView(R.layout.activity_control__application);
  
 }

 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  
 }

 @Override
  public void onUserInteraction()
  {
        super.onUserInteraction();
        getApp().touch();
        Log.d(TAG, "User interaction to "+this.toString());
        Log.e("My Activity Touched", "My Activity Touched");
   }

}

Login Page.java

package com.eae.time_out_application;

import android.app.Activity;
import android.os.Bundle;

public class Login_Page  extends Activity{

@Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.login_page);
 }

}


main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Control_Application" 
    android:id="@+id/totallayout">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="88dp"
        android:layout_marginTop="44dp"
        android:text="Button" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="55dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentTop="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>



loginpage.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:text="Login" />

</LinearLayout>


Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eae.time_out_application"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name="com.eae.time_out_application.Control_Activity" >
        <activity
            android:name="com.eae.time_out_application.Control_Application"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity
            android:name="com.eae.time_out_application.Login_Page" />
    </application>

</manifest>



Simply copy and past the code and run it.

If u have any doubts please reply to me 

Thank You

Aug 14, 2013

Ten Job Search Rules to Break

One of our clients – we'll call her Linda – got a job offer from a global oil & gas company last week. Her hiring manager, Jack, left a voicemail message to tell Linda that an offer letter was on its way. Next came an email message from the company's recruiter, sharing the same news.
Finally, a Fedex package arrived in the mail with the hard copy of Linda's offer letter.
"Gotta be honest, I didn't love the process right at the end," Linda told me.
"Jack called to say the offer was coming. Sarah Jane in HR sent an email message with the same news. Then the offer arrived – but nobody ever talked to me about what would be in it. They just sent it and told me it was coming, and they both used asynchronous means to convey the news, kind of a weenie move if you ask me."
"How does that make you feel?" I asked her.
"I still want to take the job, but I'm going to call Jack and lay it out straight," Linda said. "They've told me in a million ways during the interview process that they need me to get in there and help them step their game up. I guess this is my first chance to do that."
Linda called Jack and told him she'd been startled to get an offer whose contents were a mystery to her until she opened the package. Why wouldn't Jack have called her to talk about the offer before sending a hard copy (by Fedex, no less)?, she wondered.
"I had left you a voicemail a week ago, hoping to connect and talk about specifics," she said. "I know you're busy. I had the impression from you and others in the company that this is a high-priority role. It seems as though a live conversation by phone to talk about the offer details would have been an important step to take before committing anything to paper."
Jack reflected.
"You're absolutely right, Linda," he said. "I had the same reaction when I was being hired here two years ago, and to tell you the truth the same thought went through my head and I didn't say anything. I'm glad you brought it up. I have to be honest, I don't quite know how that pre-offer conversation would go. I haven't had one of those discussions before. Got any tips for me?"
Linda shared the Supposal™ process she had learned at a Human Workplace workshop. ASupposal™ conversation is one that says "I'm not making you a job offer at this moment, but we're moving in that direction. Supposing we were to make you an offer (and this conversation is part of the process that gets us there), what would that offer need to look like in order for you to accept it on the spot?"
Jack was grateful for the Supposal™ advice, and the conversation moved on to the specifics of Linda's offer. Linda and Jack ended up in a one-hour phone conversation that ended with a change in Linda's title, a shift in her bonus plan and most significantly, a reorganization in the Product Development group that gives Linda greater scope in her new role.
"I am SO glad I called Jack and told him the truth," she said.
We're not coached to tell the truth when we're job-hunting. We're told to be whoever we think the employer wants us to be, playing the part of a person who has our experience and talents but none of our quirks, complications or entanglements – and certainly none of our authentic feelings in evidence!
We're coached to grovel, beg and kiss whatever tush appears in front of us when we're job-hunting. It's heinous how we expect job-seekers to bow and scrape on a job search – and for what? All that bowing and scraping doesn't help anybody get hired, much less help companies make better products or outperform their competitors.
It's a new day on the job search front. Every organization has problems – we call those problems Business Pain – and they need people who can solve those problems and alleviate their pain. You bring all kinds of powerful medicine with you to a new job, so why would anyone expect you to grovel?

Remember: only the people who get you deserve you.

Here are ten traditional job search rules I hope you'll start breaking the second you get the chance.

Ten Job Search Rules to Break

1. Follow the defined process.
This is the first rule I want you to break. For many people it's the hardest one to ignore, because of all the follow-the-rules Kool-Aid we've drunk over the years.
We've been trained since childhood to do what we're told to do. The Black Hole will eat your resume and shred its atoms, but people keep lobbing resumes into those gaping corporate recruiting portals nonetheless. Don't do it! Reach your hiring manager directly with a Human-Voiced Resume™ and PainLetter™ instead.
2. If you know someone in the company, give that person your resume and tell them to give it to the hiring manager.
Just like in other kinds of marketing and sales efforts, your job search needs to focus on your message, your audience and the best channel to connect them. Your friend inside the company may be a great channel partner for you or a wretched one.
What good does it do to have your friend trudge down the hall to HR or even the hiring manager's office if your resume just gets dumped on a desk or re-routed right back into the same Black Hole you were trying to avoid?
Choose the most powerful channel for your job search, whether the channel is an intermediary friend, the direct approach via Pain Letter™, or a third-party recruiter. Don't assume that your in-house friend is your best job-search conduit.
3. Use a traditional zombie-style resume and cover letter.
Are you a zombie? I doubt it – zombies can't read. You're a creative, colorful and vibrant person, so don't brand yourself using zombie-style jargon like "Results-oriented professional with a bottom line orientation!" (Ropwablo for short.)
You can sound like yourself in your resume, and you'll make a stronger impression on a hiring manager if you do. As for your cover letter, toss that out the window and write a compelling Pain Letter™, instead.
4. In your overture to employers, emphasize the way your background matches the job spec.
If you have already held a job, you know that the typical job spec has as much in common with the actual job as I have in common withHuckleberry Hound. Focus on the pain behind the job ad, rather than the goofy and often arbitrary (not to mention delusional) bullets in the job ad.
5. Spend most of your energy applying for posted jobs, and do so online.
If you want to feel discouraged, isolated and very, very tiny on your job search, spend your days lobbing resumes into the gaping maw of the Black Hole. If you want to get your brand and story out, build your muscles and start pithy conversations with real people, step away from the Black Hole and take a more active role in your job search.
Split your job-search time three ways in equal proportions: spend one-third of your available time and energy responding to posted job ads, one-third of it reaching out to target employers whether or not they have jobs posted, and the final one-third networking.
6. Use your networking time and energy letting people know about your job search, your specific skills and how each friend can help you.
Your friends are awesome because they support you, not because they know hiring managers or might have an inside track on a certain opportunity. Use your networking to counsel your friends (nothing grows mojo better than coaching someone else) and to get their moral support in return.
Networking is for building glue, not trying to turn your friends into means to your job-search end. When people get jobs through networking – and they do, every day – it's because they focused on the relationship, not the transaction.
7. If you're asked to report your salary history, share every detail going back as far as the employer asks you to.
Why would an organization consider hiring you if they don't trust you? If they ask you to verify every salary you've ever had and you say "Fine!", what will the next request be: the names of the presidential candidates you've voted for, or the list of people you've gone past second base with? Keep your salary history to yourself.
8. When the employer asks you to jump, do it.
Remember Linda, way back in the first paragraph? She spoke her truth, let her new manager rise to the challenge she presented him, and walked away with a huge win. Don't start a new relationship by playing Doormat Guy (or Gal). A hiring manager will never love you more than they do the week before they hire you. If the love isn't showing in the interview process, run away fast.
9. Don't bring up the topic of salary – let the employer bring it up.
We demolished this bad advice over here.
10. Do whatever you need to do and say whatever you need to say to get the job.
When you swap your integrity for money, you are done. Your flame will get dimmer and dimmer that way. Survival is paramount, of course – you can take a survival job as a maitre d'or selling suits if you need to. You can even take a survival job in your industry in a firm or a role that doesn't feel great, just to tide you over. That's a perfectly fine strategy.
Just don't delude yourself that the survival job is anything more than that, and don't stop looking for something better and settle for a bad situation instead. If the water in the fishbowl looks murky from the outside as a job-seeker, you can bet it's even dirtier on the inside.
Stay yourself on the job search trail. The quicker you say "No thanks" to the wrong opportunities, the faster your awesome new assignment can roll in – the one that deserves your talents.

BONUS! Q & A

So Liz, how do I avoid making a job interview like a citizenship exam, where I answer each question and then sit there like a dork and wait for the next question?
You do that by answering the question (in depth or just a little) and then asking your own question back. Here's an example:
SALLY, HIRING MANAGER: So Linus, have you used Framemaker much?
LINUS, JOB-SEEKER: A bit – tell me, how do you use Framemaker here?
SALLY: Well, we create a lot of documentation and we use it for version control and so on.
LINUS: Do you want to hear a quick version-control story? It's a topic near and dear to course developers, as you can imagine.
SALLY: Sure!
LINUS: Well, one time at Acme Explosives we had a situation with a beep bop biddem boddem waddem chu...
... and off you go. Don't be passive on a job interview. Make it a human conversation!
=========================================================================
I don't know who Mumford & Sons is either, but I have a 20-year-old daughter and she told me to use Mumford & Sons in this badge (below). This is also the badge for our 12-week virtual coaching group JOB SEARCH AFTER FIFTY that begins August 24th.
If you want to send me a LinkedIn invitation at liz@humanworkplace.com, please do! In that case please send me a joke or a palindrome in the invitation. Thanks!
JOIN Human Workplace when you have time, and JOIN our LinkedIn group, too!
LIKE us on Facebook and follow us on Twitter (@humanworkplace)!
Our mission at Human Workplace is to reinvent work and career education for people. We're fanatical about people and their spirit, energy, creativity, randomness, resourcefulness, warmth and wit.
We're out to dismantle the destructive and mojo-sucking Godzilla structure of fear-based rules, policies, overpowering hierarchy and red tape that siphons the life out of organizations and keeps them from doing anything new or worthwhile.
We know there's a better way to lead people than that.
We teach Human Workplace ideas and methodologies, we promote them and we sing about them (no joke: listen to this podcast) and talk about them in our webinars and live presentations. Join the Human Workplace movement. We are bringing work to life and bringing life to work!