aboutsummaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rw-r--r--admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java b/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java
index 3f4cea01..8d219656 100644
--- a/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java
+++ b/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java
@@ -16,7 +16,10 @@
package com.example.android.apprestrictionschema;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.RestrictionEntry;
import android.content.RestrictionsManager;
import android.os.Build;
@@ -44,7 +47,7 @@ import java.util.List;
public class AppRestrictionSchemaFragment extends Fragment implements View.OnClickListener {
// Tag for the logger
- private static final String TAG = "AppRestrictionSchemaFragment";
+ private static final String TAG = "AppRestrictionSchema";
private static final String KEY_CAN_SAY_HELLO = "can_say_hello";
private static final String KEY_MESSAGE = "message";
@@ -60,6 +63,9 @@ public class AppRestrictionSchemaFragment extends Fragment implements View.OnCli
// Message to show when the button is clicked (String restriction)
private String mMessage;
+ // Observes restriction changes
+ private BroadcastReceiver mBroadcastReceiver;
+
// UI Components
private TextView mTextSayHello;
private Button mButtonSayHello;
@@ -96,6 +102,28 @@ public class AppRestrictionSchemaFragment extends Fragment implements View.OnCli
resolveRestrictions();
}
+ @Override
+ public void onStart() {
+ super.onStart();
+ mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ resolveRestrictions();
+ }
+ };
+ getActivity().registerReceiver(mBroadcastReceiver,
+ new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED));
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ if (mBroadcastReceiver != null) {
+ getActivity().unregisterReceiver(mBroadcastReceiver);
+ mBroadcastReceiver = null;
+ }
+ }
+
private void resolveRestrictions() {
RestrictionsManager manager =
(RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE);