List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.abroad.ruianju.im.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/*from w ww . j a v a 2s. 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.hhunj.hhudata.SearchBookContentsActivity.java
private void sendSMS(String phoneNumber, String message) { // ---sends an SMS message to another device--- SmsManager sms = SmsManager.getDefault(); String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; // create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); // register the Broadcast Receivers registerReceiver(new BroadcastReceiver() { @Override/*from www.j ava 2 s . c o m*/ public void onReceive(Context _context, Intent _intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT_SMS_ACTION)); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show(); } }, new IntentFilter(DELIVERED_SMS_ACTION)); // if message's length more than 70 , // then call divideMessage to dive message into several part ,and call // sendTextMessage() // else direct call sendTextMessage() if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(phoneNumber, null, message, sentPI, deliverPI); } }
From source file:com.nttec.everychan.ui.tabs.TabsTrackerService.java
@Override public void onCreate() { Logger.d(TAG, "TabsTrackerService creating"); super.onCreate(); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); settings = MainApplication.getInstance().settings; tabsState = MainApplication.getInstance().tabsState; tabsSwitcher = MainApplication.getInstance().tabsSwitcher; pagesCache = MainApplication.getInstance().pagesCache; registerReceiver(broadcastReceiver = new BroadcastReceiver() { @Override/*from ww w . j a v a 2s . c om*/ public void onReceive(Context context, Intent intent) { Logger.d(TAG, "received BROADCAST_ACTION_CLEAR_SUBSCRIPTIONS"); clearSubscriptions(); } }, new IntentFilter(BROADCAST_ACTION_CLEAR_SUBSCRIPTIONS)); }
From source file:com.futureplatforms.kirin.extensions.networking.NetworkingBackend.java
private void listenForChangeInNetworkStatus() { Log.i(C.TAG, "NetworkingBackend.listenForChangeInNetworkStatus: "); mReceiver = new BroadcastReceiver() { @Override/* w w w . j av a 2 s. c o m*/ public void onReceive(Context context, Intent intent) { if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON); if (reason == null || reason.trim().length() == 0) { reason = mContext.getString(R.string.networking_connection_lost); } cancelAllDownloads(reason); } } }; mContext.registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:cc.echonet.coolmicapp.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home);/*from www . j a v a2 s . c o m*/ timerValue = (TextView) findViewById(R.id.timerValue); BroadcastReceiver mPowerKeyReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String strAction = intent.getAction(); if (strAction.equals(Intent.ACTION_SCREEN_OFF) || strAction.equals(Intent.ACTION_SCREEN_ON) || strAction.equals(Intent.ACTION_USER_PRESENT)) { if (isThreadOn) { RedFlashLight(); } } } }; final IntentFilter theFilter = new IntentFilter(); /** System Defined Broadcast */ theFilter.addAction(Intent.ACTION_SCREEN_ON); theFilter.addAction(Intent.ACTION_SCREEN_OFF); theFilter.addAction(Intent.ACTION_USER_PRESENT); getApplicationContext().registerReceiver(mPowerKeyReceiver, theFilter); imageView1 = (ImageView) findViewById(R.id.imageView1); Log.v("onCreate", (imageView1 == null ? "iv null" : "iv ok")); android.view.ViewGroup.LayoutParams layoutParams = imageView1.getLayoutParams(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { layoutParams.height = 400; } else { layoutParams.height = 180; } imageView1.setLayoutParams(layoutParams); myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); animation.setDuration(500); // duration - half a second animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely animation.setRepeatMode(Animation.REVERSE); start_button = (Button) findViewById(R.id.start_recording_button); stop_button = (Button) findViewById(R.id.stop_recording_button); buttonColor = start_button.getBackground(); logArea = (TextView) findViewById(R.id.log_area); logArea.setMovementMethod(new ScrollingMovementMethod()); coolmic = new CoolMic(this, "default"); if (Wrapper.getState() == Wrapper.WrapperInitializationStatus.WRAPPER_UNINITIALIZED) { if (Wrapper.init() == Wrapper.WrapperInitializationStatus.WRAPPER_INITIALIZATION_ERROR) { Log.d("WrapperInit", Wrapper.getInitException().toString()); Toast.makeText(getApplicationContext(), "Could not initialize native components :( Blocking controls!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Native components initialized!", Toast.LENGTH_SHORT) .show(); } } else if (Wrapper.init() == Wrapper.WrapperInitializationStatus.WRAPPER_INITIALIZATION_ERROR) { Toast.makeText(getApplicationContext(), "Previous problem detected with native components :( Blocking controls!", Toast.LENGTH_SHORT) .show(); } else if (Wrapper.init() != Wrapper.WrapperInitializationStatus.WRAPPER_INTITIALIZED) { Toast.makeText(getApplicationContext(), "Native components in unknown state!", Toast.LENGTH_SHORT) .show(); } txtListeners = (TextView) findViewById(R.id.txtListeners); IntentFilter mStatusIntentFilter = new IntentFilter(Constants.BROADCAST_STREAM_STATS_SERVICE); LocalBroadcastManager.getInstance(this).registerReceiver(mStreamStatsReceiver, mStatusIntentFilter); }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadListFragment.java
/** * Initializes our fragment with various variables, displays the threads, * sets up a onItemClickListener so the user is sent to the appropriate * thread when they click on it, then sorts the threads according to the * method the user has chosen./*from w w w. j ava2 s .c o m*/ */ @Override public void onStart() { super.onStart(); if (locationListener == null) { locationListener = new LocationListenerService(getActivity()); } if (prefManager == null) { prefManager = PreferencesManager.getInstance(); } if (cacheManager == null) { cacheManager = CacheManager.getInstance(); } threadListView = (PullToRefreshListView) getActivity().findViewById(R.id.thread_list); // On start, get the threadList from the cache ArrayList<ThreadComment> list = cacheManager.deserializeThreadList(); ThreadList.setThreads(list); adapter = new ThreadListAdapter(getActivity(), ThreadList.getThreads()); threadListView.setEmptyView(getActivity().findViewById(R.id.empty_list_view)); threadListView.setAdapter(adapter); threadListView.setOnItemClickListener(new OnItemClickListener() { @Override /* * On click, launch the fragment responsible for thread viewing */ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Fragment fragment = new ThreadViewFragment(); Bundle bundle = new Bundle(); bundle.putParcelable("thread", ThreadList.getThreads().get((int) id)); bundle.putLong("id", id); fragment.setArguments(bundle); getFragmentManager().beginTransaction() .replace(R.id.fragment_container, fragment, "thread_view_fragment") .addToBackStack("thread_view_fragment").commit(); getFragmentManager().executePendingTransactions(); } }); int sort = prefManager.getThreadSort(); SortUtil.sortThreads(sort, ThreadList.getThreads()); //setSortCheck(sort); adapter.notifyDataSetChanged(); threadListView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { if (!connectHelper.isConnected()) { Toaster.toastShort("No network connection."); threadListView.onRefreshComplete(); } else { reload(); } } }); // Toggle PullToRefresh programatically on start if (!refresh && connectHelper.isConnected()) { threadListView.setRefreshing(); ThreadManager.startGetThreadComments(this); refresh = true; } updateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isVisible() && connectHelper.getWasNotConnected() == true) { connectHelper.setWasNotConnected(false); UpdateDialogFragment fragment = new UpdateDialogFragment(); fragment.show(getFragmentManager(), "updateDialogFrag"); } } }; getActivity().getApplicationContext().registerReceiver(updateReceiver, new IntentFilter(ConnectivityBroadcastReceiver.UPDATE_FROM_SERVER_INTENT)); }
From source file:com.easemob.chatuidemo.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); broadcastReceiver = new BroadcastReceiver() { @Override//from w ww .ja v a 2 s.c om 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(MainActivity.this).equals(GroupsActivity.class.getName())) { GroupsActivity.instance.onResume(); } } } }; broadcastManager.registerReceiver(broadcastReceiver, intentFilter); }
From source file:com.thomasokken.free42.Free42Activity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; int init_mode; IntHolder version = new IntHolder(); try {// w ww .j av a 2 s. c o m stateFileInputStream = openFileInput("state"); } catch (FileNotFoundException e) { stateFileInputStream = null; } if (stateFileInputStream != null) { if (read_shell_state(version)) init_mode = 1; else { init_shell_state(-1); init_mode = 2; } } else { init_shell_state(-1); init_mode = 0; } setAlwaysRepaintFullDisplay(alwaysRepaintFullDisplay); if (alwaysOn) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (style == 1) setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); else if (style == 2) { try { Method m = View.class.getMethod("setSystemUiVisibility", int.class); m.invoke(getWindow().getDecorView(), PreferencesDialog.immersiveModeFlags); } catch (Exception e) { } } Configuration conf = getResources().getConfiguration(); orientation = conf.orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 0; mainHandler = new Handler(); calcView = new CalcView(this); setContentView(calcView); printView = new PrintView(this); printScrollView = new ScrollView(this); printScrollView.setBackgroundColor(PRINT_BACKGROUND_COLOR); printScrollView.addView(printView); skin = null; if (skinName[orientation].length() == 0 && externalSkinName[orientation].length() > 0) { try { skin = new SkinLayout(externalSkinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { } } if (skin == null) { try { skin = new SkinLayout(skinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { } } if (skin == null) { try { skin = new SkinLayout(builtinSkinNames[0], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { // This one should never fail; we're loading a built-in skin. } } nativeInit(); core_init(init_mode, version.value); if (stateFileInputStream != null) { try { stateFileInputStream.close(); } catch (IOException e) { } stateFileInputStream = null; } lowBatteryReceiver = new BroadcastReceiver() { public void onReceive(Context ctx, Intent intent) { low_battery = intent.getAction().equals(Intent.ACTION_BATTERY_LOW); Rect inval = skin.update_annunciators(-1, -1, -1, -1, low_battery ? 1 : 0, -1, -1); if (inval != null) calcView.postInvalidateScaled(inval.left, inval.top, inval.right, inval.bottom); } }; IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_BATTERY_LOW); iff.addAction(Intent.ACTION_BATTERY_OKAY); registerReceiver(lowBatteryReceiver, iff); if (preferredOrientation != this.getRequestedOrientation()) setRequestedOrientation(preferredOrientation); soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); int[] soundResourceIds = { R.raw.tone0, R.raw.tone1, R.raw.tone2, R.raw.tone3, R.raw.tone4, R.raw.tone5, R.raw.tone6, R.raw.tone7, R.raw.tone8, R.raw.tone9, R.raw.squeak, R.raw.click }; soundIds = new int[soundResourceIds.length]; for (int i = 0; i < soundResourceIds.length; i++) soundIds[i] = soundPool.load(this, soundResourceIds[i], 1); }
From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log_OC.d(TAG, "onCreate() start"); // Log.d(TAG,"called first"); super.onCreate(savedInstanceState); // this calls onAccountChanged() // when ownCloud Account is valid // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); if (AccountUtils.getCurrentOwnCloudAccount(getBaseContext()) != null) { Intent intent = new Intent(this, InitialPageActivity.class); startActivity(intent);//from w w w. j av a 2s . c o m } mHandler = new Handler(); // / bindings to transference services mUploadConnection = new ListServiceConnection(); mDownloadConnection = new ListServiceConnection(); bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE); bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE); shareNotifier = new NotificationCompat.Builder(this).setContentTitle("File Shared") .setSmallIcon(R.drawable.icon); Button shareButton = (Button) findViewById(R.id.shareItem); Intent fileShareIntent = new Intent(this, FileDisplayActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, fileShareIntent, 0); shareNotifier.setContentIntent(pIntent); shareNotifier.setAutoCancel(true); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); dataSource = new DbFriends(this); // ContentResolver.setIsSyncable(getAccount(), // AccountAuthenticator.AUTHORITY, 1); // ContentResolver.setSyncAutomatically(getAccount(), // AccountAuthenticator.AUTHORITY,true); // broadcast receiver that is called by the service which downloads the // files to the phone instantdownloadreceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String message = intent.getStringExtra("message"); instantDownloadFile(); // make the http request and update the ui to include the sharer // information // unregisterReceiver(instantdownloadreceiver); } }; // PIN CODE request ; best location is to decide, let's try this first if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) { requestPinCode(); } // / file observer Intent observer_intent = new Intent(this, FileObserverService.class); observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST); startService(observer_intent); // / Load of saved instance state if (savedInstanceState != null) { mWaitingToPreview = (OCFile) savedInstanceState .getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW); } else { mWaitingToPreview = null; } // / USER INTERFACE // Inflate and set the layout view setContentView(R.layout.files); mDualPane = getResources().getBoolean(R.bool.large_land_layout); mLeftFragmentContainer = findViewById(R.id.left_fragment_container); mRightFragmentContainer = findViewById(R.id.right_fragment_container); if (savedInstanceState == null) { createMinFragments(); } // Action bar setup mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item); getSupportActionBar().setHomeButtonEnabled(true); // mandatory since // Android ICS, // according to the // official // documentation setSupportProgressBarIndeterminateVisibility(false); // always AFTER // setContentView(...) // ; to work around // bug in its // implementation Log_OC.d(TAG, "onCreate() end"); }
From source file:com.oakesville.mythling.MediaActivity.java
private void registerPlaybackReceiver() { if (playbackReceiver == null) { playbackReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { showStopMenuItem(false); }/*from ww w.ja v a 2 s . c o m*/ }; } registerReceiver(playbackReceiver, new IntentFilter(MusicPlaybackService.ACTION_PLAYBACK_STOPPED)); }