List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:gcm.play.android.samples.com.gcmquickstart.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().hide();//from w ww . j a va 2 s .c om etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); btnIniciarSesion = (Button) findViewById(R.id.btnIniciarSesion); cbRecordar = (CheckBox) findViewById(R.id.cbRecordar); progressDialog = new ProgressDialog(this, R.style.MyTheme); //Se establece como usuario la cuenta registrada por el usuario para que haga su inicio de sesin userName = UserData.getUserAccount(this); Log.d("USER_ACCOUNT_LOCAL", userName); etUsername.setText(userName); //Establece como no editable el edit text de Usuario etUsername.setKeyListener(null); //progressDialog = new ProgressDialog(this, R.style.MyTheme); progressDialog.setTitle("Registration ID"); progressDialog.setMessage("Espere un momento..."); progressDialog.setCancelable(false); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { progressDialog.dismiss(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { Toast.makeText(getApplicationContext(), getString(R.string.gcm_ready), Toast.LENGTH_LONG) .show(); } else { Toast.makeText(getApplicationContext(), getString(R.string.gcm_not_ready), Toast.LENGTH_LONG) .show(); } } }; if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } //Evento click para iniciar sesin btnIniciarSesion.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startSession(); } }); }
From source file:com.chen.mail.browse.SendersView.java
private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) { if (sConfigurationChangedReceiver == null && resourceCachingRequired) { sConfigurationChangedReceiver = new BroadcastReceiver() { @Override/* w ww . j a va2 s .c o m*/ public void onReceive(Context context, Intent intent) { sDraftSingularString = null; getSenderResources(context, true); } }; context.registerReceiver(sConfigurationChangedReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } if (sDraftSingularString == null) { Resources res = context.getResources(); sSendersSplitToken = res.getString(R.string.senders_split_token); sElidedString = res.getString(R.string.senders_elided); sDraftSingularString = res.getQuantityText(R.plurals.draft, 1); sDraftPluralString = res.getQuantityText(R.plurals.draft, 2); sDraftCountFormatString = res.getString(R.string.draft_count_format); sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance); sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance); sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance); sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersUnreadTextAppearance); sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance); sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersReadTextAppearance); sMessageCountSpacerString = res.getString(R.string.message_count_spacer); sSendingString = res.getString(R.string.sending); sBidiFormatter = BidiFormatter.getInstance(); } }
From source file:ar.com.iron.android.extensions.connections.InetDataClient.java
/** * Inicializa los listeners para conocer el estado actual de la red */// w w w. j a v a 2 s.c o m private void initListeners() { getIntentReceptor().registerMessageReceiver(ConnectivityManager.CONNECTIVITY_ACTION, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onConnectivityChanged(intent); } }); }
From source file:com.ironsmile.cordova.mediaevents.MediaEventListener.java
/** * Executes the request./*from w w w. j av a 2 s. c om*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into js * @return True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { if (this.eventCallbackContext != null) { callbackContext.error("Media event listener already running."); return true; } this.eventCallbackContext = callbackContext; // We need to listen to audio events IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { sendMediaEvent(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } if (this.focusListener == null) { Context ctx = cordova.getActivity().getBaseContext(); this.focusListener = this.new FocusListener(ctx); } // Don't return any result now, since status results will be sent when // events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { removeMediaEventListener(); // release status callback in JS side this.sendUpdate(new JSONObject(), false); this.eventCallbackContext = null; callbackContext.success(); return true; } return false; }
From source file:com.android.mail.browse.SendersView.java
private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) { if (sConfigurationChangedReceiver == null && resourceCachingRequired) { sConfigurationChangedReceiver = new BroadcastReceiver() { @Override//from w w w . j a va 2 s . c o m public void onReceive(Context context, Intent intent) { sDraftSingularString = null; getSenderResources(context, true); } }; context.registerReceiver(sConfigurationChangedReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } if (sDraftSingularString == null) { Resources res = context.getResources(); sSendersSplitToken = res.getString(R.string.senders_split_token); sElidedString = res.getString(R.string.senders_elided); sDraftSingularString = res.getQuantityText(R.plurals.draft, 1); sDraftPluralString = res.getQuantityText(R.plurals.draft, 2); sDraftCountFormatString = res.getString(R.string.draft_count_format); sMeSubjectString = res.getString(R.string.me_subject_pronoun); sMeObjectString = res.getString(R.string.me_object_pronoun); sToHeaderString = res.getString(R.string.to_heading); sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance); sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance); sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance); sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceUnreadStyle); sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance); sRetryingStyleSpan = new TextAppearanceSpan(context, R.style.RetryingTextAppearance); sFailedStyleSpan = new TextAppearanceSpan(context, R.style.FailedTextAppearance); sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceReadStyle); sMessageCountSpacerString = res.getString(R.string.message_count_spacer); sSendingString = res.getString(R.string.sending); sRetryingString = res.getString(R.string.message_retrying); sFailedString = res.getString(R.string.message_failed); sBidiFormatter = BidiFormatter.getInstance(); } }
From source file:com.bayapps.android.robophish.ui.BaseActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LogHelper.d(TAG, "Activity onCreate"); if (Build.VERSION.SDK_INT >= 21) { // Since our app icon has the same color as colorPrimary, our entry in the Recent Apps // list gets weird. We need to change either the icon or the color // of the TaskDescription. ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getTitle().toString(), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white), ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray)); setTaskDescription(taskDesc);//from w w w. j a va2 s. c om } // Connect a media browser just to get the media session token. There are other ways // this can be done, for example by sharing the session token directly. mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class), mConnectionCallback, null); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { //mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { //mInformationTextView.setText(getString(R.string.token_error_message)); } } }; // Registering BroadcastReceiver registerReceiver(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } }
From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationProvider.java
public void broadcastLocation(Location location) { final LocationProxy bgLocation = LocationProxy.fromAndroidLocation(location); bgLocation.setServiceProvider(config.getServiceProvider()); if (config.isDebugging()) { bgLocation.setDebug(true);/*w ww .j ava 2s . co m*/ persistLocation(bgLocation); } Log.d(TAG, "Broadcasting update message: " + bgLocation.toString()); try { String locStr = bgLocation.toJSONObject().toString(); Intent intent = new Intent(Constant.ACTION_FILTER); intent.putExtra(Constant.ACTION, Constant.ACTION_LOCATION_UPDATE); intent.putExtra(Constant.DATA, locStr); if (config.getUrl() != null) { Log.i(TAG, "Sending URL detail"); intent.putExtra("url", config.getUrl()); intent.putExtra("method", config.getMethod()); intent.putExtra("headers", config.getHeaders()); intent.putExtra("params", config.getParams()); } else { Log.i(TAG, "No URL defined"); } context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { // @SuppressLint("NewApi") @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Final Result Receiver"); Bundle results = getResultExtras(true); if (results.getString(Constant.LOCATION_SENT_INDICATOR) == null) { Log.w(TAG, "Main activity seems to be killed"); if (config.getStopOnTerminate() == false) { bgLocation.setDebug(false); persistLocation(bgLocation); Log.d(TAG, "Persisting location. Reason: Main activity was killed."); } } } }, null, Activity.RESULT_OK, null, null); } catch (JSONException e) { Log.w(TAG, "Failed to broadcast location"); } }
From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java
@Override public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate()"); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); mBroadcastReceiver = new BroadcastReceiver() { @Override/* w w w. j ava 2s .co m*/ public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive(): " + intent.getAction()); } }; registerReceiver(mBroadcastReceiver, filter); readPersistedData(); mCastManager = VideoChromeCastManager.initialize(this, mApplicationId, mTargetActivity, null); if (!mCastManager.isConnected()) { mCastManager.reconnectSessionIfPossible(this, false); } mConsumer = new VideoCastConsumerImpl() { @Override public void onApplicationDisconnected(int errorCode) { Log.d(TAG, "onApplicationDisconnected() was reached"); stopSelf(); } @Override public void onRemoteMediaPlayerStatusUpdated() { int mediaStatus = mCastManager.getPlaybackStatus(); VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus); } }; mCastManager.addVideoCastConsumer(mConsumer); }
From source file:com.rdrive.updateapk.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_update = (Button) findViewById(R.id.button_update); btn_update.setEnabled(false);/*from www. j a va 2s. com*/ currentVersionValue = (TextView) findViewById(R.id.currentVersionValue); lastVersionValue = (TextView) findViewById(R.id.lastVersionValue); dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); new CheckUpdate() { @Override protected void onPostExecute(Boolean aBoolean) { currentVersionValue.setText(this.getCurrentVersion().toString()); lastVersionValue.setText(this.getLastVersion().toString()); if (!aBoolean) { btn_update.setEnabled(true); } } }.execute(getContext()); btn_update.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT > 22) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, ASK_WRITE_EXTERNAL_STORAGE_FOR_UPDATE); return; } } downloadLastVersion(getContext(), dm); } }); BroadcastReceiver attachmentDownloadCompleteReceive = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); Cursor cursor = dm.query(query); if (cursor.moveToFirst()) { int downloadStatus = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); String downloadLocalUri = cursor .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); if ((downloadStatus == DownloadManager.STATUS_SUCCESSFUL) && downloadLocalUri != null) { openApk(getContext(), downloadLocalUri); } } cursor.close(); } } }; registerReceiver(attachmentDownloadCompleteReceive, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:com.hao.common.manager.AppManager.java
private AppManager() { // ?//from ww w. j a v a 2 s. c om CrashHandler.getInstance().init(); sApp.registerReceiver(new BroadcastReceiver() { private boolean mIsFirstReceiveBroadcast = true; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { if (!mIsFirstReceiveBroadcast) { if (NetWorkUtil.isNetworkAvailable()) { RxBus.send(new RxEvent.NetworkConnectedEvent()); } else { RxBus.send(new RxEvent.NetworkDisconnectedEvent()); } } else { mIsFirstReceiveBroadcast = false; } } } }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }