Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.csounds.examples.tests.MultiTouchXYActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.out.println(" RrequestC resultcode data " + requestCode + " " + resultCode + " " + data);
    if (requestCode == 0 && resultCode == RESULT_OK && data != null) {
        System.out.println("datagetIntExtrapresetNbr " + data.getIntExtra("presetNbr", 0));
        int presetNbr = data.getIntExtra("presetNbr", 0);
        this.setPreset(presetNbr);
    }//from   w  w  w. ja va2s  .  c  o m
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotate);

    Intent intent = getIntent();
    // If mechanismViewId == -1, an error occurred
    mechanismViewId = intent.getIntExtra(Utils.EXTRA_KEY_MECHANISM_VIEW_ID, -1);
    if (mechanismViewId != -1) {
        String imagePath = intent.getStringExtra("imagePath");
        textAnnotationCounter = 1;//from  w w w .  j av a 2s.c  o m
        // If no maximum is specified, no text annotations are allowed
        textAnnotationCounterMaximum = intent.getIntExtra("textAnnotationCounterMaximum", 0);
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        initAnnotateImageView(bitmap, imagePath);
        initAnnotations(intent);
        initStickerLists();
        setListeners();
    } else {
        Log.e("AnnotateImageActivity", "Failed to create the activity. No mechanismViewID provided");
    }
}

From source file:alaindc.memenguage.View.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    checkLoggedIn();//w  w  w .  jav a2s  . co  m
    setContentView(R.layout.activity_main);

    dbmanager = new DBManager(getApplicationContext());
    crs = dbmanager.getAllWords();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    if (fab != null)
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class);
                createWordIntentActivity.setAction(Constants.ACTION_ADD_WORD);
                MainActivity.this.startActivity(createWordIntentActivity);
            }
        });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    if (drawer != null)
        drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null)
        navigationView.setNavigationItemSelectedListener(this);

    ImageView navlogo = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.navLogoImageView);
    TextView navtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navTitle);
    TextView navsubtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navSubTitle);
    progressDialog = new ProgressDialog(this);

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.INTENT_VIEW_UPDATE)) {
                adapter.getFilter().filter("");
                adapter.notifyDataSetChanged();
            } else if (intent.getAction().equals(Constants.INTENT_COMMSERV_UPDATE)) {
                boolean success = intent.getBooleanExtra(Constants.EXTRA_COMMSERV_SUCCESS, false);
                String message = (intent.getIntExtra(Constants.EXTRA_COMMSERV_TYPE, 0) == Constants.UPLOAD)
                        ? "Databased uploaded "
                        : "Databased downloaded ";
                message = (success) ? message + "successfully!" : "An error occurred, try again.";
                progressDialog.setMessage(message);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        progressDialog.dismiss();
                    }
                }, 1500);

            } else {
                Log.d("", "");
            }
        }
    };

    IntentFilter updateviewIntFilt = new IntentFilter(Constants.INTENT_VIEW_UPDATE);
    IntentFilter serverCommIntFilt = new IntentFilter(Constants.INTENT_COMMSERV_UPDATE);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateviewIntFilt);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, serverCommIntFilt);

    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
            Context.MODE_PRIVATE);
    personName = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_NAME, "");
    personEmail = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_EMAIL, "");
    personId = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_ID, "");
    personPhoto = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_PHOTOURI, "");

    //        if (!personPhoto.equals(""))
    //            new AsyncImageTask(navlogo).execute(personPhoto);
    navtitle.setText(personName);
    navsubtitle.setText(personEmail);

    // TODO Just one time and in bcast receiver start phone
    Intent randomStart = new Intent(MainActivity.this, RandomIntentService.class);
    randomStart.setAction(Constants.ACTION_RANDOM_START);
    getApplicationContext().startService(randomStart);

    updateWordsList();
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Creates a Layout for a Single_Questionnaire
 * /*from  ww  w. j  a  v  a 2  s .c  om*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Intent intent = getActivity().getIntent();
    mBelongsTo = intent.getIntExtra(WelcomeActivity.KEY_BELONGS_TO, WelcomeActivityPagerAdapter.TAB_RUNNING);

    mLayoutInflater = inflater;

    container.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    if (savedInstanceState != null) {
        if (mPosition == -1)
            mPosition = savedInstanceState.getInt(KEY_POSITION, -1);

        if (mAPKID == null)
            mAPKID = savedInstanceState.getString(InstalledExternalApplication.KEY_APK_ID, null);
    }

    if (mAPKID == null)
        Log.e(LOG_TAG, "onCreateView the APKID was not set and not in the bundle");

    // check the presence of the formID
    if (mFormID == -1) {
        // the id is not set, it must be in the bundle
        mFormID = savedInstanceState.getInt(Form.KEY_FORM_ID, -1);
        if (mFormID == -1)
            // the id of the form was not in the bundle, this should never have happened
            Log.e(LOG_TAG, "onCreateView the formID was not set and not in the bundle");
    }

    ExternalApplication app;

    // get the corresponding installedApp
    if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) {
        app = HistoryExternalApplicationsManager.getInstance().getAppForId(mAPKID);
    } else {
        app = InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID);
    }

    if (app != null) {
        mForm = app.getSurvey().getForm(mFormID);
    }

    mRoot = (LinearLayout) inflater.inflate(R.layout.form, container, false);

    mScrollView = (ScrollView) mRoot.findViewById(R.id.scrollView1);

    // set focus to the dummy layout in order to prevent virtual keyboard from popping up
    View dummyLayout = mRoot.findViewById(R.id.dummy_layout_form);
    dummyLayout.requestFocus();

    addFormToLayout(mForm, mRoot);

    if (savedInstanceState != null) {
        if (mIsFirst == null)
            mIsFirst = savedInstanceState.getBoolean(KEY_IS_FIRST);

        if (mIsLast == null)
            mIsLast = savedInstanceState.getBoolean(KEY_IS_LAST);
    }

    return (View) mRoot;
}

From source file:com.amaze.carbonfilemanager.services.CopyService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    Bundle b = new Bundle();
    ArrayList<BaseFile> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
    String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
    int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
    final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt(TAG_COPY_START_ID, startId);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mBuilder = new NotificationCompat.Builder(c);
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setContentTitle(getResources().getString(R.string.copying))
            .setSmallIcon(R.drawable.ic_content_copy_white_36dp);

    startForeground(Integer.parseInt("456" + startId), mBuilder.build());

    b.putBoolean(TAG_COPY_MOVE, move);/*w  ww.j a v a  2  s. co  m*/
    b.putString(TAG_COPY_TARGET, targetPath);
    b.putInt(TAG_COPY_OPEN_MODE, mode);
    b.putParcelableArrayList(TAG_COPY_SOURCES, files);

    //going async
    new DoInBackground().execute(b);

    // If we get killed, after returning from here, restart
    return START_STICKY;
}

