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.ubuntuone.android.files.activity.PreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mContext = this;

    mTracker = GoogleAnalyticsTracker.getInstance();
    mTracker.start(Analytics.U1F_ACCOUNT, this);
    mTracker.trackPageView(TAG);//from   w  w  w  . j ava 2s .  c  o m

    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    // Account category. 

    final Preference username = findPreference(Preferences.USERNAME_KEY);

    final String usernameSummary = Preferences.getString(Preferences.USERNAME_KEY, "(?)");
    username.setSummary(usernameSummary);

    setupOnClickPreference(Pref.INVITE_FRIEND, this);

    final Preference purchaseStorage = findPreference(Pref.PURCHASE_STORAGE);
    purchaseStorage.setOnPreferenceClickListener(mPurchaseStorageListener);

    final Preference upgradePlan = findPreference(Pref.UPGRADE_PLAN);
    upgradePlan.setOnPreferenceClickListener(mLinkListener);

    // Options category.

    final PreferenceScreen mediaUploadScreen = (PreferenceScreen) findPreference(Pref.MEDIA_UPLOAD);
    mediaUploadScreen.setOnPreferenceClickListener(whiteHackClick);

    // Photo Auto Upload

    final CheckBoxPreference photosAutoUploadToggle = (CheckBoxPreference) findPreference(
            Preferences.PHOTO_UPLOAD_ENABLED_KEY);
    photosAutoUploadToggle.setOnPreferenceClickListener(mPhotosAutoUploadToggleListener);

    final Preference photosAutoUploadSources = findPreference(Pref.PHOTOS_AUTO_UPLOAD_SOURCES);
    photosAutoUploadSources.setOnPreferenceClickListener(mPhotosAutoUploadSourcesListener);

    mPhotosAutoUploadDir = (Preference) findPreference(Preferences.PHOTO_UPLOAD_DIR_KEY);
    mPhotosAutoUploadDir.setOnPreferenceClickListener(mPhotosAutoUploadDirListener);
    final String photosAutoUploadDirectory = Preferences.getPhotoUploadDirectory();
    mPhotosAutoUploadDir.setDefaultValue(photosAutoUploadDirectory);
    mPhotosAutoUploadDir.setSummary(photosAutoUploadDirectory);

    final Preference uploadPhotosNow = findPreference(Pref.UPLOAD_PHOTOS_NOW);
    uploadPhotosNow.setOnPreferenceClickListener(mUploadPhotosNowListener);

    final Preference cancelAllUploads = findPreference(Pref.CANCEL_ALL_UPLOADS);
    cancelAllUploads.setOnPreferenceClickListener(mCancelAllUploadsListener);

    // General

    final PreferenceScreen advancedOptionsScreen = (PreferenceScreen) findPreference(Pref.ADVANCED_OPTIONS);
    advancedOptionsScreen.setOnPreferenceClickListener(whiteHackClick);

    final Preference autoRetry = findPreference(Preferences.AUTO_RETRY_FAILED);
    autoRetry.setOnPreferenceChangeListener(mAutoRetryListener);

    final Preference clearPreviewCache = findPreference(Pref.CLEAR_PREVIEW_CACHE);
    clearPreviewCache.setOnPreferenceClickListener(mClearPreviewCacheListener);

    final Preference clearThumbCache = findPreference(Pref.CLEAR_THUMB_CACHE);
    clearThumbCache.setOnPreferenceClickListener(mClearThumbCacheListener);

    final Preference removeDevice = findPreference(Pref.REMOVE_DEVICE);
    removeDevice.setOnPreferenceClickListener(mRemoveDeviceListener);

    mRetryFailed = findPreference(Pref.RETRY_FAILED);
    mRetryFailed.setOnPreferenceClickListener(mRetryFailedListener);

    mCancelFailed = findPreference(Pref.CANCEL_FAILED);
    mCancelFailed.setOnPreferenceClickListener(mCancelFailedListener);

    // Manage category.

    final Preference manageAccount = findPreference(Pref.MANAGE_ACCOUNT);
    manageAccount.setOnPreferenceClickListener(mLinkListener);

    final Preference supportOptions = findPreference(Pref.SUPPORT_OPTIONS);
    supportOptions.setOnPreferenceClickListener(mLinkListener);

    final Preference feedback = findPreference(Pref.FEEDBACK);
    feedback.setOnPreferenceClickListener(mFeedbackListener);

    final PreferenceScreen reportScreen = (PreferenceScreen) findPreference(Pref.REPORT_PROBLEM);
    reportScreen.setOnPreferenceClickListener(whiteHackClick);

    mCollectLogs = (CheckBoxPreference) findPreference(Pref.COLLECT_LOGS);
    mCollectLogs.setOnPreferenceClickListener(mCollectLogsListener);

    mReviewLogs = findPreference(Pref.REVIEW_LOGS);
    mReviewLogs.setOnPreferenceClickListener(mReviewLogsListener);

    mSendLogs = findPreference(Pref.SEND_LOGS);
    mSendLogs.setOnPreferenceClickListener(mSendLogsListener);

    final PreferenceScreen about = (PreferenceScreen) findPreference(Pref.ABOUT);
    about.setSummary(UbuntuOneFiles.getVersion());
    about.setOnPreferenceClickListener(whiteHackClick);

    final Preference license = findPreference(Pref.LICENSE);
    license.setOnPreferenceClickListener(mLinkListener);

    final Preference changelog = findPreference(Pref.CHANGELOG);
    changelog.setOnPreferenceClickListener(mChangelogListener);

    final Preference author = findPreference(Pref.AUTHORS);
    author.setOnPreferenceClickListener(mLinkListener);

    final Preference webpage = findPreference(Pref.WEBPAGE);
    webpage.setOnPreferenceClickListener(mLinkListener);

    final Preference greendroid = findPreference(Pref.GREENDROID);
    greendroid.setOnPreferenceClickListener(mLinkListener);

    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (UpDownService.BROADCAST_UPLOAD_INFO.equals(action)) {
                final String info = intent.getStringExtra(Intent.EXTRA_TEXT);
                if (info != null) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adjustTransferPreferencesState();
                            Preference p = findPreference(Pref.UPLOAD_PHOTOS_NOW);
                            if (p != null) {
                                p.setSummary(info);
                            }
                        }
                    });
                }
            }
        }
    };
    registerAutoUploadInfoReceiver(receiver);

    Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(AUTOUPLOAD_SCREEN)) {
            openPreference(Pref.MEDIA_UPLOAD);
        } else if (intent.hasExtra(PURCHASE_STORAGE_SCREEN)) {
            openPreference(Pref.PURCHASE_STORAGE);
        } else if (intent.hasExtra(SHOW_RETRY_FAILED)) {
            // Simply shows top screen. Hilight retry failed pref?
        }
    }
}

From source file:com.supremainc.biostar2.alarm.AlarmListFragment.java

protected void registerBroadcast() {
    if (mReceiver == null) {
        mReceiver = new BroadcastReceiver() {
            @Override//from  w  w  w. ja va2  s.c o m
            public void onReceive(Context context, Intent intent) {
                if (mIsDestroy) {
                    return;
                }
                final String action = intent.getAction();
                if (mIsDestroy) {
                    return;
                }
                if (action.equals(Setting.BROADCAST_ALARM_UPDATE)
                        || action.equals(Setting.BROADCAST_PREFRENCE_REFRESH)) {
                    if (isResumed()) {

                        if (mAlarmAdapter != null) {
                            if (mSubMode != MODE_DELETE) {
                                refresh();
                            } else {
                                mIsDataReceived = false;
                            }
                        }
                    } else {
                        mIsDataReceived = false;
                    }
                }
            }
        };
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Setting.BROADCAST_ALARM_UPDATE);
        intentFilter.addAction(Setting.BROADCAST_PREFRENCE_REFRESH);
        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, intentFilter);
    }
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java

public void DataUpdateBackgroundService() {

    final BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.mipmap.car);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("update_map1");
    deliveryBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   ww w  . j a  v  a2 s.  c o  m
        public void onReceive(Context context, Intent intent) {
            //TODO  map updations work here
            System.out.println("update run FragmentArrive");

            mDriverdetailsList = (ArrayList<Driverdetails>) intent.getSerializableExtra("backgroundArraylist");
            // System.out.println("mDriverdetailsList info===>>>>"+mDriverdetailsList+mDriverdetailsList.size());
            if (mDriverdetailsList != null) {
                System.out.println("mDriverdetailsList infoarrive===>>>>" + mDriverdetailsList
                        + mDriverdetailsList.size());
                for (int j = 0; j < mDriverdetailsList.size(); j++) {

                    if (mDriverdetailsList.get(j).getDriverdetailslocations() != null
                            && mDriverdetailsList.get(j).getDriverdetailslocations().size() > 0) {

                        String lat = "";
                        String lng = "";

                        for (int i = 0; i < mDriverdetailsList.get(j).getDriverdetailslocations().size(); i++) {
                            if (MyApplication.driverId != null && !MyApplication.driverId.equals("")
                                    && MyApplication.driverId.equals(mDriverdetailsList.get(j).getDriverId())) {
                                System.out.println("ArriveDriver" + MyApplication.driverId);
                                lat = mDriverdetailsList.get(j).getDriverdetailslocations().get(i)
                                        .getLatitude();
                                lng = mDriverdetailsList.get(j).getDriverdetailslocations().get(i)
                                        .getLongitude();

                                validateGET_TIME(latitude, longitude, Double.parseDouble(lat),
                                        Double.parseDouble(lng));
                                if (marker != null) {
                                    System.out.println("ArriveDriver" + "ifunder>>>>>>>>>>>>>>>>>>>>>");
                                    marker.setPosition(
                                            new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
                                    angle = (float) finalBearing(previousLocationLatitude,
                                            previousLocationLongitude, Double.parseDouble(lat),
                                            Double.parseDouble(lng));
                                    CameraPosition cameraPosition = new CameraPosition.Builder()
                                            .target(new LatLng(previousLocationLatitude,
                                                    previousLocationLongitude))
                                            .bearing(angle).tilt(90).zoom(15).build();
                                    googleMap.animateCamera(
                                            CameraUpdateFactory.newCameraPosition(cameraPosition));

                                    previousLocationLatitude = Double.parseDouble(lat);
                                    previousLocationLongitude = Double.parseDouble(lng);

                                } else {
                                    System.out.println("ArriveDriver" + "elseunder>>>>>>>>>>>>>>>>>>>>>");
                                    marker = googleMap.addMarker(markerOptions.icon(icon).position(new LatLng(
                                            Double.parseDouble(mDriverdetailsList.get(j)
                                                    .getDriverdetailslocations().get(i).getLatitude()),
                                            Double.parseDouble(mDriverdetailsList.get(j)
                                                    .getDriverdetailslocations().get(i).getLongitude())))
                                            .draggable(true).visible(true));

                                    CameraPosition cameraPosition = new CameraPosition.Builder()
                                            .target(new LatLng(previousLocationLatitude,
                                                    previousLocationLongitude))
                                            .bearing(angle).tilt(90).zoom(15).build();
                                    googleMap.animateCamera(
                                            CameraUpdateFactory.newCameraPosition(cameraPosition));

                                    previousLocationLatitude = Double.parseDouble(mDriverdetailsList.get(j)
                                            .getDriverdetailslocations().get(i).getLatitude());
                                    previousLocationLongitude = Double.parseDouble(mDriverdetailsList.get(j)
                                            .getDriverdetailslocations().get(i).getLongitude());

                                }
                            }

                        }

                    }

                }
            }

        }
    };
    getActivity().registerReceiver(deliveryBroadcastReceiver, intentFilter);

}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void waitForPageLoaded(Bundle savedInstanceState) {
    final String savedHash = savedInstanceState != null
            ? savedInstanceState.getString(EXTRA_SAVED_ATTACHMENTHASH)
            : null;/*  ww w  .  j a va 2s . co m*/
    if (savedHash != null)
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction() != null
                        && intent.getAction().equals(BoardFragment.BROADCAST_PAGE_LOADED)) {
                    unregisterReceiver(this);
                    broadcastReceiver = null;

                    Intent activityIntent = getIntent();
                    String pagehash = activityIntent.getStringExtra(EXTRA_PAGEHASH);
                    if (pagehash != null && remote.isPageLoaded(pagehash)) {
                        startActivity(activityIntent.putExtra(EXTRA_SAVED_ATTACHMENTHASH, savedHash));
                        finish();
                    }
                }
            }
        }, new IntentFilter(BoardFragment.BROADCAST_PAGE_LOADED));
}

