Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:com.bt.heliniumstudentapp.UpdateClass.java

protected static void downloadAPK() {
    File oldUpdate = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS
            + "/heliniumstudentapp.apk");
    if (oldUpdate.exists()) //noinspection ResultOfMethodCallIgnored
        oldUpdate.delete();// ww  w. ja  v a 2s . c o  m

    if (MainActivity.isOnline()) {
        DownloadManager.Request request;

        request = new DownloadManager.Request(Uri.parse(HeliniumStudentApp.URL_UPDATE_RELEASE));

        request.setTitle(context.getString(R.string.app_name) + " " + versionName);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/heliniumstudentapp.apk");

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);

        context.registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                final Intent install = new Intent(Intent.ACTION_VIEW);
                install.setDataAndType(
                        Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/"
                                + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk")),
                        "application/vnd.android.package-archive");
                context.startActivity(install);
            }
        }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    } else {
        Toast.makeText(context, R.string.error_conn_no, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.ContactActivity.java

private void registerBroadcastReceiver() {
    broadcastManager = LocalBroadcastManager.getInstance(this);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constant.ACTION_CONTACT_CHANAGED);
    intentFilter.addAction(Constant.ACTION_GROUP_CHANAGED);
    //      intentFilter.addAction(RPConstant.REFRESH_GROUP_RED_PACKET_ACTION);
    broadcastReceiver = new BroadcastReceiver() {

        @Override/* www . ja v  a 2s.  c o m*/
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            updateUnreadAddressLable();
            if (currentTabIndex == 0) {
                // refresh conversation list
            } else if (currentTabIndex == 1) {
                if (contactListFragment != null) {
                    contactListFragment.refresh();
                }
            }
            String action = intent.getAction();
            if (action.equals(Constant.ACTION_GROUP_CHANAGED)) {
                if (EaseCommonUtils.getTopActivity(ContactActivity.this)
                        .equals(GroupsActivity.class.getName())) {
                    GroupsActivity.instance.onResume();
                }
            }

            if (action.equals(Constant.ACTION_CONTACT_CHANAGED)) {

            }
        }
    };
    broadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:com.zentri.otademo.ConnectActivity.java

private void initBroadcastReceiver() {
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override//www .ja va 2s . c om
        public void onReceive(Context context, Intent intent) {
            if (intent == null) {
                Log.e(TAG, "Received null intent!");
                return;
            }

            String action = intent.getAction();

            Log.d(TAG, "Received event " + action);
            switch (action) {
            case ZentriOSBLEService.ACTION_CONNECTED:
                dismissConnectingDialog();
                startOTAActivity();
                break;

            case ZentriOSBLEService.ACTION_DISCONNECTED:

                break;

            case ZentriOSBLEService.ACTION_SCAN_RESULT:
                //add result to list
                addToList(intent.getStringExtra(ZentriOSBLEService.EXTRA_NAME));
                break;

            case ZentriOSBLEService.ACTION_ERROR:
                //show error dialog
                break;
            }
        }
    };
}

From source file:com.evandroid.musica.fragment.LyricsViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);/*from   ww w  . j  av a  2 s  .c om*/
    setHasOptionsMenu(true);
    View layout = inflater.inflate(R.layout.lyrics_view, container, false);
    if (savedInstanceState != null)
        try {
            Lyrics l = Lyrics.fromBytes(savedInstanceState.getByteArray("lyrics"));
            if (l != null)
                this.mLyrics = l;
            mSearchQuery = savedInstanceState.getString("searchQuery");
            mSearchFocused = savedInstanceState.getBoolean("searchFocused");
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    else {
        Bundle args = getArguments();
        if (args != null)
            try {
                Lyrics lyrics = Lyrics.fromBytes(args.getByteArray("lyrics"));
                this.mLyrics = lyrics;
                if (lyrics != null && lyrics.getText() == null && lyrics.getArtist() != null) {
                    String artist = lyrics.getArtist();
                    String track = lyrics.getTrack();
                    String url = lyrics.getURL();
                    fetchLyrics(artist, track, url);
                    mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
                    startRefreshAnimation();
                }
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
    }
    if (layout != null) {
        Bundle args = savedInstanceState != null ? savedInstanceState : getArguments();

        boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity())
                .getBoolean("pref_force_screen_on", false);

        TextSwitcher textSwitcher = (TextSwitcher) layout.findViewById(R.id.switcher);
        textSwitcher.setFactory(new LyricsTextFactory(layout.getContext()));
        ActionMode.Callback callback = new CustomSelectionCallback(getActivity());
        ((TextView) textSwitcher.getChildAt(0)).setCustomSelectionActionModeCallback(callback);
        ((TextView) textSwitcher.getChildAt(1)).setCustomSelectionActionModeCallback(callback);
        textSwitcher.setKeepScreenOn(screenOn);
        layout.findViewById(R.id.lrc_view).setKeepScreenOn(screenOn);

        TextView id3TV = (TextView) layout.findViewById(R.id.id3_tv);
        SpannableString text = new SpannableString(id3TV.getText());
        text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0);
        id3TV.setText(text);

        final RefreshIcon refreshFab = (RefreshIcon) getActivity().findViewById(R.id.refresh_fab);
        refreshFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mRefreshLayout.isRefreshing())
                    fetchCurrentLyrics(true);
            }
        });

        FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
                startActivity(settingsIntent);
            }
        });

        if (args != null)
            refreshFab.setEnabled(args.getBoolean("refreshFabEnabled", true));

        mScrollView = (NestedScrollView) layout.findViewById(R.id.scrollview);
        mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
        TypedValue primaryColor = new TypedValue();
        getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
        mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, R.color.accent);
        float offset = getResources().getDisplayMetrics().density * 64;
        mRefreshLayout.setProgressViewEndTarget(true, (int) offset);
        mRefreshLayout.setOnRefreshListener(this);

        if (mLyrics == null) {
            if (!startEmtpy)
                fetchCurrentLyrics(false);
        } else if (mLyrics.getFlag() == Lyrics.SEARCH_ITEM) {
            mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
            startRefreshAnimation();
            if (mLyrics.getArtist() != null)
                fetchLyrics(mLyrics.getArtist(), mLyrics.getTrack());
        } else //Rotation, resume
            update(mLyrics, layout, false);
    }
    if (broadcastReceiver == null)
        broadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                searchResultLock = false;
                String artist = intent.getStringExtra("artist");
                String track = intent.getStringExtra("track");
                if (artist != null && track != null && mRefreshLayout.isEnabled()) {
                    startRefreshAnimation();
                    new ParseTask(LyricsViewFragment.this, false, true).execute(mLyrics);
                }
            }
        };
    return layout;
}

From source file:com.hsd.fsxasm.chat.activity.Jstx_MainActivity.java

private void registerBroadcastReceiver() {
    broadcastManager = LocalBroadcastManager.getInstance(this);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constant.ACTION_CONTACT_CHANAGED);
    intentFilter.addAction(Constant.ACTION_GROUP_CHANAGED);
    broadcastReceiver = new BroadcastReceiver() {

        @Override// w  ww .  j  a v  a  2s  .com
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            updateUnreadAddressLable();
            if (currentTabIndex == 0) {
                // ??????
                if (conversationListFragment != null) {
                    conversationListFragment.refresh();
                }
            } else if (currentTabIndex == 1) {
                if (contactListFragment != null) {
                    contactListFragment.refresh();
                }
            }
            String action = intent.getAction();
            if (action.equals(Constant.ACTION_GROUP_CHANAGED)) {
                if (EaseCommonUtils.getTopActivity(Jstx_MainActivity.this)
                        .equals(GroupsActivity.class.getName())) {
                    GroupsActivity.instance.onResume();
                }
            }
        }
    };
    broadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

/**
 * Register an SMS Data (Binary) Receiver
 *///w w w .j a v a  2  s  . c  om
