public class PanicResponder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PREF_TRIGGER_PACKAGE_NAME |
Constructor and Description |
---|
PanicResponder() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkForDisconnectIntent(android.app.Activity activity)
Checks whether the provided
Activity was started with the action
Panic.ACTION_DISCONNECT , and if so, processes that Intent
, removing the sending app as the panic trigger if it is currently
configured to be so. |
static void |
configTriggerAppListPreference(android.preference.ListPreference listPreference,
int defaultSummaryResid,
int noneSummaryResid)
Given a
ListPreference widget, this method sets up that widget to
display the current state of the trigger app. |
static void |
deleteAllAppData(android.content.Context context) |
static java.lang.String |
getConnectIntentSender(android.app.Activity activity)
|
static java.lang.String |
getTriggerPackageName(android.content.Context context)
Get the
packageName of the currently configured panic trigger
app, or null if none. |
static boolean |
receivedTriggerFromConnectedApp(android.app.Activity activity)
Check whether the provided
Activity has received an Intent
that has an action of Panic.ACTION_TRIGGER and is from the
panic trigger app that is currently connected to this app. |
static java.util.List<android.content.pm.ResolveInfo> |
resolveTriggerApps(android.content.pm.PackageManager pm)
Get a list of resolved
Activity s that can send panic trigger
Intent s. |
static void |
setTriggerPackageName(android.app.Activity activity)
Set the currently configured panic trigger app using the
Activity
that received a Panic.ACTION_CONNECT Intent . |
static void |
setTriggerPackageName(android.app.Activity activity,
java.lang.String packageName)
Set the
packageName as the currently configured panic trigger
app. |
static boolean |
shouldUseDefaultResponseToTrigger(android.app.Activity activity)
Check whether the provided
Activity has received an Intent
that has an action of Panic.ACTION_TRIGGER and is not from the
currently configured panic trigger app, or, there is no panic trigger app
configured. |
public static final java.lang.String PREF_TRIGGER_PACKAGE_NAME
public static java.lang.String getConnectIntentSender(android.app.Activity activity)
Activity
to see whether it has received a
Panic.ACTION_CONNECT
Intent
. If it has, it returns the
package name of the app that sent it. Otherwise, it returns null
.
The sender is the only information used from the
ACTION_CONNECT Intent
.
The responder app should always respond to every
ACTION_CONNECT Intent
, even it is from the currently connected
trigger app. That trigger app could have been uninstalled and
reinstalled, so it needs to receive the confirmation again.
WARNING: If the Activity
has
android:launchMode="singleInstance"
or "singleTask"
, then
this method will always return false
because it is not possible
to get the calling Activity
, as set by
Activity.startActivityForResult(Intent, int)
activity
- the Activity
that received the Intent
null
if it was not a
ACTION_CONNECT Intent
or the Intent
was not sent
with Activity.startActivityForResult(Intent, int)
checkForDisconnectIntent(Activity)
public static boolean checkForDisconnectIntent(android.app.Activity activity)
Activity
was started with the action
Panic.ACTION_DISCONNECT
, and if so, processes that Intent
, removing the sending app as the panic trigger if it is currently
configured to be so.
WARNING: If the Activity
has
android:launchMode="singleInstance"
or "singleTask"
, then
this method will not disconnect because it is not possible to get the
calling Activity
, as set by
Activity.startActivityForResult(Intent, int)
activity
- the Activity
to check for the Intent
ACTION_DISCONNECT Intent
was receivedgetConnectIntentSender(Activity)
public static java.lang.String getTriggerPackageName(android.content.Context context)
packageName
of the currently configured panic trigger
app, or null
if none.context
- the app's Context
packageName
or nullpublic static void setTriggerPackageName(android.app.Activity activity)
Activity
that received a Panic.ACTION_CONNECT
Intent
. If that
Intent
was not set with either
Activity.startActivityForResult(Intent, int)
or
Intent.setPackage(String)
, then this will result in no panic
trigger app being active.
When the user changes the panic app config, then the current app needs to
send Intent
s to the previous app, and the currently configured
app to let them know about the changes. This is done by sending an
ACTION_DISCONNECT Intent
to the previous app, and an
ACTION_CONNECT Intent
to the newly configured app.
When this is called with an Activity
in the same responder app
that called the Activity.startActivityForResult(Intent, int)
,
then it will not change the existing trigger app setting! For
example, if the responder app launches its Panic Config Activity
.
activity
- the Activity
that received an
Panic.ACTION_CONNECT
Intent
public static void setTriggerPackageName(android.app.Activity activity, java.lang.String packageName)
packageName
as the currently configured panic trigger
app. Set to null
to have no panic trigger app active.
When the user changes the panic app config, then the current app needs to
send Intent
s to the previous app, and the currently configured
app to let them know about the changes. This is done by sending an
ACTION_DISCONNECT Intent
to the previous app, and an
ACTION_CONNECT Intent
to the newly configured app.
activity
- the current Activity
packageName
- the app to set as the panic triggerpublic static java.util.List<android.content.pm.ResolveInfo> resolveTriggerApps(android.content.pm.PackageManager pm)
Activity
s that can send panic trigger
Intent
s.pm
- a PackageManager
instance from the app's Context
List
of ResolveInfo
instances for each app that
responds to Panic.ACTION_CONNECT
but not Panic.ACTION_TRIGGER
public static boolean receivedTriggerFromConnectedApp(android.app.Activity activity)
Activity
has received an Intent
that has an action of Panic.ACTION_TRIGGER
and is from the
panic trigger app that is currently connected to this app.
WARNING: If the Activity
has
android:launchMode="singleInstance"
or "singleTask"
, then
this method will always return false
because it is not possible
to get the calling Activity
, as set by
Activity.startActivityForResult(Intent, int)
activity
- the Activity
to get for an Intent
public static boolean shouldUseDefaultResponseToTrigger(android.app.Activity activity)
Activity
has received an Intent
that has an action of Panic.ACTION_TRIGGER
and is not from the
currently configured panic trigger app, or, there is no panic trigger app
configured.activity
- the Activity
to get for an Intent
public static void configTriggerAppListPreference(android.preference.ListPreference listPreference, int defaultSummaryResid, int noneSummaryResid)
ListPreference
widget, this method sets up that widget to
display the current state of the trigger app. If a trigger app is
connected, then the icon and name of that app will be shown.listPreference
- the UI widget to display the current statedefaultSummaryResid
- the string resource for the default summarynoneSummaryResid
- the string resource for the summary when no app is allowedpublic static void deleteAllAppData(android.content.Context context)