Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

In this page you can find the example usage for android.content Intent hasExtra.

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:fr.bmartel.android.fadecandy.service.FadecandyService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //this is the activity which will be opened when user click on notification
    Intent testIntent = new Intent();
    if (intent != null && intent.hasExtra(Constants.SERVICE_EXTRA_ACTIVITY)) {
        testIntent.setComponent(//from w  ww  .  j a va 2 s.com
                ComponentName.unflattenFromString(intent.getStringExtra(Constants.SERVICE_EXTRA_ACTIVITY)));
    }

    ServiceType serviceTypeOverride;

    if (intent != null && intent.hasExtra(Constants.SERVICE_EXTRA_SERVICE_TYPE)) {
        serviceTypeOverride = ServiceType.getServiceType(intent.getIntExtra(
                Constants.SERVICE_EXTRA_SERVICE_TYPE, ServiceType.NON_PERSISTENT_SERVICE.ordinal()));
    } else {
        serviceTypeOverride = mServiceType;
    }

    switch (serviceTypeOverride) {
    case NON_PERSISTENT_SERVICE:
        Log.v(TAG, "starting NON_PERSISTENT_SERVICE...");
        return START_NOT_STICKY;
    case PERSISTENT_SERVICE:
        startForeground(4242, NotificationHelper.createNotification(this, null, testIntent));
        Log.v(TAG, "starting PERSISTENT_SERVICE...");
        return START_STICKY;
    }

    return START_NOT_STICKY;
}

From source file:com.mobicage.rogerthat.AbstractHomeActivity.java

private void processIntent(final Intent intent) {
    final String url = intent.getDataString();
    if (intent.getBooleanExtra(INTENT_PROCESSED, false))
        return;/*from  w  w  w.j av a  2s.  co m*/
    if (url != null) {
        goToMessagingActivity();
        processUrl(url);
    } else if (intent.hasExtra(INTENT_KEY_LAUNCHINFO)) {
        String value = intent.getStringExtra(INTENT_KEY_LAUNCHINFO);
        if (INTENT_VALUE_SHOW_FRIENDS.equals(value)) {
            // goToUserFriendsActivity();

        } else if (INTENT_VALUE_SHOW_MESSAGES.equals(value)) {
            goToMessagingActivity();

        } else if (INTENT_VALUE_SHOW_NEW_MESSAGES.equals(value)) {
            if (intent.hasExtra(INTENT_KEY_MESSAGE)) {
                String messageKey = intent.getStringExtra(INTENT_KEY_MESSAGE);
                goToMessageDetail(messageKey);
            } else {
                goToMessagingActivity();
            }

        } else if (INTENT_VALUE_SHOW_UPDATED_MESSAGES.equals(value)) {
            if (intent.hasExtra(INTENT_KEY_MESSAGE)) {
                String messageKey = intent.getStringExtra(INTENT_KEY_MESSAGE);
                goToMessageDetail(messageKey);
            } else {
                goToMessagingActivity();
            }

        } else if (INTENT_VALUE_SHOW_SCANTAB.equals(value)) {
            goToScanActivity();
        } else {
            L.bug("Unexpected (key, value) for HomeActivity intent: (" + INTENT_KEY_LAUNCHINFO + ", " + value
                    + ")");
        }
        if (mMessagingPlugin != null) {
            mMessagingPlugin.updateMessagesNotification(false, false, false);
            handleBadgeMessages();
        }
    }

    intent.putExtra(INTENT_PROCESSED, true);

}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java

private void goToMessagingActivityIfNeeded(Intent intent) {
    if (intent.hasExtra(HomeActivity.INTENT_KEY_LAUNCHINFO)) {
        String value = intent.getStringExtra(HomeActivity.INTENT_KEY_LAUNCHINFO);
        if (HomeActivity.INTENT_VALUE_SHOW_MESSAGES.equals(value)
                || HomeActivity.INTENT_VALUE_SHOW_NEW_MESSAGES.equals(value)
                || HomeActivity.INTENT_VALUE_SHOW_UPDATED_MESSAGES.equals(value)) {
            goToMessagingActivity();/*from   w ww  .j  a  v a 2 s .com*/
        }
    }
}

