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.zertinteractive.wallpaper.activities.DetailActivity.java

public void initDownloadComponents() {

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override/*  w  ww  .jav  a 2 s .c  o  m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                //
            }
        }
    };

    context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    context.unregisterReceiver(receiver);
}

From source file:com.ubuntuone.android.files.service.UpDownService.java

private void registerDownloadCancelReceiver() {
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this);
    downloadCancelReceiver = new BroadcastReceiver() {
        @Override/*  w  w w.jav  a 2 s . c o m*/
        public void onReceive(Context context, Intent intent) {
            if (downloadCancelTrigger != null) {
                downloadCancelTrigger.onCancel();
            }
            Uri uri = intent.getData();
            if (uri == null) {
                // Cancel all downloads.
                uri = Downloads.CONTENT_URI;
            }
            TransferUtils.dequeue(contentResolver, uri);
        }
    };
    IntentFilter filter = new IntentFilter(ACTION_CANCEL_DOWNLOAD);
    IntentFilter filterId = null;
    try {
        filterId = new IntentFilter(ACTION_CANCEL_DOWNLOAD, "*/*");
    } catch (MalformedMimeTypeException e) {
        // Not interested.
    }
    bm.registerReceiver(downloadCancelReceiver, filter);
    if (filterId != null) {
        bm.registerReceiver(downloadCancelReceiver, filterId);
    }
}

From source file:com.rjfun.cordova.sms.SMSPlugin.java

protected void createIncomingSMSReceiver() {
    Activity ctx = this.cordova.getActivity();
    this.mReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d(LOGTAG, ("onRecieve: " + action));
            if (SMS_RECEIVED.equals(action)) {
                Bundle bundle;//from  w ww .java2  s  .c  o m
                if (SMSPlugin.this.mIntercept) {
                    this.abortBroadcast();
                }
                if ((bundle = intent.getExtras()) != null) {
                    Object[] pdus;
                    if ((pdus = (Object[]) bundle.get("pdus")).length != 0) {
                        for (int i = 0; i < pdus.length; ++i) {
                            SmsMessage sms = SmsMessage.createFromPdu((byte[]) ((byte[]) pdus[i]));
                            JSONObject json = SMSPlugin.this.getJsonFromSmsMessage(sms);
                            SMSPlugin.this.onSMSArrive(json);
                        }
                    }
                }
            }
        }
    };
    String[] filterstr = new String[] { SMS_RECEIVED };
    for (int i = 0; i < filterstr.length; ++i) {
        IntentFilter filter = new IntentFilter(filterstr[i]);
        filter.setPriority(100);
        ctx.registerReceiver(this.mReceiver, filter);
        Log.d(LOGTAG, ("broadcast receiver registered for: " + filterstr[i]));
    }
}

From source file:com.hypodiabetic.happ.MainActivity.java

public void checkInsulinAppIntegration(View view) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstace());
    Date now = new Date();
    Profile p = new Profile(now, MainActivity.getInstace());
    //Local device based Integrations
    String insulin_Integration_App = prefs.getString("insulin_integration", "");

    //Insulin Integration App, try and connect
    if (!insulin_Integration_App.equals("")) {
        final InsulinIntegrationApp insulinIntegrationApp = new InsulinIntegrationApp(MainActivity.getInstace(),
                insulin_Integration_App, "TEST");
        insulinIntegrationApp.connectInsulinTreatmentApp();
        insulinIntegrationApp_status.setText("Connecting...");
        insulinIntegrationApp_icon.setBackground(clockWhite);
        insulinIntegrationApp_icon.setColorFilter(Color.WHITE);
        //listens out for connection
        insulinIntegrationAppUpdate = new BroadcastReceiver() {
            @Override/*from   w w  w.ja  v a2s .c o m*/
            public void onReceive(Context context, Intent intent) {
                insulinIntegrationApp_status.setText(intent.getStringExtra("MSG"));
                insulinIntegrationApp_icon.setBackground(tickWhite);
                insulinIntegrationApp.sendTest();
                LocalBroadcastManager.getInstance(MainActivity.getInstace())
                        .unregisterReceiver(insulinIntegrationAppUpdate);
            }
        };
        LocalBroadcastManager.getInstance(MainActivity.getInstace())
                .registerReceiver(insulinIntegrationAppUpdate, new IntentFilter("INSULIN_INTEGRATION_TEST"));
    } else {
        insulinIntegrationApp_status.setText("No app selected or not in Closed Loop");
        insulinIntegrationApp_icon.setBackgroundResource(R.drawable.alert_circle);
    }
}

