Java Code Examples for android.content.Intent#getParcelableArrayExtra()
The following examples show how to use
android.content.Intent#getParcelableArrayExtra() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddFriendQRActivity.java From NaviBee with GNU General Public License v3.0 | 6 votes |
private void handleNfcIntent(Intent NfcIntent) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(NfcIntent.getAction())) { Parcelable[] receivedArray = NfcIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if(receivedArray != null) { NdefMessage receivedMessage = (NdefMessage) receivedArray[0]; NdefRecord[] attachedRecords = receivedMessage.getRecords(); for (NdefRecord record: attachedRecords) { String string = new String(record.getPayload()); // Make sure we don't pass along our AAR (Android Application Record) if (string.equals(getPackageName())) continue; addFriend(string); } } } }
Example 2
Source File: NfcReadUtilityImpl.java From android-nfc-lib with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public SparseArray<String> readFromTagWithSparseArray(Intent nfcDataIntent) { Parcelable[] messages = nfcDataIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); SparseArray<String> resultMap = messages != null ? new SparseArray<String>(messages.length) : new SparseArray<String>(); if (messages == null) { return resultMap; } for (Parcelable message : messages) { for (NdefRecord record : ((NdefMessage) message).getRecords()) { byte type = retrieveTypeByte(record.getPayload()); String i = resultMap.get(type); if (i == null) { resultMap.put(type, parseAccordingToType(record)); } } } return resultMap; }
Example 3
Source File: ReadTextActivity.java From android-nfc with MIT License | 6 votes |
/** * 读取NFC标签文本数据 */ private void readNfcTag(Intent intent) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra( NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msgs[] = null; int contentSize = 0; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; contentSize += msgs[i].toByteArray().length; } } try { if (msgs != null) { NdefRecord record = msgs[0].getRecords()[0]; String textRecord = parseTextRecord(record); mTagText += textRecord + "\n\ntext\n" + contentSize + " bytes"; } } catch (Exception e) { } } }
Example 4
Source File: ServiceDiscoveryRequest.java From DeviceConnect-Android with MIT License | 6 votes |
@Override protected void onResponseReceived(final Intent request, final Intent response) { // エラーが返ってきた場合には、サービスには登録しない。 int result = response.getIntExtra(IntentDConnectMessage.EXTRA_RESULT, -1); if (result == IntentDConnectMessage.RESULT_OK) { // 送られてきたサービスIDにデバイスプラグインのIDを付加して保存 Parcelable[] services = response.getParcelableArrayExtra( ServiceDiscoveryProfileConstants.PARAM_SERVICES); if (services != null) { for (Parcelable p : services) { Bundle b = (Bundle) p; String id = b.getString(ServiceDiscoveryProfile.PARAM_ID); b.putString(ServiceDiscoveryProfile.PARAM_ID, mPluginMgr.appendServiceId(mDevicePlugin, id)); mServices.add(b); } } } // レスポンス個数を追加 synchronized (mRequestCodeArray) { mRequestCodeArray.remove(mRequestCode); } mCountDownLatch.countDown(); }
Example 5
Source File: FeedsActivity.java From newsApp with Apache License 2.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == Activity.RESULT_OK) { if (requestCode == INTENT_REQUEST_GET_IMAGES) { Parcelable[] parcelableUris = intent.getParcelableArrayExtra(ImagePickerActivity.EXTRA_IMAGE_URIS); if (parcelableUris == null) { return; } // Java doesn't allow array casting, this is a little hack Uri[] uris = new Uri[parcelableUris.length]; System.arraycopy(parcelableUris, 0, uris, 0, parcelableUris.length); if (uris != null) { hitCreateNewsApi(uris[0]); } } } }
Example 6
Source File: UploadNewsActivity.java From newsApp with Apache License 2.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == Activity.RESULT_OK) { if (requestCode == INTENT_REQUEST_GET_IMAGES) { Parcelable[] parcelableUris = intent.getParcelableArrayExtra(ImagePickerActivity.EXTRA_IMAGE_URIS); if (parcelableUris == null) { return; } // Java doesn't allow array casting, this is a little hack Uri[] uris = new Uri[parcelableUris.length]; System.arraycopy(parcelableUris, 0, uris, 0, parcelableUris.length); if (uris != null) { uri = uris[0]; ivNewsImage.setImageURI(uri); } } } }
Example 7
Source File: ZannenNfcWriter.java From effective_android_sample with Apache License 2.0 | 5 votes |
NdefMessage[] getNdefMessages(Intent intent) { // Parse the intent NdefMessage[] msgs = null; String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } } else { Log.d(TAG, "Unknown intent."); finish(); } return msgs; }
Example 8
Source File: ManagedConfigurationsFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@TargetApi(VERSION_CODES.M) private void updateRestrictionEntryFromResultIntent(RestrictionEntry restrictionEntry, Intent intent) { switch (restrictionEntry.getType()) { case RestrictionEntry.TYPE_BOOLEAN: restrictionEntry.setSelectedState(intent.getBooleanExtra(RESULT_VALUE, false)); break; case RestrictionEntry.TYPE_INTEGER: restrictionEntry.setIntValue(intent.getIntExtra(RESULT_VALUE, 0)); break; case RestrictionEntry.TYPE_STRING: restrictionEntry.setSelectedString(intent.getStringExtra(RESULT_VALUE)); break; case RestrictionEntry.TYPE_MULTI_SELECT: restrictionEntry.setAllSelectedStrings(intent.getStringArrayExtra(RESULT_VALUE)); break; case RestrictionEntry.TYPE_BUNDLE: { Bundle bundle = intent.getBundleExtra(RESULT_VALUE); restrictionEntry.setRestrictions(convertBundleToRestrictions(bundle)); break; } case RestrictionEntry.TYPE_BUNDLE_ARRAY: { Parcelable[] bundleArray = intent.getParcelableArrayExtra(RESULT_VALUE); RestrictionEntry[] restrictionEntryArray = new RestrictionEntry[bundleArray.length]; for (int i = 0; i< bundleArray.length; i++) { restrictionEntryArray[i] = RestrictionEntry.createBundleEntry(String.valueOf(i), convertBundleToRestrictions((Bundle) bundleArray[i])); } restrictionEntry.setRestrictions(restrictionEntryArray); break; } } }
Example 9
Source File: NFCTagReadWriteManager.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
private void readTagFromIntent(Intent intent) { if (intent != null){ String action = intent.getAction(); /*if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) { uidRead = true; String uid = ByteArrayToHexString(intent.getByteArrayExtra(NfcAdapter.EXTRA_ID)); onTagReadListener.onUidRead(uid); }*/ if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { tagRead = true; // get NDEF tag details Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); if (tag != null) { Ndef ndefTag = Ndef.get(tag); //int tagSize = ndefTag.getMaxSize(); // tag size tagIsWritable = ndefTag.isWritable(); // is tag writable? //String tagType = ndefTag.getType(); // tag type Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMessages != null) { NdefRecord[] records = ((NdefMessage) rawMessages[0]).getRecords(); String text = ndefRecordToString(records[0]); onTagReadListener.onTagRead(text); } } } } }
Example 10
Source File: IntentUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * Just like {@link Intent#getParcelableArrayExtra(String)} but doesn't throw exceptions. */ public static Parcelable[] safeGetParcelableArrayExtra(Intent intent, String name) { try { return intent.getParcelableArrayExtra(name); } catch (Throwable t) { Log.e(TAG, "getParcelableArrayExtra failed on intent " + intent); return null; } }
Example 11
Source File: HiddenReceiverActivity.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
private String readNfcTagPayload(Intent intent) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { NdefMessage[] msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } return new String(msgs[0].getRecords()[0].getPayload()); } return null; }
Example 12
Source File: IntentUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Just like {@link Intent#getParcelableArrayExtra(String)} but doesn't throw exceptions. */ public static Parcelable[] safeGetParcelableArrayExtra(Intent intent, String name) { try { return intent.getParcelableArrayExtra(name); } catch (Throwable t) { Log.e(TAG, "getParcelableArrayExtra failed on intent " + intent); return null; } }
Example 13
Source File: ChooserActivity.java From container with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); int userId = intent.getIntExtra(Constants.EXTRA_USER_HANDLE, VUserHandle.getCallingUserId()); mOptions = intent.getParcelableExtra(EXTRA_DATA); mResultWho = intent.getStringExtra(EXTRA_WHO); mRequestCode = intent.getIntExtra(EXTRA_REQUEST_CODE, 0); Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT); if (!(targetParcelable instanceof Intent)) { VLog.w("ChooseActivity", "Target is not an intent: " + targetParcelable); finish(); return; } Intent target = (Intent) targetParcelable; CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE); if (title == null) { title = getString(R.string.choose); } Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS); Intent[] initialIntents = null; if (pa != null) { initialIntents = new Intent[pa.length]; for (int i = 0; i < pa.length; i++) { if (!(pa[i] instanceof Intent)) { VLog.w("ChooseActivity", "Initial intent #" + i + " not an Intent: " + pa[i]); finish(); return; } initialIntents[i] = (Intent) pa[i]; } } super.onCreate(savedInstanceState, target, title, initialIntents, null, false, userId); }
Example 14
Source File: NFCHandler.java From timelapse-sony with GNU General Public License v3.0 | 5 votes |
public static Pair<String, String> parseIntent(Intent intent) throws Exception { Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); Parcelable[] messages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (tagFromIntent != null && messages != null) { return getCameraWifiSettingsFromTag(tagFromIntent, messages); } return null; }
Example 15
Source File: RepoDetailsActivity.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
private void processIntent(Intent i) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) { Parcelable[] rawMsgs = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) rawMsgs[0]; String url = new String(msg.getRecords()[0].getPayload()); Utils.debugLog(TAG, "Got this URL: " + url); Toast.makeText(this, "Got this URL: " + url, Toast.LENGTH_LONG).show(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setClass(this, ManageReposActivity.class); startActivity(intent); finish(); } }
Example 16
Source File: FileOperation.java From Camera-Roll-Android-App with Apache License 2.0 | 4 votes |
public static File_POJO[] getFiles(Intent workIntent) { Parcelable[] parcelables = workIntent.getParcelableArrayExtra(FILES); return File_POJO.generateArray(parcelables); }
Example 17
Source File: MnemonicActivity.java From GreenBits with GNU General Public License v3.0 | 4 votes |
private static byte[] getNFCPayload(final Intent intent) { final Parcelable[] extra = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); return ((NdefMessage) extra[0]).getRecords()[0].getPayload(); }
Example 18
Source File: UploadFileIntentService.java From geopaparazzi with GNU General Public License v3.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { resultReceiver = intent.getParcelableExtra(UploadResultReceiver.EXTRA_KEY); Parcelable[] uploadItems = intent.getParcelableArrayExtra(UploadResultReceiver.EXTRA_FILES_KEY); Bundle extras = intent.getExtras(); String user = extras.getString(PREFS_KEY_USER); String password = extras.getString(PREFS_KEY_PWD); try { String action = intent.getAction(); if (action != null && action.equals(UploadResultReceiver.UPLOAD_ACTION)) { updateBundle = new Bundle(); for (Parcelable p : uploadItems) { if (p instanceof IUploadable) { IUploadable uploadable = (IUploadable) p; if (isCancelled) { sendError(getString(R.string.upload_Canceled)); return; } File sourceFile = new File(uploadable.getDestinationPath()); if (!sourceFile.exists()) { updateBundle.putString(PROGRESS_MESSAGE_KEY, getString(R.string.upload_NotFound) + sourceFile.getName()); resultReceiver.send(UploadResultReceiver.RESULT_CODE, updateBundle); pause(); continue; } String url = uploadable.getUploadUrl(); updateBundle.putString(PROGRESS_MESSAGE_KEY, getString(R.string.upload_Uploading) + sourceFile.getName()); updateBundle.putInt(PROGRESS_KEY, 0); resultReceiver.send(UploadResultReceiver.RESULT_CODE, updateBundle); try { String response = sendFileViaPost(url, sourceFile, "document", user, password); updateBundle.putInt(PROGRESS_KEY, max); resultReceiver.send(UploadResultReceiver.RESULT_CODE, updateBundle); pause(); } catch (Exception e) { sendError(getString(R.string.upload_Error) + e.getLocalizedMessage()); return; } finally { if (GPLog.LOG) GPLog.addLogEntry("UploadFile", getString(R.string.upload_Uploaded) + sourceFile.getName()); } } } } sendDone(); } finally { isCancelled = false; } }
Example 19
Source File: MnemonicActivity.java From green_android with GNU General Public License v3.0 | 4 votes |
private static byte[] getNFCPayload(final Intent intent) { final Parcelable[] extra = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); return ((NdefMessage) extra[0]).getRecords()[0].getPayload(); }
Example 20
Source File: IntentConverter.java From external-nfc-api with Apache License 2.0 | 3 votes |
public static Intent convert(Intent input) { Intent output = new Intent(); output.setAction(input.getAction()); // detect supported types if(input.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { Parcelable[] messages = input.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); Bundle extras = new Bundle(); extras.putParcelableArray(NfcAdapter.EXTRA_NDEF_MESSAGES, messages); output.putExtras(extras); } if(input.hasExtra(NfcAdapter.EXTRA_TAG)) { android.nfc.Tag tag = (android.nfc.Tag) input.getParcelableExtra(NfcAdapter.EXTRA_TAG); output.putExtra(NfcAdapter.EXTRA_TAG, new TagWrapper(tag)); } if(input.hasExtra(NfcAdapter.EXTRA_AID)) { output.putExtra(NfcAdapter.EXTRA_AID, input.getParcelableExtra(NfcAdapter.EXTRA_AID)); } if(input.hasExtra(NfcAdapter.EXTRA_ID)) { byte[] id = input.getByteArrayExtra(NfcAdapter.EXTRA_ID); output.putExtra(NfcAdapter.EXTRA_ID, id); } // TODO forward all types return output; }