From source file:ch.fixme.status.Main.java

private void showHsInfo(Intent intent, Bundle savedInstanceState) {
    // Get hackerspace api url
    if (intent != null && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
        mApiUrl = mPrefs.getString(PREF_API_URL_WIDGET + intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID), ParseGeneric.API_DEFAULT);
    } else if (intent != null && intent.hasExtra(STATE_HS)) {
        mApiUrl = intent.getStringExtra(STATE_HS);
    } else {/*from ww w  . ja va 2  s.  c o  m*/
        mApiUrl = mPrefs.getString(PREF_API_URL, ParseGeneric.API_DEFAULT);
    }
    // Get Data
    final Bundle data = (Bundle) getLastNonConfigurationInstance();
    if (data == null || (savedInstanceState == null && !savedInstanceState.containsKey(STATE_HS))) {
        getApiTask = new GetApiTask();
        getApiTask.execute(mApiUrl);
    } else {
        finishApi = true;
        mResultHs = data.getString(STATE_HS);
        populateDataHs();
    }

    // Update widget
    Widget.UpdateAllWidgets(getApplicationContext());
}

From source file:eu.inmite.apps.smsjizdenka.service.UpdateService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;//from ww w. j a  v  a2 s  .  co m
    }
    final boolean force = intent.getBooleanExtra("force", false);
    try {
        Locale loc = Locale.getDefault();
        String lang = loc.getISO3Language(); // http://www.loc.gov/standards/iso639-2/php/code_list.php; T-values if present both T and B
        if (lang == null || lang.length() == 0) {
            lang = "";
        }

        int serverVersion = intent.getIntExtra("serverVersion", -1);
        boolean fromPush = serverVersion != -1;
        JSONObject versionJson = null;
        if (!fromPush) {
            versionJson = getVersion(true);
            serverVersion = versionJson.getInt("version");
        }
        int localVersion = Preferences.getInt(c, Preferences.DATA_VERSION, -1);
        final String localLanguage = Preferences.getString(c, Preferences.DATA_LANGUAGE, "");

        if (serverVersion <= localVersion && !force && lang.equals(localLanguage)
                && !LOCAL_DEFINITION_TESTING) {
            // don't update
            DebugLog.i("Nothing new, not updating");
            return;
        }

        // update but don't notify about it.
        boolean firstLaunchNoUpdate = ((localVersion == -1
                && getVersion(false).getInt("version") == serverVersion) || !lang.equals(localLanguage));

        if (!firstLaunchNoUpdate) {
            DebugLog.i("There are new definitions available!");
        }

        handleAuthorMessage(versionJson, lang, intent, fromPush);

        InputStream is = getIS(URL_TICKETS_ID);
        try {
            String json = readResult(is);

            JSONObject o = new JSONObject(json);
            JSONArray array = o.getJSONArray("tickets");

            final SQLiteDatabase db = DatabaseHelper.get(this).getWritableDatabase();
            for (int i = 0; i < array.length(); i++) {
                final JSONObject city = array.getJSONObject(i);
                try {

                    final ContentValues cv = new ContentValues();
                    cv.put(Cities._ID, city.getInt("id"));
                    cv.put(Cities.CITY, getStringLocValue(city, lang, "city"));
                    if (city.has("city_pubtran")) {
                        cv.put(Cities.CITY_PUBTRAN, city.getString("city_pubtran"));
                    }
                    cv.put(Cities.COUNTRY, city.getString("country"));
                    cv.put(Cities.CURRENCY, city.getString("currency"));
                    cv.put(Cities.DATE_FORMAT, city.getString("dateFormat"));
                    cv.put(Cities.IDENTIFICATION, city.getString("identification"));
                    cv.put(Cities.LAT, city.getDouble("lat"));
                    cv.put(Cities.LON, city.getDouble("lon"));
                    cv.put(Cities.NOTE, getStringLocValue(city, lang, "note"));
                    cv.put(Cities.NUMBER, city.getString("number"));
                    cv.put(Cities.P_DATE_FROM, city.getString("pDateFrom"));
                    cv.put(Cities.P_DATE_TO, city.getString("pDateTo"));
                    cv.put(Cities.P_HASH, city.getString("pHash"));
                    cv.put(Cities.PRICE, city.getString("price"));
                    cv.put(Cities.PRICE_NOTE, getStringLocValue(city, lang, "priceNote"));
                    cv.put(Cities.REQUEST, city.getString("request"));
                    cv.put(Cities.VALIDITY, city.getInt("validity"));
                    if (city.has("confirmReq")) {
                        cv.put(Cities.CONFIRM_REQ, city.getString("confirmReq"));
                    }
                    if (city.has("confirm")) {
                        cv.put(Cities.CONFIRM, city.getString("confirm"));
                    }

                    final JSONArray additionalNumbers = city.getJSONArray("additionalNumbers");
                    for (int j = 0; j < additionalNumbers.length() && j < 3; j++) {
                        cv.put("ADDITIONAL_NUMBER_" + (j + 1), additionalNumbers.getString(j));
                    }

                    db.beginTransaction();
                    int count = db.update(DatabaseHelper.CITY_TABLE_NAME, cv,
                            Cities._ID + " = " + cv.getAsInteger(Cities._ID), null);
                    if (count == 0) {
                        db.insert(DatabaseHelper.CITY_TABLE_NAME, null, cv);
                    }

                    db.setTransactionSuccessful();
                    getContentResolver().notifyChange(Cities.CONTENT_URI, null);
                } finally {
                    if (db.inTransaction()) {
                        db.endTransaction();
                    }
                }
            }
            Preferences.set(c, Preferences.DATA_VERSION, serverVersion);
            Preferences.set(c, Preferences.DATA_LANGUAGE, lang);
            if (!firstLaunchNoUpdate && !fromPush) {
                final int finalServerVersion = serverVersion;
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(UpdateService.this,
                                getString(R.string.cities_update_completed, finalServerVersion),
                                Toast.LENGTH_LONG).show();
                    }
                });
            }
            if (LOCAL_DEFINITION_TESTING) {
                DebugLog.w(
                        "Local definition testing - data updated from assets - must be removed in production!");
            }
        } finally {
            is.close();
        }
    } catch (IOException e) {
        DebugLog.e("IOException when calling update: " + e.getMessage(), e);
    } catch (JSONException e) {
        DebugLog.e("JSONException when calling update: " + e.getMessage(), e);
    }
}