From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (resultCode == RESULT_CANCELED)
        return;//from w  w  w . j  a  va 2s  . c  om

    switch (requestCode) {
    case BROWSER_ACTIVITY:
        if (intent instanceof Intent && intent.hasExtra("exit_app"))
            mExitApplication = true;

        finish();
        break;
    }
}

From source file:com.android.contacts.ContactSaveService.java

public static boolean canUndo(Intent resultIntent) {
    return resultIntent.hasExtra(EXTRA_UNDO_DATA);
}

From source file:com.flowzr.budget.holo.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.main);/*from  w  ww  .j  a  v  a 2 s  .  c  o  m*/

    actionBar = getSupportActionBar();
    setTitle(getResources().getString(R.string.app_name) + " (" + Utils.getAppVersion(this) + ")");
    setupDrawer();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // create new tabs and and set up the titles of the tabs
    mAccountTab = setupAccountsTab(actionBar);
    mBlotterTab = setupBlotterTab(actionBar);
    mBudgetsTab = setupBudgetsTab(actionBar);

    Intent intent = getIntent();

    mAdapter = new MyAdapter(getSupportFragmentManager(), intent);
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    viewPager.setAdapter(mAdapter);
    viewPager.setOnPageChangeListener(this);

    mAccountTab.setTabListener(this);
    mBlotterTab.setTabListener(this);
    mBudgetsTab.setTabListener(this);

    addMyTabs();

    if (intent.hasExtra(REQUEST_BLOTTER)) {

        blotterFragment = new BlotterFragment();
        if (intent.hasExtra(EntityListActivity.REQUEST_NEW_TRANSACTION_FROM_TEMPLATE)) {
            Bundle bundle = new Bundle();
            bundle.putInt(BlotterFragment.EXTRA_REQUEST_TYPE,
                    BlotterFragment.NEW_TRANSACTION_FROM_TEMPLATE_REQUEST);
            blotterFragment.setArguments(bundle);
        }

        loadTabFragment(new BlotterFragment(), R.layout.blotter, intent.getExtras(), TAB_BLOTTER);
    } else if (intent.hasExtra(REQUEST_SPLIT_BLOTTER)) {
        loadTabFragment(new SplitsBlotterActivity(), R.layout.blotter, intent.getExtras(), TAB_BLOTTER);
    } else if (intent.hasExtra(REQUEST_BUDGET_BLOTTER)) {
        loadTabFragment(new BudgetBlotterFragment(), R.layout.blotter, intent.getExtras(), TAB_BLOTTER);
    } else {
        StartupScreen startupScreen = MyPreferences.getStartupScreen(this);
        viewPager.setCurrentItem(startupScreen.ordinal());
    }
    initialLoad();
    FlowzrSyncEngine.setUpdatable(this);
}

From source file:com.ht.app.RestaurantsActivity.java

/**
 * -------------------- LIFE CYCLE --------------------
 *///from   ww  w.  j a  v  a2  s.co  m

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setupShortucts();

    setContentView(R.layout.activity_restaurants);

    Tracker t = ((AnalyticsHelper) this.getApplication()).getTracker(AnalyticsHelper.TrackerName.APP_TRACKER);
    t.setScreenName("Restaurant List");
    t.send(new HitBuilders.AppViewBuilder().build());

    // Get cuisine url
    Intent intent = getIntent();
    if (intent.hasExtra(SearchRestaurantsActivity.CUISINE_URL)) {
        mCuisineUrl = intent.getStringExtra(SearchRestaurantsActivity.CUISINE_URL);
    } else
        mCuisineUrl = "";

    if (intent.hasExtra(SearchRestaurantsActivity.PLACE_MODEL)) {
        mPlaceModel = PlaceModelConverter
                .createPlaceModelFromJSONString(intent.getStringExtra(SearchRestaurantsActivity.PLACE_MODEL));
    }

    setupView();
}

