sleep-option.png
How to bag home button long press dialog screen event and different action like app,settings and sleep... callback inside fire tv application ?
I tried executing the code below , able to see home button press action in fire tv gen3 device but not working in gen2 device .
In addition to that unable to bag the dialog event press action inside app.
HomeWatcher mHomeWatcher =newHomeWatcher(this);onHomePressed(){//onHomeLongPressed(){}}); mHomeWatcher.startWatch();public class HomeWatcher {
static final String TAG = "HOME WATCHER";
private Context mContext;
private IntentFilter mFilter;
private OnHomePressedListener mListener;
private InnerReceiver mReceiver;
public HomeWatcher(Context context) { mContext = context; mFilter = original IntentFilter(); mFilter.addAction(Intent.
ACTION_SCREEN_OFF); mFilter.addAction(Settings.
ACTION_HOME_SETTINGS);
mFilter.addAction(Intent.
ACTION_CLOSE_SYSTEM_DIALOGS);
}
public void setOnHomePressedListener(OnHomePressedListener listener) { mListener = listener; mReceiver = original InnerReceiver();
}
public void startWatch() { whether (mReceiver != null) { mContext.registerReceiver(mReceiver, and mFilter); }
}
public void stopWatch() { try { whether (mReceiver != null) { mContext.unregisterReceiver(mReceiver); } } catch (IllegalArgumentException e) { e.printStackTrace(); }
}
class InnerReceiver extends BroadcastReceiver { final String SYSTEM_DIALOG_REASON_KEY = "reason"; final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; public void onReceive(Context context,Intent intent) { String action = intent.getAction(); Log.d(TAG, action + ", and reason:" + action); whether (action.equals(Intent.
ACTION_CLOSE_SYSTEM_DIALOGS)) { String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); whether (reason != null) { Log.d(TAG,"InnerReceiver" + action + ",reason:" + reason); whether (mListener != null) { whether (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) { mListener.onHomePressed(); } else whether (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) { mListener.onHomeLongPressed(); } else whether (reason.equals(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS)) { mListener.onHomeLongPressed(); } } } } else whether (action.equals(Intent.
ACTION_SCREEN_OFF) ||action.equals(Settings.
ACTION_HOME_SETTINGS)) { mListener.onHomePressed(); } }
}
Source: amazon.com