List of usage examples for android.content Intent getByteArrayExtra
public byte[] getByteArrayExtra(String name)
From source file:ja.keystore00.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 w w . ja v a 2 s. c o 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: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 w w . java2 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; 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.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;//from ww w. jav a 2s. c o 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; //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.kncwallet.wallet.service.BlockchainServiceImpl.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { String action = null;/*from www.j a v a 2 s. c o m*/ if (intent == null) { log.info("Blockchain service started with null intent"); } else { log.info("service start command: " + intent + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT) ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")" : "")); action = intent.getAction(); } if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) { notificationCount = 0; 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:com.BeeFramework.service.PushMessageReceiver.java
/** * * * @param context/*from w w w . j av a 2s . c o m*/ * Context * @param intent * intent */ @Override public void onReceive(final Context context, Intent intent) { shared = context.getSharedPreferences("userInfo", 0); editor = shared.edit(); if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) { //?? // String message = intent.getExtras().getString( // PushConstants.EXTRA_PUSH_MESSAGE_STRING); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // // //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_MESSAGE); // responseIntent.putExtra(SquaredActivity.EXTRA_MESSAGE, message); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); //?? //:PushManager.startWork()PushConstants.METHOD_BIND } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVE)) { //? final String method = intent.getStringExtra(PushConstants.EXTRA_METHOD); //?,???bind??bind,??startWork final int errorCode = intent.getIntExtra(PushConstants.EXTRA_ERROR_CODE, PushConstants.ERROR_SUCCESS); // final String content = new String(intent.getByteArrayExtra(PushConstants.EXTRA_CONTENT)); //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_RESPONSE); // responseIntent.putExtra(SquaredActivity.RESPONSE_METHOD, method); // responseIntent.putExtra(SquaredActivity.RESPONSE_ERRCODE, // errorCode); // responseIntent.putExtra(SquaredActivity.RESPONSE_CONTENT, content); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); if (errorCode == 0) { String appid = ""; String channelid = ""; String userid = ""; try { JSONObject jsonContent = new JSONObject(content); JSONObject params = jsonContent.getJSONObject("response_params"); appid = params.getString("appid"); channelid = params.getString("channel_id"); userid = params.getString("user_id"); editor.putString("UUID", userid); editor.commit(); } catch (JSONException e) { } } //?? } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVER_NOTIFICATION_CLICK)) { // String content = intent // .getStringExtra(PushConstants.EXTRA_NOTIFICATION_CONTENT); // // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_PUSHCLICK); // // // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // responseIntent.putExtra(SquaredActivity.CUSTOM_CONTENT, customContentString); // // context.startActivity(responseIntent); } }
From source file:de.schildbach.wallet.service.BlockchainService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { super.onStartCommand(intent, flags, 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 .jav a 2s . co m*/ notificationAccumulatedAmount = Coin.ZERO; notificationAddresses.clear(); nm.cancel(Constants.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 = Sha256Hash .wrap(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.zpci.firstsignhairclipdemo.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }/*from w w w. j a va2 s . com*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; case REQUEST_DIAG_CMD: if (resultCode == Activity.RESULT_OK) { byte[] value = data.getByteArrayExtra("cmd"); Log.d(TAG, "Diag command request success. length = " + value.length + ", 0x" + Integer.toHexString(value[0] & 0xff) + ", " + value[0]); if (value[0] == (byte) 0x05) { //alarm arm/disarm if (value[1] == (byte) 0x00) { armed = true; alarmsent = false; adStream.reset(); // reset audio data buffer expectedAudioSamples = ALARMAUDIOSAMPLES; // set to default number of samples SensorStream.reset(); // reset sensor data buffer expectedSensorSamples = ALARMSENSORSAMPLES; // set to default } else armed = false; } try { mService.writeRXCharacteristic(value); } catch (Exception e) { Log.e(TAG, e.toString()); } ; //Update the log with time stamp and message sent String msg = ""; for (int i = 0; i < value.length; i++) { msg = msg + "0x" + Integer.toHexString(value[i] & 0xff) + " "; } String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); listAdapter.add("[" + currentDateTimeString + "] TX: " + msg); messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); } else { Log.d(TAG, "Diag command request result fail"); } break; default: Log.e(TAG, "bad activity result request code"); break; } }
From source file:com.granita.tasks.notification.NotificationActionIntentService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @Override//from ww w. j a v a 2 s . c o m protected void onHandleIntent(Intent intent) { mAuthority = getString(R.string.org_dmfs_tasks_authority); final String action = intent.getAction(); final Context context = this; if (intent.hasExtra(EXTRA_NOTIFICATION_ID)) { Uri taskUri = intent.getData(); int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(notificationId); if (ACTION_COMPLETE.equals(action)) { markCompleted(taskUri); } else if (intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE)) { long due = intent.getLongExtra(EXTRA_TASK_DUE, -1); String tz = intent.getStringExtra(EXTRA_TIMEZONE); boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false); if (ACTION_DELAY_1H.equals(action)) { Time time = new Time(tz); time.set(due); time.allDay = false; time.hour++; time.normalize(true); delayTask(taskUri, time); } else if (ACTION_DELAY_1D.equals(action)) { if (tz == null) { tz = "UTC"; } Time time = new Time(tz); time.set(due); time.allDay = allDay; time.monthDay++; time.normalize(true); delayTask(taskUri, time); } } } else if (intent.hasExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION)) { /* * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent to add some extra data, it must unparcel the * NotificationAction object. It throws a ClassNotFoundException when unparcelling. To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { return; } if (NotificationActionUtils.ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); resendNotification(notificationAction); } else if (ACTION_COMPLETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(this, notificationAction); } else { if (NotificationActionUtils.ACTION_UNDO_TIMEOUT.equals(action) || NotificationActionUtils.ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); processDesctructiveNotification(notificationAction); } } } }
From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case PICK_IMAGE: if (resultCode == Activity.RESULT_OK) { if (mUriSavedFile == null) { setupUploadFile("jpg", false); }// w w w.j a v a2 s.c o m mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG; if (data != null && data.getData() != null) { final Uri selectedImage = data.getData(); setFileExtemsionFromUri(selectedImage); setAttachmentSelected(selectedImage); } else { setFileExtemsionFromUri(mUriSavedFile); setAttachmentSelected(mUriSavedFile); } } break; case PICK_VIDEO: if (resultCode == Activity.RESULT_OK) { if (mUriSavedFile == null) { setupUploadFile("mp4", false); } mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4; if (data != null && data.getData() != null) { final Uri selectedVideo = data.getData(); setFileExtemsionFromUri(selectedVideo); setAttachmentSelected(selectedVideo); } else { setFileExtemsionFromUri(mUriSavedFile); setAttachmentSelected(mUriSavedFile); } } break; case PICK_BUTTON: if (resultCode == Activity.RESULT_OK) { try { mCannedButtons = (CannedButtons) Pickler.createObjectFromPickle( data.getByteArrayExtra(SendMessageButtonActivity.CANNED_BUTTONS)); mButtons = new LinkedHashSet<>(); mButtonsContainer.removeAllViews(); long[] buttons = data.getLongArrayExtra(SendMessageButtonActivity.BUTTONS); if (buttons != null) { for (final long l : buttons) { mButtons.add(l); CannedButton cannedButton = mCannedButtons.getById(l); if (cannedButton == null) continue; final View previewButtonContainer = mActivity.getLayoutInflater() .inflate(R.layout.chat_container_message_button, null); final Button previewButton = (Button) previewButtonContainer.findViewById(R.id.button); previewButton.setText(cannedButton.getCaption()); previewButton.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mButtons.remove(l); mButtonsContainer.removeView(previewButtonContainer); } }); mButtonsContainer.addView(previewButtonContainer); } } } catch (Exception e) { L.bug(e); } } break; } }
From source file:org.microg.gms.gcm.McsService.java
private void handleSendMessage(Intent intent) { String messageId = intent.getStringExtra(EXTRA_MESSAGE_ID); String collapseKey = intent.getStringExtra(EXTRA_COLLAPSE_KEY); Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER); intent.removeExtra(EXTRA_MESSENGER); Parcelable app = intent.getParcelableExtra(EXTRA_APP); String packageName = null;/*from w w w . j a v a 2 s.c o m*/ if (app instanceof PendingIntent) { packageName = PackageUtils.packageFromPendingIntent((PendingIntent) app); } if (packageName == null) { Log.w(TAG, "Failed to send message, missing package name"); return; } intent.removeExtra(EXTRA_APP); int ttl; try { ttl = Integer.parseInt(intent.getStringExtra(EXTRA_TTL)); if (ttl < 0 || ttl > maxTtl) { ttl = maxTtl; } } catch (NumberFormatException e) { // TODO: error TtlUnsupported Log.w(TAG, e); return; } String to = intent.getStringExtra(EXTRA_SEND_TO); if (to == null) { // TODO: error missing_to Log.w(TAG, "missing to"); return; } String from = intent.getStringExtra(EXTRA_SEND_FROM); if (from != null) { intent.removeExtra(EXTRA_SEND_FROM); } else { from = intent.getStringExtra(EXTRA_FROM); } if (from == null) { GcmDatabase.Registration reg = database.getRegistration(packageName, PackageUtils.firstSignatureDigest(this, packageName)); if (reg != null) from = reg.registerId; } if (from == null) { Log.e(TAG, "Can't send message, missing from!"); return; } String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID); intent.removeExtra(EXTRA_REGISTRATION_ID); List<AppData> appData = new ArrayList<>(); Bundle extras = intent.getExtras(); for (String key : extras.keySet()) { if (!key.startsWith("google.")) { Object val = extras.get(key); if (val instanceof String) { appData.add(new AppData(key, (String) val)); } } } byte[] rawDataArray = intent.getByteArrayExtra("rawData"); ByteString rawData = rawDataArray != null ? ByteString.of(rawDataArray) : null; try { DataMessageStanza msg = new DataMessageStanza.Builder().sent(System.currentTimeMillis() / 1000L) .id(messageId).token(collapseKey).from(from).reg_id(registrationId).to(to).category(packageName) .raw_data(rawData).app_data(appData).build(); send(MCS_DATA_MESSAGE_STANZA_TAG, msg); database.noteAppMessage(packageName, msg.getSerializedSize()); } catch (Exception e) { Log.w(TAG, e); } }