private void registerSmsReceiver() {
    smsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Debug.i("Received Binary SMS");

            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;

            if (null != bundle) {
                // In telecommunications the term (PDU) means protocol data
                // unit.
                // There are two ways of sending and receiving SMS messages:
                // by text mode and by PDU (protocol description unit) mode.
                // The PDU string contains not only the message, but also a
                // lot of meta-information about the sender, his SMS service
                // center, the time stamp etc
                // It is all in the form of hexa-decimal octets or decimal
                // semi-octets.
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];

                for (int i = 0; i < msgs.length; i++) {
                    // Create the Message
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    // Get Message Parameters
                    SmsObject receivedSms = new SmsObject();
                    receivedSms.setTelephoneNumber(msgs[i].getOriginatingAddress());
                    receivedSms.setMessageTimestamp(msgs[i].getTimestampMillis());
                    receivedSms.setMessageData(Base64.encodeToString(msgs[i].getUserData(), Base64.CRLF));

                    Debug.d("Received SMS and it's content hash is: " + BinaryHelpers
                            .toHexadecimealString(Hashing.getMD5Hash(msgs[i].getUserData()).toByteArray()));

                    // Store the SmsObject to the db
                    dao.storeSms(receivedSms);
                }
            }

            // This will stop the Broadcast and not allow the message to
            // be interpreted by the default Android app or other apps
            abortBroadcast();
        }
    };

    // Set up the Receiver Parameters
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.setPriority(999);
    mIntentFilter.addAction("android.intent.action.DATA_SMS_RECEIVED");
    mIntentFilter.addDataScheme("sms");
    // Set the Port that is listening to
    mIntentFilter.addDataAuthority("*", "2013");
    // mIntentFilter.addDataType(type)
    registerReceiver(smsReceiver, mIntentFilter);
    Debug.d("Set up BinarySMS receiver.");
}

From source file:com.klinker.android.twitter.ui.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MainActivity.sendHandler = new Handler();

    context = this;
    sContext = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    DrawerActivity.settings = AppSettings.getInstance(context);

    try {//from   w w w .  j  a  va 2  s .co m
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    } catch (Exception e) {

    }

    sharedPrefs.edit().putBoolean("refresh_me", getIntent().getBooleanExtra("from_notification", false))
            .commit();

    setUpTheme();
    setUpWindow();
    setContentView(R.layout.main_activity);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    setUpDrawer(0, getResources().getString(R.string.timeline));

    MainActivity.sendLayout = (LinearLayout) findViewById(R.id.send_layout);
    MainActivity.sendHandler.postDelayed(showSend, 1000);
    MainActivity.sendButton = (ImageButton) findViewById(R.id.send_button);
    MainActivity.sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent compose = new Intent(context, ComposeActivity.class);
            startActivity(compose);
        }
    });

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.timeline));

    if (!settings.isTwitterLoggedIn) {
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    } /*else if (!sharedPrefs.getBoolean("setup_v_two", false) && !PreferenceManager.getDefaultSharedPreferences(context).getBoolean("setup_v_two", false)) {
      Intent setupV2 = new Intent(context, Version2Setup.class);
      startActivity(setupV2);
      }*/

    mSectionsPagerAdapter = new TimelinePagerAdapter(getFragmentManager(), context, sharedPrefs,
            getIntent().getBooleanExtra("from_launcher", false));

    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPager.setCurrentItem(mSectionsPagerAdapter.getCount() - 3);

    if (getIntent().getBooleanExtra("from_launcher", false)) {
        actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(getIntent().getIntExtra("launcher_page", 0)));
    }

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (!actionBar.isShowing()) {
                actionBar.show();

                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
            MainActivity.sendHandler.post(showSend);
        }

        public void onPageSelected(int position) {

            String title = "" + mSectionsPagerAdapter.getPageTitle(position);

            if (title.equals(getResources().getString(R.string.mentions))) {
                MainDrawerArrayAdapter.current = 1;
            } else if (title.equals(getResources().getString(R.string.direct_messages))) {
                MainDrawerArrayAdapter.current = 2;
            } else if (title.equals(getResources().getString(R.string.timeline))) {
                MainDrawerArrayAdapter.current = 0;
            } else {
                MainDrawerArrayAdapter.current = -1;
            }

            drawerList.invalidateViews();

            actionBar.setTitle(title);
        }
    });

    mViewPager.setOffscreenPageLimit(4);

    if (getIntent().getBooleanExtra("tutorial", false) && !sharedPrefs.getBoolean("done_tutorial", false)) {
        getIntent().putExtra("tutorial", false);
        sharedPrefs.edit().putBoolean("done_tutorial", true).commit();
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "close drawer");
                    mDrawerLayout.closeDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_CLOSE_DRAWER));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "open drawer");
                    mDrawerLayout.openDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_OPEN_DRAWER));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page left");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_LEFT));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page right");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_RIGHT));

        startActivity(new Intent(context, TutorialActivity.class));
        overridePendingTransition(0, 0);
    }

    setLauncherPage();

    if (getIntent().getBooleanExtra("from_drawer", false)) {
        mViewPager.setCurrentItem(getIntent().getIntExtra("page_to_open", 3));
    }
}