From source file:com.p2p.misc.DeviceUtility.java

public float batteryLevel() {
    try {//from   w w w  . j  a v  a  2s  . c o  m

        BroadcastReceiver batteryReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                //  context.unregisterReceiver(this);
                Intent batteryIntent = mactivity.registerReceiver(null,
                        new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
                int rawlevel = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                if (level == -1 || scale == -1) {
                    level = 50.0f;
                }

                if (rawlevel >= 0 && scale > 0) {
                    level = ((float) level / (float) scale) * 100.0f;
                }

                set_BatteryLevel(level);
                // Constants.BATTERY_LEVEL=level;
                System.out.println("Battery Level Remaining: " + level + "%");
            }

        };
        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        mactivity.registerReceiver(batteryReceiver, filter);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return level;
}

From source file:com.zhou.superwechat.ui.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);
    intentFilter.addAction(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION);
    broadcastReceiver = new BroadcastReceiver() {

        @Override// ww  w .ja va  2 s . c om
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            updateUnreadAddressLable();
            // if (currentTabIndex == 0) {
            // refresh conversation list
            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(MainActivity.this).equals(GroupsActivity.class.getName())) {
                    GroupsActivity.instance.onResume();
                }
            }
            //red packet code : ???
            if (action.equals(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION)) {
                if (conversationListFragment != null) {
                    conversationListFragment.refresh();
                }
            }
            //end of red packet code
        }
    };
    broadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:com.andreadec.musicplayer.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (musicService != null)
        startRoutine();//  w w w. ja va2s  .co  m

    // Enable the broadcast receiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.andreadec.musicplayer.newsong");
    intentFilter.addAction("com.andreadec.musicplayer.playpausechanged");
    intentFilter.addAction("com.andreadec.musicplayer.podcastdownloadcompleted");
    intentFilter.addAction("com.andreadec.musicplayer.quitactivity");
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("com.andreadec.musicplayer.newsong")) {
                updatePlayingItem();
            } else if (intent.getAction().equals("com.andreadec.musicplayer.playpausechanged")) {
                updatePlayPauseButton();
            } else if (intent.getAction().equals("com.andreadec.musicplayer.podcastdownloadcompleted")) {
                if (currentPage == PAGE_PODCASTS) {
                    PodcastsFragment podcastsFragment = (PodcastsFragment) currentFragment;
                    podcastsFragment.updateListView(true);
                }
            } else if (intent.getAction().equals("com.andreadec.musicplayer.quitactivity")) {
                finish(); // I don't call quitActivity() because the service closes himself after sending this broadcast
            }

        }
    };
    registerReceiver(broadcastReceiver, intentFilter);
    updatePlayPauseButton();
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private void requestLicense() {
    if (TextUtils.isEmpty(LicenseUtils.getLicenseName(this))) {
        Intent intent = new Intent(PreventIntent.ACTION_CHECK_LICENSE,
                Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
        intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
        sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, new BroadcastReceiver() {
            @Override/* w  w  w . j  av  a2 s . com*/
            public void onReceive(Context context, Intent intent) {
                if (PreventIntent.ACTION_CHECK_LICENSE.equals(intent.getAction()) && getResultCode() != 1) {
                    request = LicenseUtils.requestLicense(UserGuideActivity.this, null, getResultData());
                }
            }
        }, null, 0, null, null);
    }
}

From source file:cn.moon.superwechat.ui.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);
    intentFilter.addAction(RPConstant.REFRESH_GROUP_RED_PACKET_ACTION);
    broadcastReceiver = new BroadcastReceiver() {

        @Override//from  w w w  .  j av a2s .  c  om
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            updateUnreadAddressLable();
            if (currentTabIndex == 0) {
                // refresh conversation list
                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(MainActivity.this).equals(GroupsActivity.class.getName())) {
                    GroupsActivity.instance.onResume();
                }
            }
            //red packet code : ???
            if (action.equals(RPConstant.REFRESH_GROUP_RED_PACKET_ACTION)) {
                if (conversationListFragment != null) {
                    conversationListFragment.refresh();
                }
            }
            //end of red packet code
        }
    };
    broadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:cn.ucai.wechat.ui.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);
    intentFilter.addAction(RPConstant.REFRESH_GROUP_RED_PACKET_ACTION);
    broadcastReceiver = new BroadcastReceiver() {

        @Override//w  w  w. j  a v a 2 s.  c om
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            updateUnreadAddressLable();
            if (currentTabIndex == 0) {
                // refresh conversation list
                if (conversationListFragment != null) {
                    conversationListFragment.refresh();
                }
            } else if (currentTabIndex == 1) { // currentTabIndex=1?
                if (contactListFragment != null) {
                    contactListFragment.refresh();// ?
                }
            }
            String action = intent.getAction();
            if (action.equals(Constant.ACTION_GROUP_CHANAGED)) {
                if (EaseCommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) {
                    GroupsActivity.instance.onResume();
                }
            }
            //red packet code : ???
            if (action.equals(RPConstant.REFRESH_GROUP_RED_PACKET_ACTION)) {
                if (conversationListFragment != null) {
                    conversationListFragment.refresh();
                }
            }
            //end of red packet code
        }
    };
    broadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}