Java Code Examples for android.content.Intent.getByteArrayExtra()

The following are Jave code examples for showing how to use getByteArrayExtra() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: IntentServiceSample.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // switch() doesn't support strings in older JDK.
    if (ACTION_START.equals(action)) {
        clearOutputs();
        addView(getColoredView(LIGHTBLUE, "Request started"));
    } else if (ACTION_FINISH.equals(action)) {
        addView(getColoredView(LIGHTBLUE, "Request finished"));
    } else if (ACTION_CANCEL.equals(action)) {
        addView(getColoredView(LIGHTBLUE, "Request cancelled"));
    } else if (ACTION_RETRY.equals(action)) {
        addView(getColoredView(LIGHTBLUE, "Request retried"));
    } else if (ACTION_FAILURE.equals(action) || ACTION_SUCCESS.equals(action)) {
        debugThrowable(LOG_TAG, (Throwable) intent.getSerializableExtra(ExampleIntentService.INTENT_THROWABLE));
        if (ACTION_SUCCESS.equals(action)) {
            debugStatusCode(LOG_TAG, intent.getIntExtra(ExampleIntentService.INTENT_STATUS_CODE, 0));
            debugHeaders(LOG_TAG, IntentUtil.deserializeHeaders(intent.getStringArrayExtra(ExampleIntentService.INTENT_HEADERS)));
            byte[] returnedBytes = intent.getByteArrayExtra(ExampleIntentService.INTENT_DATA);
            if (returnedBytes != null) {
                debugResponse(LOG_TAG, new String(returnedBytes));
            }
        }
    }
}
 
Example 2
Project: mobile-store   File: IntentIntegrator.java   View Source Code Vote up 7 votes
/**
 * <p>Call this from your {@link Activity}'s
 * {@link Activity#onActivityResult(int, int, Intent)} method.</p>
 *
 * @param requestCode request code from {@code onActivityResult()}
 * @param resultCode result code from {@code onActivityResult()}
 * @param intent {@link Intent} from {@code onActivityResult()}
 * @return null if the event handled here was not related to this class, or
 *  else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
 *  the fields will be null.
 */
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
            byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
            int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
            Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
            String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
            return new IntentResult(contents,
                    formatName,
                    rawBytes,
                    orientation,
                    errorCorrectionLevel);
        }
        return new IntentResult();
    }
    return null;
}
 
Example 3
Project: OpenYOLO-Android   File: IntentProtocolBufferExtractor.java   View Source Code Vote up 7 votes
/**
 * Attempts to extract a protocol buffer from the specified extra.
 * @throws MalformedDataException if the intent is null, the extra is missing or not a byte
 *     array, or the protocol buffer could not be parsed.
 */
@NonNull
public static <T extends MessageLite> T extract(
        @NonNull String extraName,
        @NonNull Parser<T> protoParser,
        @NonNull String failureDescription,
        @Nullable Intent intent)
        throws MalformedDataException {

    if (intent == null) {
        throw new MalformedDataException(failureDescription);
    }

    byte[] protoBytes = intent.getByteArrayExtra(extraName);
    if (protoBytes == null) {
        throw new MalformedDataException(failureDescription);
    }

    try {
        return protoParser.parseFrom(protoBytes);
    } catch (IOException ex) {
        throw new MalformedDataException(failureDescription, ex);
    }
}
 
Example 4
Project: Nird2   File: RevealContactsActivity.java   View Source Code Vote up 7 votes
@Override
@SuppressWarnings("ConstantConditions")
public void onCreate(@Nullable Bundle bundle) {
	super.onCreate(bundle);

	Intent i = getIntent();
	byte[] b = i.getByteArrayExtra(GROUP_ID);
	if (b == null) throw new IllegalStateException("No GroupId");
	groupId = new GroupId(b);

	button = (Button) findViewById(R.id.revealButton);
	button.setOnClickListener(this);
	button.setEnabled(false);

	if (bundle == null) {
		showInitialFragment(RevealContactsFragment.newInstance(groupId));
	}
}
 
