List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java
@Override public void onNewIntent(Intent intent) { String action = intent.getAction(); LogUtils.v("GCM onNewIntent action" + action); if (CommunicationActivity.ACTION_OPEN_CHATBOX.equals(action)) { mRequestedChatboxId = intent.getIntExtra(CommunicationActivity.CHATBOX_ID, 0); LogUtils.v("GCM onNewIntent action mRequestedChatboxId " + mRequestedChatboxId); }/*w w w . j a va2s . c om*/ }
From source file:com.blu3f1re.reddwallet.service.BlockchainServiceImpl.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { log.info("service start command: " + intent + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT) ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")" : "")); final String action = intent.getAction(); if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) { notificationCount = 0;//ww w . ja va 2 s . co m notificationAccumulatedAmount = BigInteger.ZERO; notificationAddresses.clear(); nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) { log.info("will remove blockchain on service shutdown"); resetBlockchainOnShutdown = true; stopSelf(); } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) { final Sha256Hash hash = new Sha256Hash( intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH)); final Transaction tx = application.getWallet().getTransaction(hash); if (peerGroup != null) { log.info("broadcasting transaction " + tx.getHashAsString()); peerGroup.broadcastTransaction(tx); } else { log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString()); } } return START_NOT_STICKY; }
From source file:autobahn.demo.com.autobahndemo.EchoClientActivity.java
@Override protected void onResume() { super.onResume(); mReceiver = new BroadcastReceiver() { @Override//from ww w . j a v a 2s.co m public void onReceive(Context context, Intent intent) { boolean isConnectionLost = intent.getBooleanExtra("IsConnectionLost", false); boolean isConnectionOpen = intent.getBooleanExtra("IsConnectionOpen", false); boolean isMessageReceived = intent.getBooleanExtra("IsMessageReceived", false); if (isConnectionOpen) { mStatusline.setText("Status: Connected to " + ApplicationController.WS_URI); savePrefs(); mSendMessage.setEnabled(true); mMessage.setEnabled(true); mConnection.sendPingMessage(PING.getBytes()); } if (isConnectionLost) { String reason = intent.getStringExtra("Reason"); int code = intent.getIntExtra("CODE", 0); alert("Connection lost. " + reason); mStatusline.setText("Status: " + getTime() + " " + code + " " + reason); setButtonConnect(); } if (isMessageReceived) { String message = intent.getStringExtra("message"); Log.d(TAG, message); mTvEchoMessage.setText(message); messages.add(getTime() + " " + message); String[] messsagesArray = new String[messages.size()]; messsagesArray = messages.toArray(messsagesArray); ArrayAdapter<String> adapter = new ArrayAdapter<String>(EchoClientActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, messsagesArray); // ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2, messages); mListView.setAdapter(adapter); } } }; IntentFilter intentFilter = new IntentFilter("MESSAGE"); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, intentFilter); }
From source file:com.cannabiscoin.wallet.service.BlockchainServiceImpl.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { log.info("service start command: " + intent + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT) ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")" : "")); final String action = intent.getAction(); if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) { notificationCount = 0;/*ww w . j a va2 s . c om*/ notificationAccumulatedAmount = BigInteger.ZERO; notificationAddresses.clear(); nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) { log.info("will remove blockchain on service shutdown"); resetBlockchainOnShutdown = true; //WalletApplication.scheduleStartBlockchainService(this); //disconnect feature stopSelf(); } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) { final Sha256Hash hash = new Sha256Hash( intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH)); final Transaction tx = application.getWallet().getTransaction(hash); if (peerGroup != null) { log.info("broadcasting transaction " + tx.getHashAsString()); peerGroup.broadcastTransaction(tx); } else { log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString()); } } else if (BlockchainService.ACTION_STOP_SERVICE.equals(action)) { log.info("stopping self"); // deliberate stop command, so don't schedule restart stopSelf(); } return START_NOT_STICKY; }
From source file:com.dellingertech.andevcon.mocklocationprovider.SendMockLocationService.java
@Override public int onStartCommand(Intent startIntent, int flags, int startId) { // Get the type of test to run mTestRequest = startIntent.getAction(); /*/* w w w . j a v a 2s . co m*/ * If the incoming Intent was a request to run a one-time or continuous test */ if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE)) || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) { // Get the pause interval and injection interval mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2); mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1); // Post a notification in the notification bar that a test is starting postNotification(getString(R.string.notification_content_test_start)); // Create a location client mLocationClient = new LocationClient(this, this, this); // Start connecting to Location Services mLocationClient.connect(); } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) { // Remove any existing notifications removeNotification(); // Send a message back to the main activity that the test is stopping sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0); // Stop this Service stopSelf(); } /* * Tell the system to keep the Service alive, but to discard the Intent that * started the Service */ return Service.START_STICKY; }
From source file:com.dm.wallpaper.board.activities.WallpaperBoardActivity.java
@Override public void onWallpapersChecked(@Nullable Intent intent) { if (intent != null) { String packageName = intent.getStringExtra("packageName"); LogUtil.d("Broadcast received from service with packageName: " + packageName); if (packageName == null) return; if (!packageName.equals(getPackageName())) { LogUtil.d("Received broadcast from different packageName, expected: " + getPackageName()); return; }//from w w w.j a v a 2 s . c om int size = intent.getIntExtra(Extras.EXTRA_SIZE, 0); int offlineSize = Database.get(this).getWallpapersCount(); Preferences.get(this).setAvailableWallpapersCount(size); if (size > offlineSize) { int accent = ColorHelper.getAttributeColor(this, R.attr.colorAccent); LinearLayout container = (LinearLayout) mNavigationView.getMenu().getItem(0).getActionView(); if (container != null) { TextView counter = (TextView) container.findViewById(R.id.counter); if (counter == null) return; ViewCompat.setBackground(counter, DrawableHelper.getTintedDrawable(this, R.drawable.ic_toolbar_circle, accent)); counter.setTextColor(ColorHelper.getTitleTextColor(accent)); int newItem = (size - offlineSize); counter.setText(String.valueOf(newItem > 99 ? "99+" : newItem)); container.setVisibility(View.VISIBLE); if (mFragmentTag.equals(Extras.TAG_WALLPAPERS)) { WallpapersFragment fragment = (WallpapersFragment) mFragManager .findFragmentByTag(Extras.TAG_WALLPAPERS); if (fragment != null) fragment.showPopupBubble(); } return; } } } LinearLayout container = (LinearLayout) mNavigationView.getMenu().getItem(0).getActionView(); if (container != null) container.setVisibility(View.GONE); }
From source file:com.aegiswallet.actions.MainActivity.java
private void setupBlockchainBroadcastReceiver(final TextView blockchainStatus) { receiver = new BroadcastReceiver() { @Override/*w w w . j a va 2 s . com*/ public void onReceive(Context context, Intent intent) { int download = intent.getIntExtra(PeerBlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD, PeerBlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK); Date bestChainDate = (Date) intent .getSerializableExtra(PeerBlockchainService.ACTION_BLOCKCHAIN_STATE_BEST_CHAIN_DATE); long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; boolean downloadOk = download == PeerBlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK; String downloading = downloadOk ? getString(R.string.synchronizing_network) : getString(R.string.sync_stalled); Date currentDate = new Date(); long daysOutOfDate = TimeUnit.MILLISECONDS.toDays(currentDate.getTime() - bestChainDate.getTime()) + 1; if (!blockchainUptodate) { blockchainStatus.setText( downloading + " " + daysOutOfDate + " " + getString(R.string.sync_days_behind)); blockchainStatus.setTextColor(getResources().getColor(R.color.custom_red)); } else { blockchainStatus.setText(getString(R.string.sync_completed)); blockchainStatus.setTextColor(getResources().getColor(R.color.custom_green)); } updateMainViews(); } }; }
From source file:io.scalac.locationprovider.SendMockLocationService.java
@Override public int onStartCommand(Intent startIntent, int flags, int startId) { // Get the type of test to run mTestRequest = startIntent.getAction(); /*/*from w ww .j a va2 s . com*/ * If the incoming Intent was a request to run a one-time or continuous test */ if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE)) || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) { // Get the pause interval and injection interval mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2); mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1); mMockId = startIntent.getStringExtra(LocationUtils.EXTRA_MOCK_ID); // Post a notification in the notification bar that a test is starting postNotification(getString(R.string.notification_content_test_start)); // Create a location client mLocationClient = new LocationClient(this, this, this); // Start connecting to Location Services mLocationClient.connect(); } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) { // Remove any existing notifications removeNotification(); // Send a message back to the main activity that the test is stopping sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0); // Stop this Service stopSelf(); } /* * Tell the system to keep the Service alive, but to discard the Intent that * started the Service */ return Service.START_STICKY; }
From source file:com.bushstar.htmlcoin_android_wallet.service.BlockchainServiceImpl.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent != null) { log.info("service start command: " + intent + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT) ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")" : "")); final String action = intent.getAction(); if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) { notificationCount = 0;/*from w ww. j a v a 2 s .co m*/ notificationAccumulatedAmount = BigInteger.ZERO; notificationAddresses.clear(); nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) { log.info("will remove blockchain on service shutdown"); resetBlockchainOnShutdown = true; stopSelf(); } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) { final Sha256Hash hash = new Sha256Hash( intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH)); final Transaction tx = application.getWallet().getTransaction(hash); if (peerGroup != null) { log.info("broadcasting transaction " + tx.getHashAsString()); peerGroup.broadcastTransaction(tx); } else { log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString()); } } } else { log.warn("service restart, although it was started as non-sticky"); } return START_NOT_STICKY; }
From source file:com.layer8apps.CalendarHandler.java
/************ * PURPOSE: Handles the primary thread in the service * ARGUMENTS: Intent intent/*from ww w. java 2 s. co m*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ @Override protected void onHandleIntent(Intent intent) { // Get our stored data from the intent username = intent.getStringExtra("username"); password = intent.getStringExtra("password"); messenger = (Messenger) intent.getExtras().get("handler"); calID = intent.getIntExtra("calendarID", -1); String url = getApplicationContext().getResources().getString(R.string.url); // Create variables to be used through the application List<String[]> workDays = null; ConnectionManager conn = ConnectionManager.newConnection(); /************ * Once we verify that we have a valid token, we get the actual schedule *************/ updateStatus("Logging in..."); String tempToken = conn.getData(url + "/etm/login.jsp"); if (tempToken != null) { loginToken = parseToken(tempToken); } else { showError("Error connecting to MyTLC, make sure you have a valid network connection"); return; } String postResults = null; // This creates our login information List<NameValuePair> parameters = createParams(); if (loginToken != null) { // Here we send the information to the server and login postResults = conn.postData(url + "/etm/login.jsp", parameters); } else { showError("Error retrieving your login token"); return; } if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp") && !postResults.toLowerCase().contains("<font size=\"2\">")) { updateStatus("Retrieving schedule..."); postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp"); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error logging in, please verify your username and password"); } return; } // If we successfully got the information, then parse out the schedule to read it properly String secToken = null; if (postResults != null) { updateStatus("Parsing schedule..."); workDays = parseSchedule(postResults); secToken = parseSecureToken(postResults); wbat = parseWbat(postResults); } else { showError("Could not obtain user schedule"); return; } if (secToken != null) { parameters = createSecondParams(secToken); postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error retrieving your security token"); } return; } List<String[]> secondMonth = null; if (postResults != null) { secondMonth = parseSchedule(postResults); } else { showError("Could not obtain user schedule"); return; } if (secondMonth != null) { if (workDays == null) { workDays = secondMonth; } else { workDays.addAll(secondMonth); } finalDays = workDays; } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("There was an error retrieving your schedule"); } return; } // Add our shifts to the calendar updateStatus("Adding shifts to calendar..."); int numShifts = addDays(); if (finalDays != null && numShifts > -1) { // Report back that we're successful! Message msg = Message.obtain(); Bundle b = new Bundle(); b.putString("status", "DONE"); b.putInt("count", numShifts); msg.setData(b); try { messenger.send(msg); } catch (Exception e) { // Nothing } } else { showError("Couldn't add your shifts to your calendar"); } }