From source file:org.peterbaldwin.vlcremote.app.PlaybackActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String host = intent.getStringExtra(Intents.EXTRA_REMOTE_HOST);
    if (host != null) {
        int port = intent.getIntExtra(Intents.EXTRA_REMOTE_PORT, 8080);
        String authority = host + ":" + port;
        changeServer(authority);// w  w w.ja va 2 s.  co  m
    }

    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intents.ACTION_REMOTE_VIEW.equals(action)
            || Intents.ACTION_VIEW.equals(action)) {
        Uri data = intent.getData();
        if (data != null) {
            changeInput(data.toString());
        }
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        String input = intent.getStringExtra(SearchManager.QUERY);
        changeInput(input);
    }
}

From source file:com.bluros.updater.service.UpdateCheckService.java

private void recordAvailableUpdates(LinkedList<UpdateInfo> availableUpdates, Intent finishedIntent) {

    if (availableUpdates == null) {
        sendBroadcast(finishedIntent);/*from   w  w  w .j ava  2 s .com*/
        return;
    }

    // Store the last update check time and ensure boot check completed is true
    Date d = new Date();
    PreferenceManager.getDefaultSharedPreferences(UpdateCheckService.this).edit()
            .putLong(Constants.LAST_UPDATE_CHECK_PREF, d.getTime())
            .putBoolean(Constants.BOOT_CHECK_COMPLETED, true).apply();

    int realUpdateCount = finishedIntent.getIntExtra(EXTRA_REAL_UPDATE_COUNT, 0);
    UpdateApplication app = (UpdateApplication) getApplicationContext();

    // Write to log
    Log.i(TAG, "The update check successfully completed at " + d + " and found " + availableUpdates.size()
            + " updates (" + realUpdateCount + " newer than installed)");

    if (realUpdateCount != 0 && !app.isMainActivityActive()) {
        // There are updates available
        // The notification should launch the main app
        Intent i = new Intent(this, UpdatesSettings.class);
        i.putExtra(UpdatesSettings.EXTRA_UPDATE_LIST_UPDATED, true);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_ONE_SHOT);

        Resources res = getResources();
        String text = res.getQuantityString(R.plurals.not_new_updates_found_body, realUpdateCount,
                realUpdateCount);

        // Get the notification ready
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_system_update).setWhen(System.currentTimeMillis())
                .setTicker(res.getString(R.string.not_new_updates_found_ticker))
                .setContentTitle(res.getString(R.string.not_new_updates_found_title)).setContentText(text)
                .setContentIntent(contentIntent).setLocalOnly(true).setAutoCancel(true);

        LinkedList<UpdateInfo> realUpdates = new LinkedList<UpdateInfo>();
        for (UpdateInfo ui : availableUpdates) {
            if (ui.isNewerThanInstalled()) {
                realUpdates.add(ui);
            }
        }

        Collections.sort(realUpdates, new Comparator<UpdateInfo>() {
            @Override
            public int compare(UpdateInfo lhs, UpdateInfo rhs) {
                /* sort by date descending */
                long lhsDate = lhs.getDate();
                long rhsDate = rhs.getDate();
                if (lhsDate == rhsDate) {
                    return 0;
                }
                return lhsDate < rhsDate ? 1 : -1;
            }
        });

        NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(builder)
                .setBigContentTitle(text);
        int added = 0, count = realUpdates.size();

        for (UpdateInfo ui : realUpdates) {
            if (added < EXPANDED_NOTIF_UPDATE_COUNT) {
                inbox.addLine(ui.getName());
                added++;
            }
        }
        if (added != count) {
            inbox.setSummaryText(
                    res.getQuantityString(R.plurals.not_additional_count, count - added, count - added));
        }
        builder.setStyle(inbox);
        builder.setNumber(availableUpdates.size());

        if (count == 1) {
            i = new Intent(this, DownloadReceiver.class);
            i.setAction(DownloadReceiver.ACTION_START_DOWNLOAD);
            i.putExtra(DownloadReceiver.EXTRA_UPDATE_INFO, (Parcelable) realUpdates.getFirst());
            PendingIntent downloadIntent = PendingIntent.getBroadcast(this, 0, i,
                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

            builder.addAction(R.drawable.ic_tab_download, res.getString(R.string.not_action_download),
                    downloadIntent);
        }

        // Trigger the notification
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(R.string.not_new_updates_found_title, builder.build());
    }

    sendBroadcast(finishedIntent);
}

From source file:com.coact.kochzap.CaptureActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_OK && requestCode == Constants.HISTORY_REQUEST_CODE && historyManager != null) {
        int itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER, -1);
        if (itemNumber >= 0) {
            HistoryItem historyItem = historyManager.buildHistoryItem(itemNumber);
            decodeOrStoreSavedBitmap(null, historyItem.getResult());
        }/*from w  w  w.j  a  v  a2  s . c  o m*/
    }
}