Skip to content

Instantly share code, notes, and snippets.

@neiraza
Created February 12, 2014 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neiraza/8951303 to your computer and use it in GitHub Desktop.
Save neiraza/8951303 to your computer and use it in GitHub Desktop.
ホームボタンをタップした際のイベントを取得しちゃる
public class HomeButtonReceiverActivity extends Activity {
private HomeButtonReceiver mHomeButtonReceiver;
private IntentFilter mIntentFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO ホームボタン押された時の Receiver の登録
mHomeButtonReceiver = new HomeButtonReceiver();
mIntentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
}
@Override
public void onResume() {
super.onResume();
//TODO ホームボタン押された時の Receiver の登録
this.registerReceiver(mHomeButtonReceiver, mIntentFilter);
}
//TODO
private class HomeButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "ホームボタンが押されました", Toast.LENGTH_LONG).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment