/** * Checks to see if the activity's intent ({@link android.app.Activity#getIntent()}) is an NFC * intent that the app recognizes. If it is, then parse the NFC message and set the activity's * intent (using {@link android.app.Activity#setIntent(android.content.Intent)}) to something the * app can recognize (i.e. a normal {@link android.content.Intent#ACTION_VIEW} intent). */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static void tryUpdateIntentFromBeam(Activity activity) { if (UIUtils.hasICS()) { Intent originalIntent = activity.getIntent(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(originalIntent.getAction())) { Parcelable[] rawMsgs = originalIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) rawMsgs[0]; // Record 0 contains the MIME type, record 1 is the AAR, if present. // In iosched, AARs are not present. NdefRecord mimeRecord = msg.getRecords()[0]; if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(new String(mimeRecord.getType()))) { // Re-set the activity's intent to one that represents session details. Intent sessionDetailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(new String(mimeRecord.getPayload()))); activity.setIntent(sessionDetailIntent); } } } }
/** Sets this activity's Android Beam message to one representing the given session. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static void setBeamSessionUri(Activity activity, Uri sessionUri) { if (UIUtils.hasICS()) { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) { // No NFC :-( return; } nfcAdapter.setNdefPushMessage( new NdefMessage( new NdefRecord[] { new NdefRecord( NdefRecord.TNF_MIME_MEDIA, ScheduleContract.Sessions.CONTENT_ITEM_TYPE.getBytes(), new byte[0], sessionUri.toString().getBytes()) }), activity); } }
private void routeIntent(Intent intent, boolean updateSurfaceOnly) { Uri uri = intent.getData(); if (uri == null) { return; } if (intent.hasExtra(Intent.EXTRA_TITLE)) { setTitle(intent.getStringExtra(Intent.EXTRA_TITLE)); } String mimeType = getContentResolver().getType(uri); if (ScheduleContract.Tracks.CONTENT_ITEM_TYPE.equals(mimeType)) { // Load track details showFullUI(true); if (!updateSurfaceOnly) { // TODO: don't assume the URI will contain the track ID int defaultViewType = intent.getIntExtra(EXTRA_DEFAULT_VIEW_TYPE, TracksDropdownFragment.VIEW_TYPE_SESSIONS); String selectedTrackId = ScheduleContract.Tracks.getTrackId(uri); loadTrackList(defaultViewType, selectedTrackId); getSupportActionBar().setSelectedNavigationItem(defaultViewType); onTrackSelected(selectedTrackId); mSlidingPaneLayout.openPane(); } } else if (ScheduleContract.Sessions.CONTENT_TYPE.equals(mimeType)) { // Load a session list, hiding the tracks dropdown and the tabs mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; showFullUI(false); if (!updateSurfaceOnly) { loadSessionList(uri, null); mSlidingPaneLayout.openPane(); } } else if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(mimeType)) { // Load session details if (intent.hasExtra(EXTRA_MASTER_URI)) { mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; showFullUI(false); if (!updateSurfaceOnly) { loadSessionList( (Uri) intent.getParcelableExtra(EXTRA_MASTER_URI), ScheduleContract.Sessions.getSessionId(uri)); loadSessionDetail(uri); } } else { mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; // prepare for onTrackInfo... showFullUI(true); if (!updateSurfaceOnly) { loadSessionDetail(uri); loadTrackInfoFromSessionUri(uri); } } } else if (ScheduleContract.Sandbox.CONTENT_TYPE.equals(mimeType)) { // Load a sandbox company list mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX; showFullUI(false); if (!updateSurfaceOnly) { loadSandboxList(uri, null); mSlidingPaneLayout.openPane(); } } else if (ScheduleContract.Sandbox.CONTENT_ITEM_TYPE.equals(mimeType)) { // Load company details mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX; showFullUI(false); if (!updateSurfaceOnly) { Uri masterUri = intent.getParcelableExtra(EXTRA_MASTER_URI); if (masterUri == null) { masterUri = ScheduleContract.Sandbox.CONTENT_URI; } loadSandboxList(masterUri, ScheduleContract.Sandbox.getCompanyId(uri)); loadSandboxDetail(uri); } } updateDetailBackground(); }