List of usage examples for android.content Intent getComponent
public @Nullable ComponentName getComponent()
From source file:com.hukum.app_framework.application.gcm.controller.AppGcmListenerService.java
/** * Called when message is received.//from w w w. ja va 2 s.c om * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { if (data != null) { if (data.containsKey("CMD")) return; Log.d(TAG, "From: " + from); if (from.startsWith("/topics/")) { // message received from some topic. } else { // normal downstream message. String he = data.getString("he"); String messageId = data.getString("messageId"); int event = Integer.parseInt(he); String playStoreUrl; String webUrl; String openAppScreen; String message; Intent intent = null; message = data.getString("message"); String notificationType = data.getString("nt"); if (!TextUtils.isEmpty(notificationType) && !TextUtils.isEmpty(messageId)) { ApplicationObject.getInstance().getInternalTracker().sendNotificationTracking(notificationType, messageId); } switch (event) { case GCMConstants.APP_OPEN_EVENT: PackageManager packageManager = getPackageManager(); intent = packageManager.getLaunchIntentForPackage(getPackageName()); ComponentName componentName = intent.getComponent(); Intent mainIntent = IntentCompat.makeRestartActivityTask(componentName); sendNotification(mainIntent, message); break; case GCMConstants.APP_CONSUMABLE_EVENT: openAppScreen = data.getString("op"); String parameter = data.getString("pm"); handleParams(message, parameter, messageId); // push notification handling.. break; case GCMConstants.PLAY_STORE_CONSUMABLE_EVENT: playStoreUrl = data.getString("androidURL"); if (TextUtils.isEmpty(playStoreUrl)) { playStoreUrl = getPackageName(); } try { intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + playStoreUrl)); } catch (ActivityNotFoundException e) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + playStoreUrl)); } sendNotification(intent, message); break; case GCMConstants.WEB_CONSUMABLE_EVENT: webUrl = data.getString("androidURL"); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl)); sendNotification(intent, message); break; } } } }
From source file:com.ycdyng.onemulti.OneActivity.java
private final void startFragmentForResult(Intent intent, int requestCode, int[] customAnimations) { hiddenSoftInput();/*from www. j a v a 2 s .c o m*/ clearAvailIndices(); mCurTransaction = mFragmentManager.beginTransaction(); if (customAnimations != null && customAnimations.length >= 2) { mCurTransaction.setCustomAnimations(customAnimations[0], customAnimations[1]); } String name = makeFragmentName(getClass().getSimpleName(), intent.getComponent().getClassName()); Fragment fragment = getFragment(intent.getComponent().getClassName()); fragment.setTargetFragment(mCurrentPrimaryItem, requestCode); fragment.setArguments(intent.getExtras()); if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_NO_HISTORY && fragment instanceof MultiFragment) { ((MultiFragment) fragment).setLaunchMode(LaunchMode.FLAG_FRAGMENT_NO_HISTORY); } if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); mCurTransaction.hide(mCurrentPrimaryItem); if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); mCurrentPrimaryItem = fragment; } mCurTransaction.commitAllowingStateLoss(); mCurTransaction = null; }
From source file:com.test.onesignal.GenerateNotificationRunner.java
@Test public void shouldRestoreNotifications() throws Exception { NotificationRestorer.restore(blankActivity); NotificationRestorer.restored = false; NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, getBaseNotifBundle(), null); NotificationRestorer.restore(blankActivity); NotificationRestorer.restored = false; Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService(); Assert.assertEquals(GcmIntentService.class.getName(), intent.getComponent().getClassName()); // Go forward 1 week // Note: Does not effect the SQL function strftime ShadowSystemClock.setCurrentTimeMillis(System.currentTimeMillis() + 604801L * 1000L); // Restorer should not fire service since the notification is over 1 week old. NotificationRestorer.restore(blankActivity); NotificationRestorer.restored = false; Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedService()); }
From source file:com.test.onesignal.GenerateNotificationRunner.java
@Test @Config(shadows = { ShadowGcmBroadcastReceiver.class }) public void shouldSetButtonsCorrectly() throws Exception { Intent intentGcm = new Intent(); intentGcm.setAction("com.google.android.c2dm.intent.RECEIVE"); intentGcm.putExtra("message_type", "gcm"); Bundle bundle = getBaseNotifBundle(); bundle.putString("o", "[{\"n\": \"text1\", \"i\": \"id1\"}]"); intentGcm.putExtras(bundle);/*from w w w . j av a 2 s. c o m*/ GcmBroadcastReceiver gcmBroadcastReceiver = new GcmBroadcastReceiver(); gcmBroadcastReceiver.onReceive(blankActivity, intentGcm); Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService(); Assert.assertEquals("com.onesignal.GcmIntentService", intent.getComponent().getClassName()); JSONObject jsonPayload = new JSONObject(intent.getStringExtra("json_payload")); Assert.assertEquals(null, jsonPayload.optString("o", null)); JSONObject customJson = new JSONObject(jsonPayload.optString("custom")); JSONObject additionalData = new JSONObject((customJson.getString("a"))); Assert.assertEquals("id1", additionalData.getJSONArray("actionButtons").getJSONObject(0).getString("id")); }
From source file:com.achep.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();/* w w w . j ava2 s .c om*/ final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(android.R.id.content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:com.bullmobi.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();/*from w ww.j a v a 2 s . co m*/ final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(R.id.main_content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:cz.maresmar.sfm.service.plugin.sync.SyncHandler.java
private void startPlugin(@NonNull String plugin, long portalId, long credentialsID, @SyncTask int pluginTasks) { Intent intent = PluginUtils.buildPluginIntent(plugin); // Puts action details intent.setAction(ActionContract.ACTION_SYNC); intent.putExtra(ActionContract.EXTRA_PORTAL_ID, portalId); intent.putExtra(ActionContract.EXTRA_CREDENTIAL_ID, credentialsID); intent.putExtra(ActionContract.EXTRA_TASKS, pluginTasks); // Provides access to login data intent.setData(LogData.getUri(portalId, credentialsID)); // Give permissions to access data int rwFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION; String packageName = intent.getComponent().getPackageName(); mContext.grantUriPermission(packageName, intent.getData(), rwFlags); mContext.grantUriPermission(packageName, ProviderContract.Action.getCredentialUri(credentialsID), rwFlags); mContext.grantUriPermission(packageName, ProviderContract.GroupMenuEntry.getPortalUri(portalId), rwFlags); mContext.grantUriPermission(packageName, ProviderContract.MenuEntry.getPortalUri(portalId), rwFlags); Timber.i("Starting plugin \"%s\" on portal %d with credential %d", plugin, portalId, credentialsID); // Fire start PluginUtils.startPlugin(mContext, intent); }
From source file:com.ycdyng.onemulti.OneActivity.java
public void startFragment(Intent intent, int[] customAnimations) { hiddenSoftInput();//w w w . j a va2s. co m clearAvailIndices(); mCurTransaction = mFragmentManager.beginTransaction(); if (customAnimations != null && customAnimations.length >= 2) { mCurTransaction.setCustomAnimations(customAnimations[0], customAnimations[1]); } mCurTransaction.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); String name = makeFragmentName(getClass().getSimpleName(), intent.getComponent().getClassName()); Fragment fragment = null; if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_CLEAR_TOP) { // at the top of the history stack ? if (mCurrentPrimaryItem.getClass().getName().equals(intent.getComponent().getClassName())) { // Yes fragment = mCurrentPrimaryItem; mCurTransaction.attach(mCurrentPrimaryItem); } else { // Do we already have this fragment? fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null) { // Yes, we have mCurTransaction.attach(fragment); int attachFragmentIndex = getFragmentIndex(fragment); List<Fragment> availableFragments = getAvailableFragments(); for (int i = availableFragments.size() - 1; i >= 0; i--) { if (fragment != availableFragments.get(i)) { Fragment tempFragment = availableFragments.get(i); int index = getFragmentIndex(tempFragment); if (index > attachFragmentIndex) { mCurTransaction.remove(availableFragments.get(i)); } } } } else { fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); if (mCurrentPrimaryItem != null) { mCurTransaction.detach(mCurrentPrimaryItem); } } } } else if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_CLEAR_ALL) { // add new fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); // remove all List<Fragment> availableFragments = getAvailableFragments(); for (int i = availableFragments.size() - 1; i >= 0; i--) { mCurTransaction.remove(availableFragments.get(i)); } } else if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_SINGLE_INSTANCE) { // Do we already have this fragment? fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null) { // Yes, we have mCurTransaction.attach(fragment); if (mCurrentPrimaryItem != null) { mCurTransaction.detach(mCurrentPrimaryItem); } } else { fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); if (mCurrentPrimaryItem != null) { if (mCurrentPrimaryItem instanceof MultiFragment && ((MultiFragment) mCurrentPrimaryItem) .getLaunchMode() == LaunchMode.FLAG_FRAGMENT_NO_HISTORY) { mCurTransaction.remove(mCurrentPrimaryItem); } else { mCurTransaction.detach(mCurrentPrimaryItem); } } } } else if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_SINGLE_TOP) { if (mCurrentPrimaryItem.getClass().getName().equals(intent.getComponent().getClassName())) { mCurTransaction.attach(mCurrentPrimaryItem); } else { // Do we already have this fragment? fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null) { int currentFragmentIndex = getFragmentIndex(mCurrentPrimaryItem); int fragmentIndex = getFragmentIndex(fragment); if (fragmentIndex > currentFragmentIndex) { mCurTransaction.attach(fragment); } else { fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); } } else { fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); } if (mCurrentPrimaryItem != null) { if (mCurrentPrimaryItem instanceof MultiFragment && ((MultiFragment) mCurrentPrimaryItem) .getLaunchMode() == LaunchMode.FLAG_FRAGMENT_NO_HISTORY) { mCurTransaction.remove(mCurrentPrimaryItem); } else { mCurTransaction.detach(mCurrentPrimaryItem); } } } } else { fragment = getFragment(intent.getComponent().getClassName()); fragment.setArguments(intent.getExtras()); if (DEBUG) Log.v(TAG, "Adding item #" + name); mCurTransaction.add(android.R.id.content, fragment, name); if (intent.getFlags() == LaunchMode.FLAG_FRAGMENT_NO_HISTORY && fragment instanceof MultiFragment) { ((MultiFragment) fragment).setLaunchMode(LaunchMode.FLAG_FRAGMENT_NO_HISTORY); } if (mCurrentPrimaryItem != null) { if (mCurrentPrimaryItem instanceof MultiFragment && ((MultiFragment) mCurrentPrimaryItem) .getLaunchMode() == LaunchMode.FLAG_FRAGMENT_NO_HISTORY) { mCurTransaction.remove(mCurrentPrimaryItem); } else { mCurTransaction.detach(mCurrentPrimaryItem); } } } if (mCurrentPrimaryItem != null && mCurrentPrimaryItem.getView() != null) { mCurrentPrimaryItem.getView().post(new Runnable() { @Override public void run() { finishOp(); } }); } else { finishOp(); } if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); mCurrentPrimaryItem = fragment; } } }
From source file:org.spontaneous.trackservice.RemoteService.java
@Override public IBinder onBind(Intent intent) { // Select the interface to return. If your service only implements // a single interface, you can just return it here without checking // the Intent. try {// ww w . j av a 2 s . c o m Log.i(TAG, IRemoteService.class.getName().toString()); Log.i(TAG, intent.getComponent().getClassName()); if (Class.forName(RemoteService.class.getName()).toString() .equals(intent.getComponent().getClassName())) { return this.mBinder; } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.mBinder; }
From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java
/** * Create a chooser intent to select the source to get image from.<br/> * The source can be camera's (ACTION_IMAGE_CAPTURE) or gallery's (ACTION_GET_CONTENT).<br/> * All possible sources are added to the intent chooser. *//*from www . j a va2 s .c o m*/ public Intent getPickImageChooserIntent() { List<Intent> allIntents = new ArrayList<>(); PackageManager packageManager = getPackageManager(); // collect all gallery intents Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); galleryIntent.setType("image/*"); List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0); for (ResolveInfo res : listGallery) { Intent intent = new Intent(galleryIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(res.activityInfo.packageName); allIntents.add(intent); } // the main intent is the last in the list (fucking android) so pickup the useless one Intent mainIntent = allIntents.get(allIntents.size() - 1); for (Intent intent : allIntents) { if (intent.getComponent().getClassName().equals("com.android.documentsui.DocumentsActivity")) { mainIntent = intent; break; } } allIntents.remove(mainIntent); // Create a chooser from the main intent Intent chooserIntent = Intent.createChooser(mainIntent, getString(R.string.choose_photos)); // Add all other intents chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()])); return chooserIntent; }