Example 5
Project: Nird2   File: GroupMemberListActivity.java   View Source Code Vote up 7 votes
@Override
public void onCreate(@Nullable final Bundle state) {
	super.onCreate(state);

	setContentView(R.layout.activity_sharing_status);

	Intent i = getIntent();
	byte[] b = i.getByteArrayExtra(GROUP_ID);
	if (b == null) throw new IllegalStateException("No GroupId in intent.");
	groupId = new GroupId(b);

	list = (BriarRecyclerView) findViewById(R.id.list);
	LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
	list.setLayoutManager(linearLayoutManager);
	adapter = new MemberListAdapter(this);
	list.setAdapter(adapter);

	TextView info = (TextView) findViewById(R.id.info);
	info.setText(R.string.sharing_status_groups);
}
 
Example 6
Project: ZxingForAndroid   File: IntentIntegrator.java   View Source Code Vote up 7 votes
/**
 * <p>Call this from your {@link Activity}'s
 * {@link Activity#onActivityResult(int, int, Intent)} method.</p>
 *
 * @param requestCode request code from {@code onActivityResult()}
 * @param resultCode  result code from {@code onActivityResult()}
 * @param intent      {@link Intent} from {@code onActivityResult()}
 * @return null if the event handled here was not related to this class, or
 * else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
 * the fields will be null.
 */
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            String contents = intent.getStringExtra(Intents.Scan.RESULT);
            String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
            byte[] rawBytes = intent.getByteArrayExtra(Intents.Scan.RESULT_BYTES);
            int intentOrientation = intent.getIntExtra(Intents.Scan.RESULT_ORIENTATION, Integer.MIN_VALUE);
            Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
            String errorCorrectionLevel = intent.getStringExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL);
            String barcodeImagePath = intent.getStringExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH);
            return new IntentResult(contents,
                    formatName,
                    rawBytes,
                    orientation,
                    errorCorrectionLevel,
                    barcodeImagePath);
        }
        return new IntentResult();
    }
    return null;
}
 
Example 7
Project: ecam-app-android   File: IntentIntegrator.java   View Source Code Vote up 7 votes
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
            byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
            int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
            Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
            String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
            return new IntentResult(contents,
                    formatName,
                    rawBytes,
                    orientation,
                    errorCorrectionLevel);
        }
        return new IntentResult();
    }
    return null;
}
 
Example 8
Project: OpenYOLO-Android   File: HintRetrieveResultTest.java   View Source Code Vote up 7 votes
@Test
public void toResultIntentData() throws Exception {
    HintRetrieveResult result = new HintRetrieveResult.Builder(
            HintRetrieveResult.CODE_HINT_SELECTED)
            .setHint(HINT)
            .setAdditionalProperties(ValidAdditionalProperties.make())
            .build();

    Intent intent = result.toResultDataIntent();
    assertThat(intent.hasExtra(ProtocolConstants.EXTRA_HINT_RESULT));
    byte[] data = intent.getByteArrayExtra(ProtocolConstants.EXTRA_HINT_RESULT);

    HintRetrieveResult readResult = HintRetrieveResult.fromProtobufBytes(data);
    assertThat(readResult.getResultCode()).isEqualTo(HintRetrieveResult.CODE_HINT_SELECTED);
    assertThat(readResult.getHint()).isNotNull();
    ValidAdditionalProperties.assertEquals(readResult.getAdditionalProperties());
}
 
Example 9
Project: Nird2   File: GroupMemberListActivity.java   View Source Code Vote up 7 votes
@Override
public void onCreate(@Nullable final Bundle state) {
	super.onCreate(state);

	setContentView(R.layout.activity_sharing_status);

	Intent i = getIntent();
	byte[] b = i.getByteArrayExtra(GROUP_ID);
	if (b == null) throw new IllegalStateException("No GroupId in intent.");
	groupId = new GroupId(b);

	list = (BriarRecyclerView) findViewById(R.id.list);
	LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
	list.setLayoutManager(linearLayoutManager);
	adapter = new MemberListAdapter(this);
	list.setAdapter(adapter);

	TextView info = (TextView) findViewById(R.id.info);
	info.setText(R.string.sharing_status_groups);
}
 
Example 10
Project: mDL-ILP   File: AbstractLicenseActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    byte[] deviceEngagementData = intent.getByteArrayExtra("deviceEngagement");
    try {
        deviceEngagement = new DeviceEngagement(new TLVData(deviceEngagementData));
    } catch (IOException e) {
        e.printStackTrace();
    }

    final InterchangeProfile transferInterchange = deviceEngagement.getTransferInterchangeProfile();
    dataMinimizationParameter = deviceEngagement.getInterfaceIndependentProfile().dataMinimizationParameter;

    progressDialog = createTransferProgressDialog(transferInterchange);
    progressDialog.show();

    if (transferInterchange instanceof InterchangeProfileBLE) {
        connection = new BLEConnection(this, ((InterchangeProfileBLE) transferInterchange).antiCollisionIdentifier);
    } else if (transferInterchange instanceof InterchangeProfileNFC) {
        connection = new NFCLicenseTransferConnection(this);
    } else if (transferInterchange instanceof InterchangeProfileWD) {
        connection = new WiFiDirectConnection(this, ((InterchangeProfileWD) transferInterchange).MAC);
    } else {
        throw new UnsupportedOperationException("transferInterchange not supported");
    }
}
 
Example 11
Project: OpenYOLO-Android   File: BroadcastQueryClient.java   View Source Code Vote up 6 votes
@Override
public void onReceive(Context context, Intent intent) {
    byte[] responseBytes = intent.getByteArrayExtra(QueryUtil.EXTRA_RESPONSE_MESSAGE);
    if (responseBytes == null) {
        Log.w(LOG_TAG, "Received query response without a defined message");
        return;
    }

    BroadcastQueryResponse response;
    try {
        response = BroadcastQueryResponse.parseFrom(responseBytes);
    } catch (IOException e) {
        Log.w(LOG_TAG, "Unable to parse query response message");
        return;
    }

    String responder = mPendingQuery.mRespondersById.get(response.getResponseId());
    if (responder == null) {
        Log.w(LOG_TAG, "Received response from unknown responder");
        return;
    }

    if (!mPendingQuery.mPendingResponses.remove(response.getResponseId())) {
        Log.w(LOG_TAG, "Duplicate response received; ignoring");
        return;
    }

    if (response.getResponseMessage() != null) {
        QueryResponse queryResponse = new QueryResponse(
                responder,
                response.getResponseId(),
                response.getResponseMessage().toByteArray());
        mPendingQuery.mResponses.put(responder, queryResponse);
    }

    if (mPendingQuery.mPendingResponses.isEmpty()) {
        mPendingQuery.complete();
    }
}
 
Example 12
Project: q-mail   File: PgpMessageBuilder.java   View Source Code Vote up 6 votes
private void mimeBuildSignedMessage(@NonNull BodyPart signedBodyPart, Intent result) throws MessagingException {
    if (!cryptoStatus.isSigningEnabled()) {
        throw new IllegalStateException("call to mimeBuildSignedMessage while signing isn't enabled!");
    }

    byte[] signedData = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
    if (signedData == null) {
        throw new MessagingException("didn't find expected RESULT_DETACHED_SIGNATURE in api call result");
    }

    MimeMultipart multipartSigned = createMimeMultipart();
    multipartSigned.setSubType("signed");
    multipartSigned.addBodyPart(signedBodyPart);
    multipartSigned.addBodyPart(
            new MimeBodyPart(new BinaryMemoryBody(signedData, MimeUtil.ENC_7BIT),
                    "application/pgp-signature; name=\"signature.asc\""));
    MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartSigned);

    String contentType = String.format(
            "multipart/signed; boundary=\"%s\";\r\n  protocol=\"application/pgp-signature\"",
            multipartSigned.getBoundary());
    if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG)) {
        String micAlgParameter = result.getStringExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG);
        contentType += String.format("; micalg=\"%s\"", micAlgParameter);
    } else {
        Timber.e("missing micalg parameter for pgp multipart/signed!");
    }
    currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
 