From source file:com.google.android.apps.muzei.SourceSubscriberService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;/*from  w  w  w.j  a  va 2  s.co m*/
    }

    String action = intent.getAction();
    if (!ACTION_PUBLISH_STATE.equals(action)) {
        return;
    }
    // Handle API call from source
    String token = intent.getStringExtra(EXTRA_TOKEN);
    ComponentName selectedSource = SourceManager.getSelectedSource(this);
    if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) {
        Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for "
                + selectedSource);
        return;
    }

    SourceState state = null;
    if (intent.hasExtra(EXTRA_STATE)) {
        Bundle bundle = intent.getBundleExtra(EXTRA_STATE);
        if (bundle != null) {
            state = SourceState.fromBundle(bundle);
        }
    }

    if (state == null) {
        // If there is no state, there is nothing to change
        return;
    }

    ContentValues values = new ContentValues();
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString());
    values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true);
    values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription());
    values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable());
    JSONArray commandsSerialized = new JSONArray();
    int numSourceActions = state.getNumUserCommands();
    boolean supportsNextArtwork = false;
    for (int i = 0; i < numSourceActions; i++) {
        UserCommand command = state.getUserCommandAt(i);
        if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) {
            supportsNextArtwork = true;
        } else {
            commandsSerialized.put(command.serialize());
        }
    }
    values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork);
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString());
    ContentResolver contentResolver = getContentResolver();
    Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI,
            new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { selectedSource.flattenToShortString() }, null, null);
    if (existingSource != null && existingSource.moveToFirst()) {
        Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI,
                existingSource.getLong(0));
        contentResolver.update(sourceUri, values, null, null);
    } else {
        contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values);
    }
    if (existingSource != null) {
        existingSource.close();
    }

    Artwork artwork = state.getCurrentArtwork();
    if (artwork != null) {
        artwork.setComponentName(selectedSource);
        contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues());

        // Download the artwork contained from the newly published SourceState
        startService(TaskQueueService.getDownloadCurrentArtworkIntent(this));
    }
}

From source file:com.androzic.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.e(TAG, "onNewIntent()");
    if (intent.hasExtra(LAUNCH_ACTIVITY)) {
        Serializable object = intent.getExtras().getSerializable(LAUNCH_ACTIVITY);
        if (Class.class.isInstance(object)) {
            Intent launch = new Intent(this, (Class<?>) object);
            launch.putExtras(intent);/*from w ww  .  j a  v  a2s. c  o  m*/
            launch.removeExtra(LAUNCH_ACTIVITY);
            startActivity(launch);
        }
    } else if (intent.hasExtra(SHOW_FRAGMENT)) {
        Serializable object = intent.getExtras().getSerializable(SHOW_FRAGMENT);
        if (Class.class.isInstance(object)) {
            @SuppressWarnings("rawtypes")
            String name = ((Class) object).getName();
            Fragment f = Fragment.instantiate(this, name);
            intent.removeExtra(SHOW_FRAGMENT);
            f.setArguments(intent.getExtras());
            if (DialogFragment.class.isInstance(f))
                ((DialogFragment) f).show(getSupportFragmentManager(), "show");
            else
                addFragment(f, name);
        }
    } else if (intent.hasExtra("lat") && intent.hasExtra("lon")) {
        application.ensureVisible(intent.getExtras().getDouble("lat"), intent.getExtras().getDouble("lon"));
        selectItem(0);
    }
}

From source file:com.nadmm.airports.DownloadActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDbManager = DatabaseManager.instance(this);
    mDownloadTask = null;//ww w .j a va  2s  . c  o m
    mHandler = new Handler();

    setContentView(createContentView(R.layout.download_list_view));

    // Add the footer view
    View footer = inflate(R.layout.download_footer);
    mListView = (ListView) findViewById(android.R.id.list);
    mListView.addFooterView(footer);
    mListView.setFooterDividersEnabled(true);

    Button btnDownload = (Button) findViewById(R.id.btnDownload);
    btnDownload.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            checkNetworkAndDownload();
        }
    });

    Button btnDelete = (Button) findViewById(R.id.btnDelete);
    btnDelete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            checkDelete();
        }
    });

    Intent intent = getIntent();
    if (intent.hasExtra("MSG")) {
        String msg = intent.getStringExtra("MSG");
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    checkData(false);
}