List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main4); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override//ww w . j av a 2 s . c o m 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)); }*/ Log.i("Entro nessa bagaa", "asdgasjdgjhasgdjgasda"); } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); /*if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } EventBus.getDefault().register(this);*/ tv = (TextView) findViewById(R.id.textView); Amigo amigo = new Amigo(); amigo.setIdAmigo(2); String url = "http://192.168.129.147:80/Servidor/FronteiraBuscarAmigo.php"; NetworkConnection.getInstance(this).executeBusca(new WrapObjToNetwork(amigo), RegistrationIntentService.class.getName(), url); }
From source file:com.polyvi.xface.extension.XBatteryExt.java
@Override public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException { XExtensionResult.Status status = XExtensionResult.Status.INVALID_ACTION; String result = "Unsupported Operation: " + action; if (COMMAND_START.equals(action)) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); final XCallbackContext cbCtx = callbackCtx; if (null == mBroadcastReceiver) { mBroadcastReceiver = new BroadcastReceiver() { @Override/*from w w w.j a v a2 s . c om*/ public void onReceive(Context context, Intent intent) { XLog.d(CLASS_NAME, "received broadcast of battery changing"); updateBatteryInfo(intent, cbCtx); } }; getContext().registerReceiver(mBroadcastReceiver, intentFilter); } XExtensionResult extensionResult = new XExtensionResult(XExtensionResult.Status.NO_RESULT); extensionResult.setKeepCallback(true); return extensionResult; } else if (COMMAND_STOP.equals(action)) { removeBatteryListener(); sendUpdate(new JSONObject(), callbackCtx, false); return new XExtensionResult(XExtensionResult.Status.OK); } return new XExtensionResult(status, result); }
From source file:kkook.team.projectswitch.gcm.TestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_gcm); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override/*from w w w . j ava2 s . c o m*/ 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( "Token retrieved and sent to server! You can now use gcmsender to send downstream messages to this app."); ((Button) findViewById(R.id.btnSend)).setVisibility(View.VISIBLE); ((EditText) findViewById(R.id.etMessage)).setVisibility(View.VISIBLE); } else { mInformationTextView.setText( "An error occurred while either fetching the InstanceID token, sending the fetched token to the server or subscribing to the PubSub topic. Please try running the sample again."); } } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); ((Button) findViewById(R.id.btnSend)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(runSender).start(); } }); } }
From source file:com.jams.music.player.Dialogs.ABRepeatDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;//from w w w . j a v a2s . com receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { initRepeatSongRangeDialog(); } }; sharedPreferences = getActivity().getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_repeat_song_range_dialog, null); currentSongIndex = mApp.getService().getCurrentSongIndex(); repeatSongATime = (TextView) view.findViewById(R.id.repeat_song_range_A_time); repeatSongBTime = (TextView) view.findViewById(R.id.repeat_song_range_B_time); currentSongDurationMillis = (int) mApp.getService().getCurrentMediaPlayer().getDuration(); currentSongDurationSecs = (int) currentSongDurationMillis / 1000; //Remove the placeholder seekBar and replace it with the RangeSeekBar. seekBar = (SeekBar) view.findViewById(R.id.repeat_song_range_placeholder_seekbar); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) seekBar.getLayoutParams(); viewGroup = (ViewGroup) seekBar.getParent(); viewGroup.removeView(seekBar); rangeSeekBar = new RangeSeekBar<Integer>(0, currentSongDurationSecs, getActivity()); rangeSeekBar.setLayoutParams(params); viewGroup.addView(rangeSeekBar); if (sharedPreferences.getInt(Common.REPEAT_MODE, Common.REPEAT_OFF) == Common.A_B_REPEAT) { repeatSongATime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointA())); repeatSongBTime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointB())); rangeSeekBar.setSelectedMinValue(mApp.getService().getRepeatSongRangePointA()); rangeSeekBar.setSelectedMaxValue(mApp.getService().getRepeatSongRangePointB()); repeatPointA = mApp.getService().getRepeatSongRangePointA(); repeatPointB = mApp.getService().getRepeatSongRangePointB(); } else { repeatSongATime.setText("0:00"); repeatSongBTime.setText(convertMillisToMinsSecs(currentSongDurationMillis)); repeatPointA = 0; repeatPointB = currentSongDurationMillis; } rangeSeekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() { @Override public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) { repeatPointA = minValue * 1000; repeatPointB = maxValue * 1000; repeatSongATime.setText(convertMillisToMinsSecs(minValue * 1000)); repeatSongBTime.setText(convertMillisToMinsSecs(maxValue * 1000)); } }); //Set the dialog title. builder.setTitle(R.string.a_b_repeat); builder.setView(view); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }); builder.setPositiveButton(R.string.repeat, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((currentSongDurationSecs - repeatPointB) < mApp.getCrossfadeDuration()) { //Remove the crossfade handler. mApp.getService().getHandler().removeCallbacks(mApp.getService().startCrossFadeRunnable); mApp.getService().getHandler().removeCallbacks(mApp.getService().crossFadeRunnable); } mApp.broadcastUpdateUICommand(new String[] { Common.UPDATE_PLAYBACK_CONTROLS }, new String[] { "" }); mApp.getService().setRepeatSongRange(repeatPointA, repeatPointB); mApp.getService().setRepeatMode(Common.A_B_REPEAT); } }); return builder.create(); }
From source file:com.jelly.music.player.Dialogs.ABRepeatDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;/*from w w w. j av a 2 s . c o m*/ receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { initRepeatSongRangeDialog(); } }; sharedPreferences = getActivity().getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_repeat_song_range_dialog, null); currentSongIndex = mApp.getService().getCurrentSongIndex(); repeatSongATime = (TextView) view.findViewById(R.id.repeat_song_range_A_time); repeatSongBTime = (TextView) view.findViewById(R.id.repeat_song_range_B_time); currentSongDurationMillis = (int) mApp.getService().getCurrentMediaPlayer().getDuration(); currentSongDurationSecs = (int) currentSongDurationMillis / 1000; //Remove the placeholder seekBar and replace it with the RangeSeekBar. seekBar = (SeekBar) view.findViewById(R.id.repeat_song_range_placeholder_seekbar); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) seekBar.getLayoutParams(); viewGroup = (ViewGroup) seekBar.getParent(); viewGroup.removeView(seekBar); rangeSeekBar = new RangeSeekBar<Integer>(0, currentSongDurationSecs, getActivity()); rangeSeekBar.setLayoutParams(params); viewGroup.addView(rangeSeekBar); if (sharedPreferences.getInt(Common.REPEAT_MODE, Common.REPEAT_OFF) == Common.A_B_REPEAT) { repeatSongATime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointA())); repeatSongBTime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointB())); rangeSeekBar.setSelectedMinValue(mApp.getService().getRepeatSongRangePointA()); rangeSeekBar.setSelectedMaxValue(mApp.getService().getRepeatSongRangePointB()); repeatPointA = mApp.getService().getRepeatSongRangePointA(); repeatPointB = mApp.getService().getRepeatSongRangePointB(); } else { repeatSongATime.setText("0:00"); repeatSongBTime.setText(convertMillisToMinsSecs(currentSongDurationMillis)); repeatPointA = 0; repeatPointB = currentSongDurationMillis; } rangeSeekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() { @Override public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) { repeatPointA = minValue * 1000; repeatPointB = maxValue * 1000; repeatSongATime.setText(convertMillisToMinsSecs(minValue * 1000)); repeatSongBTime.setText(convertMillisToMinsSecs(maxValue * 1000)); } }); //Set the dialog title. builder.setTitle(R.string.a_b_repeat); builder.setView(view); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }); builder.setPositiveButton(R.string.repeat, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((currentSongDurationSecs - repeatPointB) < mApp.getCrossfadeDuration()) { //Remove the crossfade handler. mApp.getService().getHandler().removeCallbacks(mApp.getService().startCrossFadeRunnable); mApp.getService().getHandler().removeCallbacks(mApp.getService().crossFadeRunnable); } mApp.broadcastUpdateUICommand(new String[] { Common.UPDATE_PLAYBACK_CONTROLS }, new String[] { "" }); mApp.getService().setRepeatSongRange(repeatPointA, repeatPointB); mApp.getService().setRepeatMode(Common.A_B_REPEAT); } }); return builder.create(); }
From source file:com.aniruddhc.acemusic.player.Dialogs.ABRepeatDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;/*from ww w . j a va2s.c om*/ receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { initRepeatSongRangeDialog(); } }; sharedPreferences = getActivity().getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_repeat_song_range_dialog, null); currentSongIndex = mApp.getService().getCurrentSongIndex(); repeatSongATime = (TextView) view.findViewById(R.id.repeat_song_range_A_time); repeatSongBTime = (TextView) view.findViewById(R.id.repeat_song_range_B_time); currentSongDurationMillis = (int) mApp.getService().getCurrentMediaPlayer().getDuration(); currentSongDurationSecs = (int) currentSongDurationMillis / 1000; //Remove the placeholder seekBar and replace it with the RangeSeekBar. seekBar = (SeekBar) view.findViewById(R.id.repeat_song_range_placeholder_seekbar); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) seekBar.getLayoutParams(); viewGroup = (ViewGroup) seekBar.getParent(); viewGroup.removeView(seekBar); rangeSeekBar = new RangeSeekBar<Integer>(0, currentSongDurationSecs, getActivity()); rangeSeekBar.setLayoutParams(params); viewGroup.addView(rangeSeekBar); if (sharedPreferences.getInt(Common.REPEAT_MODE, Common.REPEAT_OFF) == Common.A_B_REPEAT) { repeatSongATime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointA())); repeatSongBTime.setText(convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointB())); rangeSeekBar.setSelectedMinValue(mApp.getService().getRepeatSongRangePointA()); rangeSeekBar.setSelectedMaxValue(mApp.getService().getRepeatSongRangePointB()); repeatPointA = mApp.getService().getRepeatSongRangePointA(); repeatPointB = mApp.getService().getRepeatSongRangePointB(); } else { repeatSongATime.setText("0:00"); repeatSongBTime.setText(convertMillisToMinsSecs(currentSongDurationMillis)); repeatPointA = 0; repeatPointB = currentSongDurationMillis; } rangeSeekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() { @Override public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) { repeatPointA = minValue * 1000; repeatPointB = maxValue * 1000; repeatSongATime.setText(convertMillisToMinsSecs(minValue * 1000)); repeatSongBTime.setText(convertMillisToMinsSecs(maxValue * 1000)); } }); //Set the dialog title. builder.setTitle(R.string.a_b_repeat); builder.setView(view); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }); builder.setPositiveButton(R.string.repeat, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((currentSongDurationSecs - repeatPointB) < mApp.getCrossfadeDuration()) { //Remove the crossfade handler. mApp.getService().getHandler().removeCallbacks(mApp.getService().startCrossFadeRunnable); mApp.getService().getHandler().removeCallbacks(mApp.getService().crossFadeRunnable); } mApp.broadcastUpdateUICommand(new String[] { Common.UPDATE_PLAYBACK_CONTROLS }, new String[] { "" }); mApp.getService().setRepeatSongRange(repeatPointA, repeatPointB); mApp.getService().setRepeatMode(Common.A_B_REPEAT); } }); return builder.create(); }
From source file:com.andreadec.musicplayer.PodcastEpisodeDownloaderService.java
@Override protected void onHandleIntent(Intent intent) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(STOP_DOWNLOAD_INTENT); BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override/*from ww w. jav a 2 s. c o m*/ public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(STOP_DOWNLOAD_INTENT)) { downloadInProgress = false; } } }; registerReceiver(broadcastReceiver, intentFilter); String type = intent.getStringExtra("type"); String title = intent.getStringExtra("title"); String idItem = intent.getStringExtra("idItem"); String podcastsDirectory = intent.getStringExtra("podcastsDirectory"); notificationBuilder.setContentTitle(getResources().getString(R.string.podcastDownloading, title)); notificationBuilder.setContentText(getResources().getString(R.string.podcastDownloading, title)); notificationManager.notify(Constants.NOTIFICATION_PODCAST_ITEM_DOWNLOAD_ONGOING, notificationBuilder.build()); String filename; do { filename = podcastsDirectory + "/" + UUID.randomUUID().toString(); } while (new File(filename).exists()); // To avoid accidentally override an already existing file Intent intentCompleted = new Intent("com.andreadec.musicplayer.podcastdownloadcompleted"); HttpURLConnection httpConnection = null; try { if (type.equalsIgnoreCase("audio/mpeg") || type.equalsIgnoreCase("audio/.mp3")) filename += ".mp3"; else if (type.equalsIgnoreCase("audio/ogg")) filename += ".ogg"; else throw new Exception("Unsupported format"); URL url = new URL(intent.getStringExtra("url")); httpConnection = (HttpURLConnection) url.openConnection(); if (httpConnection.getResponseCode() != 200) throw new Exception("Failed to connect"); length = httpConnection.getContentLength(); lengthString = Utils.formatFileSize(length); input = httpConnection.getInputStream(); output = new FileOutputStream(filename); byte[] buffer = new byte[1024]; int read = 0; totalRead = 0; downloadInProgress = true; new NotificationThread().start(); while ((read = input.read(buffer)) > 0) { if (!downloadInProgress) { input.close(); throw new Exception(); } output.write(buffer, 0, read); totalRead += read; } intentCompleted.putExtra("success", true); PodcastEpisode.setDownloadedFile(idItem, filename); output.flush(); output.close(); } catch (Exception e) { new File(filename).delete(); PodcastEpisode.setDownloadCanceled(idItem); intentCompleted.putExtra("success", false); intentCompleted.putExtra("reason", e.getMessage()); showErrorNotification(e.getMessage()); } finally { try { httpConnection.disconnect(); } catch (Exception e) { } } downloadInProgress = false; unregisterReceiver(broadcastReceiver); sendBroadcast(intentCompleted); notificationManager.cancel(Constants.NOTIFICATION_PODCAST_ITEM_DOWNLOAD_ONGOING); }
From source file:com.comunidadesvirtualesonline.cvo_notificacines.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (estado1 == Servestado1) { Intent i = new Intent(this, com.comunidadesvirtualesonline.cvo_notificacines.Notificaciones.class); startActivity(i);/*from w w w.ja va2 s . c o m*/ } else if (estado2 == Servestado2) { Intent i = new Intent(this, com.comunidadesvirtualesonline.cvo_notificacines.inicio.class); startActivity(i); } mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); 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)); } } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, QuickstartPreferences.RegistrationIntentService.class); startService(intent); } }
From source file:com.binoy.vibhinna.VibhinnaFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true);// w w w. j a va2 s. c o m setEmptyText(getString(R.string.no_vfs_found)); registerForContextMenu(getListView()); if (!Constants.BINARY_FOLDER.exists() || Constants.BINARY_FOLDER.list().length < 4) { Constants.BINARY_FOLDER.mkdirs(); AssetsManager assetsManager = new AssetsManager(getActivity().getApplicationContext()); assetsManager.copyAssets(); } mLocalBroadcastManager = LocalBroadcastManager.getInstance(getActivity()); mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(VibhinnaService.ACTION_VFS_LIST_UPDATED)) { restartLoading(); } } }; resolver = getActivity().getContentResolver(); setHasOptionsMenu(true); startLoading(); }
From source file:net.atlaslearning.cordova.OpenIn.OpenIn.java
/** * Executes the request./*from ww w .java 2 s.co m*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @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.batteryCallbackContext != null) { callbackContext.error("Battery listener already running."); return true; } this.batteryCallbackContext = callbackContext; // We need to listen to power events to update battery status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateBatteryInfo(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } // 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")) { removeBatteryListener(); this.sendUpdate(new JSONObject(), false); // release status callback in JS side this.batteryCallbackContext = null; callbackContext.success(); return true; } return false; }