From source file:com.xbh.tmi.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//www  . j  a va2 s .c  o m
        public void onReceive(Context context, Intent intent) {
            updateUnreadLabel();
            if (currentTabIndex == 1) {
                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.polyvi.xface.extension.telephony.XTelephonyExt.java

private void genIncomingCallBroadcastReceiver() {
    if (null == mIncomingCallBroadcastReceiver) {
        mIncomingCallBroadcastReceiver = new BroadcastReceiver() {

            @Override//from  w w w. j  av  a 2 s  .c o m
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (ACTION_PHONE_STATE_CHANGED.equals(action)) {
                    incomingCallResponse(intent);
                }
            }
        };
    }
}

From source file:com.alibaba.weex.IndexActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_index);
    setContainer((ViewGroup) findViewById(R.id.index_container));
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//w  w w. j av  a  2  s  .c  o  m
    getWindow().setFormat(PixelFormat.TRANSLUCENT);

    mProgressBar = (ProgressBar) findViewById(R.id.index_progressBar);
    mTipView = (TextView) findViewById(R.id.index_tip);
    mProgressBar.setVisibility(View.VISIBLE);
    mTipView.setVisibility(View.VISIBLE);

    if (!WXSoInstallMgrSdk.isCPUSupport()) {
        mProgressBar.setVisibility(View.INVISIBLE);
        mTipView.setText(R.string.cpu_not_support_tip);
        return;
    }

    if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
        renderPage(WXFileUtils.loadAsset("index.js", this), getIndexUrl());
    } else {
        renderPageByURL(getIndexUrl());
    }

    mReloadReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            createWeexInstance();
            if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
                renderPage(WXFileUtils.loadAsset("index.js", getApplicationContext()), getIndexUrl());
            } else {
                renderPageByURL(getIndexUrl());
            }
            mProgressBar.setVisibility(View.VISIBLE);
        }
    };

    LocalBroadcastManager.getInstance(this).registerReceiver(mReloadReceiver,
            new IntentFilter(WXSDKEngine.JS_FRAMEWORK_RELOAD));
}

From source file:cn.wyl.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//  w ww  .j  a v a 2 s .co  m
        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.geecko.QuickLyric.fragment.LyricsViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);//from   w  w  w . ja v  a 2  s. com
    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.getTitle();
                    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);

        EditText artistTV = (EditText) getActivity().findViewById(R.id.artist);
        EditText songTV = (EditText) getActivity().findViewById(R.id.song);

        if (args != null && args.containsKey("editedLyrics")) {
            EditText editedLyrics = (EditText) layout.findViewById(R.id.edit_lyrics);
            textSwitcher.setVisibility(View.GONE);
            editedLyrics.setVisibility(View.VISIBLE);
            songTV.setInputType(InputType.TYPE_CLASS_TEXT);
            artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
            songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            editedLyrics.setText(args.getCharSequence("editedLyrics"), TextView.BufferType.EDITABLE);
            songTV.setText(args.getCharSequence("editedTitle"), TextView.BufferType.EDITABLE);
            artistTV.setText(args.getCharSequence("editedArtist"), TextView.BufferType.EDITABLE);
        }

        artistTV.setTypeface(LyricsTextFactory.FontCache.get("regular", getActivity()));
        songTV.setTypeface(LyricsTextFactory.FontCache.get("medium", getActivity()));

        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);
            }
        });
        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();
        TypedValue accentColor = new TypedValue();
        getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
        getActivity().getTheme().resolveAttribute(R.attr.colorAccent, accentColor, true);
        mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, accentColor.resourceId);
        float offset = getResources().getDisplayMetrics().density * 64;
        mRefreshLayout.setProgressViewEndTarget(true, (int) offset);
        mRefreshLayout.setOnRefreshListener(this);

        final ImageButton editTagsButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);

        View.OnClickListener startEditClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startEditTagsMode();
                final View.OnClickListener startEditClickListener = this;
                editTagsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        exitEditTagsMode();
                        editTagsButton.setOnClickListener(startEditClickListener);
                    }
                });
            }
        };
        editTagsButton.setOnClickListener(startEditClickListener);

        if (mLyrics == null) {
            if (!startEmpty)
                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.getTitle());
            ((TextView) (getActivity().findViewById(R.id.artist))).setText(mLyrics.getArtist());
            ((TextView) (getActivity().findViewById(R.id.song))).setText(mLyrics.getTitle());
        } 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.supremainc.biostar2.door.DoorFragment.java

protected void registerBroadcast() {
    if (mReceiver == null) {
        mReceiver = new BroadcastReceiver() {
            @Override/* ww  w  .j  a v a2s. co  m*/
            public void onReceive(Context context, Intent intent) {
                if (mIsDestroy) {
                    return;
                }
                String action = intent.getAction();
                if (action.equals(Setting.BROADCAST_REROGIN)) {
                    applyPermission();
                }
            }
        };
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Setting.BROADCAST_REROGIN);
        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, intentFilter);
    }
}