Example 13
Project: fruit   File: FruitActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fruit);
    Intent intent = getIntent();
    String fruitName = intent.getStringExtra(FRUIT_NAME);
    int fruitImageId = intent.getIntExtra(FRUIT_IMAGE_ID, 0);
    String fruitinfo = intent.getStringExtra(FRUIT_INFO);
    byte[] in = intent.getByteArrayExtra(FRUIT_IMAGE);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    ImageView fruitImageView = (ImageView) findViewById(R.id.fruit_image_view);
    TextView fruitContentText = (TextView) findViewById(R.id.fruit_content_text);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    collapsingToolbar.setTitle(fruitName);
    if(fruitImageId==0)
    {
        Bitmap fruitimage = BitmapFactory.decodeByteArray(in, 0, in.length);
        fruitImageView.setImageBitmap(fruitimage);
    }
    else Glide.with(this).load(fruitImageId).into(fruitImageView);
    String fruitContent = generateFruitContent(fruitinfo);
    fruitContentText.setText(fruitContent);
}
 
Example 14
Project: Nird2   File: GroupInviteActivity.java   View Source Code Vote up 6 votes
@Override
public void onCreate(Bundle bundle) {
	super.onCreate(bundle);

	Intent i = getIntent();
	byte[] g = i.getByteArrayExtra(GROUP_ID);
	if (g == null) throw new IllegalStateException("No GroupId in intent.");
	groupId = new GroupId(g);

	if (bundle == null) {
		showInitialFragment(GroupInviteFragment.newInstance(groupId));
	}
}
 
Example 15
Project: OpenYOLO-Android   File: CredentialSaveResultTest.java   View Source Code Vote up 6 votes
@Test
public void toResultDataIntent_withValidResult_returnsValidIntent() throws Exception {
    final Intent resultIntent = ValidResult.INSTANCE.toResultDataIntent();

    final byte[] encodedResult =
            resultIntent.getByteArrayExtra(ProtocolConstants.EXTRA_SAVE_RESULT);
    ValidResult.assertEqualTo(CredentialSaveResult.fromProtobufBytes(encodedResult));
}
 
Example 16
Project: OpenYOLO-Android   File: CredentialClient.java   View Source Code Vote up 6 votes
/**
 * Returns the result of a {@link CredentialRetrieveResult}.
 *
 * <pre>{@code
 * CredentialClient client = CredentialClient.getInstance(getContext());
 *
 * // ...
 * @Override
 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
 *     super.onActivityResult(requestCode, resultCode, data);
 *     if (RC_RETRIEVE_CREDENTIAL == requestCode) {
 *        CredentialRetrieveResult result = client.getCredentialRetrieveResult(data);
 *        if (result.isSuccessful()) {
 *          // A credential was retrieved, you may automatically sign the user in.
 *          result.getCredential();
 *        } else {
 *          // A credential was not retrieved, you may look at the result code to determine why
 *          // and decide what step to take next. For example, result code may inform you of the
 *          // user's intent such as CredentialRetrieveResult.CODE_USER_CANCELED.
 *          result.getResultCode();
 *        }
 *     }
 * }
 * }</pre>
 *
 *
 * @see #getCredentialRetrieveIntent(CredentialRetrieveRequest)
 */
@NonNull
public CredentialRetrieveResult getCredentialRetrieveResult(
        @Nullable Intent resultData) {
    if (resultData == null) {
        Log.i(LOG_TAG, "resultData is null, returning default response");
        return CredentialRetrieveResult.UNKNOWN;
    }

    if (!resultData.hasExtra(EXTRA_RETRIEVE_RESULT)) {
        Log.i(LOG_TAG, "retrieve result missing from response, returning default response");
        return CredentialRetrieveResult.UNKNOWN;
    }

    byte[] resultBytes = resultData.getByteArrayExtra(EXTRA_RETRIEVE_RESULT);
    if (resultBytes == null) {
        Log.i(LOG_TAG, "No retrieve result found in result data, returning default response");
        return CredentialRetrieveResult.UNKNOWN;
    }

    try {
        CredentialRetrieveResult result =
                CredentialRetrieveResult.fromProtobufBytes(resultBytes);

        // Once a successfully retrieve result has been handled, re-enable auto sign-in.
        if (CredentialRetrieveResult.CODE_CREDENTIAL_SELECTED == result.getResultCode()) {
            mDeviceState.setIsAutoSignInDisabled(false);
        }

        return result;
    } catch (MalformedDataException ex) {
        Log.e(LOG_TAG, "validation of result proto failed, returning default response", ex);
        return CredentialRetrieveResult.UNKNOWN;
    }
}
 
Example 17
Project: Nird2   File: GroupInviteActivity.java   View Source Code Vote up 6 votes
@Override
public void onCreate(Bundle bundle) {
	super.onCreate(bundle);

	Intent i = getIntent();
	byte[] g = i.getByteArrayExtra(GROUP_ID);
	if (g == null) throw new IllegalStateException("No GroupId in intent.");
	groupId = new GroupId(g);

	if (bundle == null) {
		showInitialFragment(GroupInviteFragment.newInstance(groupId));
	}
}
 
Example 18
Project: react-native-mpush   File: RCTMPushReceiver.java   View Source Code Vote up 5 votes
@Override
    public void onReceive(Context context, Intent intent) {

        if (MPushService.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            byte[] bytes = intent.getByteArrayExtra(MPushService.EXTRA_PUSH_MESSAGE);
            int messageId = intent.getIntExtra(MPushService.EXTRA_PUSH_MESSAGE_ID, 0);
            String message = new String(bytes, Constants.UTF_8);

//           Toast.makeText(context, "收到新的通知:" + message, Toast.LENGTH_SHORT).show();

            if (messageId > 0) MPush.I.ack(messageId);
            if (TextUtils.isEmpty(message)) return;
            reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT_MESSAGE, message);

        } else {
            //reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT, intent.getAction());
        }
        Log.d("MPush", intent.toString());
        if (MPushService.ACTION_KICK_USER.equals(intent.getAction())) {

            Toast.makeText(context, "用户被踢下线了", Toast.LENGTH_SHORT).show();
        } else if (MPushService.ACTION_BIND_USER.equals(intent.getAction())) {

            Toast.makeText(context, "绑定用户:"
                            + intent.getStringExtra(MPushService.EXTRA_USER_ID)
                            + (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false) ? "成功" : "失败")
                    , Toast.LENGTH_SHORT).show();

        } else if (MPushService.ACTION_UNBIND_USER.equals(intent.getAction())) {
            Toast.makeText(context, "解绑用户:"
                            + (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false)
                            ? "成功"
                            : "失败")
                    , Toast.LENGTH_SHORT).show();

        } else if (MPushService.ACTION_CONNECTIVITY_CHANGE.equals(intent.getAction())) {
            Toast.makeText(context, intent.getBooleanExtra(MPushService.EXTRA_CONNECT_STATE, false)
                            ? "MPUSH连接建立成功"
                            : "MPUSH连接断开"
                    , Toast.LENGTH_SHORT).show();
        } else if (MPushService.ACTION_HANDSHAKE_OK.equals(intent.getAction())) {
            Toast.makeText(context, "MPUSH握手成功, 心跳:" + intent.getIntExtra(MPushService.EXTRA_HEARTBEAT, 0)
                    , Toast.LENGTH_SHORT).show();
        }
    }
 
Example 19
Project: okwallet   File: BitcoinIntegration.java   View Source Code Vote up 3 votes
/**
 * Get BIP70 payment message from result intent. Meant for usage by applications initiating a Bitcoin
 * payment.
 * 
 * You can use the transactions contained in the payment to validate the payment. For this, you need your
 * own Bitcoin infrastructure though. There is no guarantee that the payment will ever confirm.
 * 
 * @param result
 *            result intent
 * @return payment message
 */
public static byte[] paymentFromResult(final Intent result) {
    final byte[] payment = result.getByteArrayExtra(INTENT_EXTRA_PAYMENT);

    return payment;
}
 
Example 20
Project: okwallet   File: BitcoinIntegration.java   View Source Code Vote up 3 votes
/**
 * Get payment request from intent. Meant for usage by applications accepting payment requests.
 * 
 * @param intent
 *            intent
 * @return payment request or null
 */
public static byte[] paymentRequestFromIntent(final Intent intent) {
    final byte[] paymentRequest = intent.getByteArrayExtra(INTENT_EXTRA_PAYMENTREQUEST);

    return paymentRequest;
}