From source file:eu.power_switch.gui.fragment.BackupFragment.java

@Override
public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_backup, container, false);
    setHasOptionsMenu(true);//from  w ww  .ja v  a2 s. c o m

    final RecyclerViewFragment recyclerViewFragment = this;

    textViewBackupPath = (TextView) rootView.findViewById(R.id.textView_backupPath);
    textViewBackupPath.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!PermissionHelper.isWriteExternalStoragePermissionAvailable(getContext())) {
                new AlertDialog.Builder(getContext()).setTitle(R.string.missing_permission)
                        .setMessage(R.string.missing_external_storage_permission)
                        .setNeutralButton(R.string.close, null).show();
                return;
            }

            PathChooserDialog pathChooserDialog = PathChooserDialog.newInstance();
            pathChooserDialog.setTargetFragment(recyclerViewFragment, 0);
            pathChooserDialog.show(getActivity().getSupportFragmentManager(), null);
        }
    });

    recyclerViewBackups = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    backupArrayAdapter = new BackupRecyclerViewAdapter(this, getActivity(), backups);
    backupArrayAdapter.setOnItemClickListener(new BackupRecyclerViewAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View itemView, int position) {
            final Backup backup = backups.get(position);

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setPositiveButton(getActivity().getString(R.string.restore),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                BackupHandler backupHandler = new BackupHandler(getActivity());
                                backupHandler.restoreBackup(backup.getName());

                                DeveloperPreferencesHandler.forceRefresh();
                                SmartphonePreferencesHandler.forceRefresh(getContext());
                                WearablePreferencesHandler.forceRefresh(getContext());

                                // restart app to apply
                                getActivity().finish();
                                Intent intent = new Intent(getContext(), MainActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                            } catch (BackupNotFoundException e) {
                                Log.e(e);
                                StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(),
                                        R.string.backup_not_found, Snackbar.LENGTH_LONG);
                            } catch (Exception e) {
                                StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(),
                                        e);
                            }
                        }
                    }).setNeutralButton(getActivity().getString(android.R.string.cancel), null)
                    .setTitle(getActivity().getString(R.string.are_you_sure))
                    .setMessage(R.string.restore_backup_message);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
    backupArrayAdapter.setOnItemLongClickListener(new BackupRecyclerViewAdapter.OnItemLongClickListener() {
        @Override
        public void onItemLongClick(View itemView, int position) {
            final Backup backup = backups.get(position);

            EditBackupDialog editBackupDialog = EditBackupDialog.newInstance(backup.getName());
            editBackupDialog.setTargetFragment(recyclerViewFragment, 0);
            editBackupDialog.show(getActivity().getSupportFragmentManager(), null);
        }
    });
    recyclerViewBackups.setAdapter(backupArrayAdapter);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(),
            StaggeredGridLayoutManager.VERTICAL);
    recyclerViewBackups.setLayoutManager(layoutManager);

    fab = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    fab.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!PermissionHelper.isWriteExternalStoragePermissionAvailable(getContext())) {
                new AlertDialog.Builder(getContext()).setTitle(R.string.missing_permission)
                        .setMessage(R.string.missing_external_storage_permission)
                        .setNeutralButton(R.string.close, null).show();
                return;
            }

            CreateBackupDialog createBackupDialog = new CreateBackupDialog();
            createBackupDialog.setTargetFragment(recyclerViewFragment, 0);
            createBackupDialog.show(getFragmentManager(), null);
        }
    });

    // BroadcastReceiver to get notifications from background service if data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("BackupFragment", "received intent: " + intent.getAction());

            switch (intent.getAction()) {
            case LocalBroadcastConstants.INTENT_PERMISSION_CHANGED:
                int permissionRequestCode = intent.getIntExtra(PermissionConstants.KEY_REQUEST_CODE, 0);
                int[] results = intent.getIntArrayExtra(PermissionConstants.KEY_RESULTS);

                if (permissionRequestCode == PermissionConstants.REQUEST_CODE_STORAGE_PERMISSION) {
                    if (results[0] == PackageManager.PERMISSION_GRANTED) {
                        // Permission Granted
                        updateListContent();
                        StatusMessageHandler.showInfoMessage(getRecyclerView(), R.string.permission_granted,
                                Snackbar.LENGTH_SHORT);
                    } else {
                        // Permission Denied
                        StatusMessageHandler.showPermissionMissingMessage(getActivity(), getRecyclerView(),
                                Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    }
                }

                break;
            case LocalBroadcastConstants.INTENT_BACKUP_CHANGED:
                updateUI();
            }
        }
    };
}

From source file:com.renard.ocr.help.OCRLanguageActivity.java

private void registerDownloadReceiver() {
    mDownloadReceiver = new BroadcastReceiver() {

        @Override/*from  w  w w . j  a va  2s .c o m*/
        public void onReceive(Context context, Intent intent) {
            String lang = intent.getStringExtra(OCRLanguageInstallService.EXTRA_OCR_LANGUAGE);
            int status = intent.getIntExtra(OCRLanguageInstallService.EXTRA_STATUS, -1);
            updateLanguageList(lang, status);
        }

    };
    mFailedReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String lang = intent.getStringExtra(OCRLanguageInstallService.EXTRA_OCR_LANGUAGE_DISPLAY);
            int status = intent.getIntExtra(OCRLanguageInstallService.EXTRA_STATUS, -1);
            updateLanguageListByDisplayValue(lang, status);
        }
    };
    registerReceiver(mFailedReceiver, new IntentFilter(OCRLanguageInstallService.ACTION_INSTALL_FAILED));
    registerReceiver(mDownloadReceiver, new IntentFilter(OCRLanguageInstallService.ACTION_INSTALL_COMPLETED));
}

From source file:com.inbeacon.cordova.CordovaInbeaconManager.java

private void initEventListener() {

    if (broadcastReceiver != null) {
        // "Already listening, not adding again"
        return;/*from w  ww  . java 2  s . co  m*/
    }

    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            sendUpdate(getEventObject(intent));
        }
    };

    // get all notifications from the inBeacon SDK to our broadcastReceiver
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.inbeacon.sdk.event.enterregion"); // user entered a region
    filter.addAction("com.inbeacon.sdk.event.exitregion"); // user left a region
    filter.addAction("com.inbeacon.sdk.event.enterlocation"); // user entered a location
    filter.addAction("com.inbeacon.sdk.event.exitlocation"); // user left a location
    filter.addAction("com.inbeacon.sdk.event.regionsupdate"); // region definitions were updated
    filter.addAction("com.inbeacon.sdk.event.enterproximity"); // user entered a beacon proximity
    filter.addAction("com.inbeacon.sdk.event.exitproximity"); // user left a beacon proximity
    filter.addAction("com.inbeacon.sdk.event.proximity"); // low level proximity update, once every second when beacons are around
    filter.addAction("com.inbeacon.sdk.event.appevent"); // defined in the backend for special app-specific pages to show
    filter.addAction("com.inbeacon.sdk.event.appaction"); // defined in the backend to handle your own local notifications

    LocalBroadcastManager.getInstance(cordova.getActivity().getApplicationContext())
            .registerReceiver(broadcastReceiver, filter);

}