List of usage examples for android.content Intent removeCategory
public void removeCategory(String category)
From source file:com.google.vr.sdk.samples.video360.VideoActivity.java
/** * Checks that the appropriate permissions have been granted. Otherwise, the sample will wait * for the user to grant the permission. * * @param savedInstanceState unused in this sample but it could be used to track video position *//*from w w w. j a va 2 s . c o m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video_activity); // Configure the MonoscopicView which will render the video and UI. videoView = (MonoscopicView) findViewById(R.id.video_view); VideoUiView videoUi = (VideoUiView) findViewById(R.id.video_ui_view); videoUi.setVrIconClickListener(new OnClickListener() { @Override public void onClick(View v) { // Convert the Intent used to launch the 2D Activity into one that can launch the VR // Activity. This flow preserves the extras and data in the Intent. DaydreamApi api = DaydreamApi.create(VideoActivity.this); if (api != null) { // Launch the VR Activity with the proper intent. Intent intent = DaydreamApi .createVrIntent(new ComponentName(VideoActivity.this, VrVideoActivity.class)); intent.setData(getIntent().getData()); intent.putExtra(MediaLoader.MEDIA_FORMAT_KEY, getIntent().getIntExtra(MediaLoader.MEDIA_FORMAT_KEY, Mesh.MEDIA_MONOSCOPIC)); api.launchInVr(intent); api.close(); } else { // Fall back for devices that don't have Google VR Services. This flow should only // be used for older Cardboard devices. Intent intent = new Intent(getIntent()).setClass(VideoActivity.this, VrVideoActivity.class); intent.removeCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(0); // Clear any flags from the previous intent. startActivity(intent); } // See VrVideoActivity's launch2dActivity() for more info about why this finish() call // may be required. finish(); } }); videoView.initialize(videoUi); // Boilerplate for checking runtime permissions in Android. if (ContextCompat.checkSelfPermission(this, permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { View button = findViewById(R.id.permission_button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(VideoActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, READ_EXTERNAL_STORAGE_PERMISSION_ID); } }); // The user can click the button to request permission but we will also click on their behalf // when the Activity is created. button.callOnClick(); } else { // Permission has already been granted. initializeActivity(); } }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
@Override public void updateEditedIntent(Intent editedIntent) { // Intent action if (mAvailbleActions != null) { editedIntent.setAction((String) mActionsSpinner.getSelectedItem()); } else {/*w ww . j a v a 2 s . co m*/ String action = mActionText.getText().toString(); if ("".equals(action)) { action = null; } editedIntent.setAction(action); } // Categories { // Clear categories (why there's no api for this) Set<String> origCategories = editedIntent.getCategories(); if (origCategories != null) { for (String category : origCategories.toArray(new String[origCategories.size()])) { editedIntent.removeCategory(category); } } } // Fill categories if (mCategoryCheckBoxes != null) { // Fill categories from checkboxes for (CheckBox cb : mCategoryCheckBoxes) { String category = (String) cb.getTag(); if (cb.isChecked()) { editedIntent.addCategory(category); } } } else { // Fill categories from textfields for (TextView categoryTextView : mCategoryTextInputs) { editedIntent.addCategory(categoryTextView.getText().toString()); } } // Intent data (Uri) and type (MIME) String data = mDataText.getText().toString(); editedIntent.setDataAndType(data.equals("") ? null : Uri.parse(data), getDataType()); // Package name { String packageName = mPackageNameText.getText().toString(); if ("".equals(packageName)) { editedIntent.setPackage(null); } else { editedIntent.setPackage(packageName); } } // Set component for explicit intent updateIntentComponent(); }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Filter the intent to a single activity so a chooser won't pop up. If not found, it tries to * resolve intent by falling back to default category. * @param intent intent to filter.//from www . jav a2 s .c o m */ private void filterIntentWithCategory(final Intent intent) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Try to notify the content to the user. * @param content reach content.//from ww w .j a v a2 s.co m * @param replaySystemNotifications true iff system notifications must be replayed. * @throws RuntimeException if an error occurs. */ private void notifyContent(final CapptainReachContent content, boolean replaySystemNotifications) throws RuntimeException { /* Check expiry */ final long localId = content.getLocalId(); if (content.hasExpired()) { /* Delete */ deleteContent(content); return; } /* If datapush, just broadcast, can be done in parallel with another content */ final Intent intent = content.getIntent(); if (content instanceof CapptainDataPush) { /* If it's a datapush it may already be in the process of broadcasting. */ if (!mPendingDataPushes.add(localId)) return; /* Broadcast intent */ final CapptainDataPush dataPush = (CapptainDataPush) content; intent.setPackage(mContext.getPackageName()); mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { /* The last broadcast receiver to set a defined result wins (to determine which result). */ switch (getResultCode()) { case RESULT_OK: dataPush.actionContent(context); break; case RESULT_CANCELED: dataPush.exitContent(context); break; default: dataPush.dropContent(context); } /* Clean broadcast state */ mPendingDataPushes.remove(localId); } }, null, RESULT_UNDEFINED, null, null); /* Datapush processed */ return; } /* Don't notify in-app if we are already notifying in app or showing a content */ if (mState != State.IDLE && !content.isSystemNotification()) return; /* Don't process again a pending notification */ if (mPendingNotifications.contains(localId)) return; /* Not an interactive content, exit (but there is no other type left, this is just a cast guard) */ if (!(content instanceof CapptainReachInteractiveContent)) return; CapptainReachInteractiveContent iContent = (CapptainReachInteractiveContent) content; /* Don't replay system notification unless told otherwise. */ if (!replaySystemNotifications && iContent.isSystemNotification() && iContent.getNotificationLastDisplayedDate() != null && iContent.getNotificationLastDisplayedDate() > mAppLastUpdateTime) return; /* Check if the content can be notified in the current context (behavior) */ if (!iContent.canNotify(sActivityManager.getCurrentActivityAlias())) return; /* If there is a show intent */ if (intent != null) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } } /* Delegate notification */ Boolean notifierResult = getNotifier(content).handleNotification(iContent); /* Check if notifier rejected content notification for now */ if (Boolean.FALSE.equals(notifierResult)) /* The notifier rejected the content, nothing more to do */ return; /* Cache content if accepted, it will most likely be used again soon for the next steps. */ mContentCache.put(localId, content); /* * If notifier did not return null (e.g. returned true, meaning actually accepted the content), * we assume the notification is correctly displayed. */ if (Boolean.TRUE.equals(notifierResult)) { /* Report displayed feedback */ iContent.displayNotification(mContext); /* Track in-app content life cycle: one at a time */ if (!iContent.isSystemNotification()) mState = State.NOTIFYING_IN_APP; } /* Track pending notifications to avoid re-processing them every time we change activity. */ if (notifierResult == null) mPendingNotifications.add(localId); }