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.better.alarm.presenter.alert.AlarmAlertReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    mContext = context;/* w w  w.j  a  v  a  2  s  .  c o  m*/
    alarmsManager = AlarmsManager.getAlarmsManager();
    nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    String action = intent.getAction();
    int id = intent.getIntExtra(Intents.EXTRA_ID, -1);
    try {
        if (id != -1) {
            alarm = alarmsManager.getAlarm(id);
        }

        if (action.equals(Intents.ALARM_ALERT_ACTION) || action.equals(Intents.ALARM_PREALARM_ACTION)) {
            // our alarm fired again, remove snooze notification
            nm.cancel(id + NOTIFICATION_OFFSET);
            onAlert(alarm);

        } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) {
            nm.cancel(id);
            nm.cancel(id + NOTIFICATION_OFFSET);

        } else if (action.equals(Intents.ACTION_CANCEL_SNOOZE)) {
            nm.cancel(id);
            nm.cancel(id + NOTIFICATION_OFFSET);

        } else if (action.equals(Intents.ALARM_SNOOZE_ACTION)) {
            nm.cancel(id);
            onSnoozed(id);

        } else if (action.equals(Intents.ACTION_SOUND_EXPIRED)) {
            onSoundExpired(id);

        } else if (action.equals(ACTION_CANCEL_NOTIFICATION)) {
            alarmsManager.dismiss(alarm);
        }
    } catch (AlarmNotFoundException e) {
        Logger.getDefaultLogger().d("Alarm not found");
        nm.cancel(id);
        nm.cancel(id + NOTIFICATION_OFFSET);
    }
}

From source file:com.microsoft.onenote.pickerlib.OneNotePickerActivity.java

private void readExtras() {
    Intent intent = getIntent();
    mNavTextColor = intent.getIntExtra("NAV_TEXT_COLOR", -1);
    mAccessToken = intent.getStringExtra("ACCESS_TOKEN");
    mThemeColor = (OneNotePickerThemeColor) intent.getSerializableExtra("THEME_COLOR");
}

From source file:com.android.deskclock.DeskClock.java

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

    mSelectedTab = CLOCK_TAB_INDEX;/*from w w w .ja v a  2s  .c  o  m*/
    if (icicle != null) {
        mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX);
    }

    // Timer receiver may ask the app to go to the timer fragment if a timer expired
    Intent i = getIntent();
    if (i != null) {
        int tab = i.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        if (tab != -1) {
            mSelectedTab = tab;
        }
    }
    initViews();
    setHomeTimeZone();
}

From source file:anakiou.com.picontrol.service.InputIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    receiver = intent.getParcelableExtra(Constants.RECEIVER);

    if (!networkService.isNetworkAvailableAndConnected()) {

        deliverResultToReceiver(Constants.FAILURE_RESULT, getString(R.string.network_required_msg));

        return;/* w w  w.  j ava2  s .c  om*/
    }

    int operationType = intent.getIntExtra(Constants.EXTRA_OPERATION_TYPE, 0);

    switch (operationType) {
    case Constants.OP_INPUT_GET:
        handleGet();
        break;
    case Constants.OP_INPUT_STATUS_ALL_GET:
        handleStatusAllGet();
        break;
    case Constants.OP_INPUT_NAME_SET:
        handleNameSet(intent);
        break;
    }
}

From source file:com.androidpi.bricks.gallery.lru.ImageDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    final List<ImageFileEntry> entries = (ArrayList<ImageFileEntry>) intent
            .getSerializableExtra(EXTRA_IMAGE_ENTRIES);
    final int currentItem = intent.getIntExtra(EXTRA_CURRENT_ENTRY_POS, -1);
    // Set up ViewPager and backing adapter
    // mAdapter = new ImagePagerAdapter(getSupportFragmentManager(),
    // Images.imageUrls.length);
    mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), entries);
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);//from ww  w. jav  a2s  . com
    mPager.setPageMargin((int) getResources().getDimension(R.dimen.horizontal_page_margin));
    mPager.setOffscreenPageLimit(2);

    mTvEdit = (TextView) findViewById(R.id.tv_edit);

    // Set up activity to go full screen
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

    // Enable some additional newer visibility and ActionBar features to
    // create a more
    // immersive photo viewing experience
    if (AppUtil.hasHoneycomb()) {
        final ActionBar actionBar = getSupportActionBar();

        // Hide title text and set home as up
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Hide and show the ActionBar as the visibility changes
        mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int vis) {
                if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                    actionBar.hide();
                } else {
                    actionBar.show();
                }
            }
        });

        // Start low profile mode and hide ActionBar
        mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        actionBar.hide();
    }

    // Set the current item based on the extra passed in to this activity

    if (currentItem != -1) {
        mPager.setCurrentItem(currentItem);
    }

    // Fetch screen height and width, to use as our max size when loading
    // images as this
    // activity runs full screen
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;

    // For this sample we'll use half of the longest width to resize our
    // images. As the
    // image scaling ensures the image is larger than this, we should be
    // left with a
    // resolution that is appropriate for both portrait and landscape. For
    // best image quality
    // we shouldn't divide by 2, but this will use more memory and require a
    // larger memory
    // cache.
    final int longest = (height > width ? height : width) / 2;

    ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(this, IMAGE_CACHE_DIR);
    cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of
    // app memory

    // The ImageFetcher takes care of loading images into our ImageView
    // children asynchronously
    mImageResizer = new ImageResizer(this, longest);
    mImageResizer.addImageCache(getSupportFragmentManager(), cacheParams);
    mImageResizer.setImageFadeIn(false);

    mTvEdit.setOnClickListener(this);
}

From source file:com.b44t.messenger.AutoMessageReplyReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;/*from w ww  .ja  v a 2s. c  o m*/
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null);
    MrMailbox.markseenChat((int) dialog_id);
    NotificationsController.getInstance().removeSeenMessages();
}

From source file:com.anjlab.android.iab.v3.BillingProcessor.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != PURCHASE_FLOW_REQUEST_CODE)
        return false;
    int responseCode = data.getIntExtra(Constants.RESPONSE_CODE, Constants.BILLING_RESPONSE_RESULT_OK);
    Log.d(LOG_TAG, String.format("resultCode = %d, responseCode = %d", resultCode, responseCode));
    String purchasePayload = getPurchasePayload();
    if (resultCode == Activity.RESULT_OK && responseCode == Constants.BILLING_RESPONSE_RESULT_OK
            && !TextUtils.isEmpty(purchasePayload)) {
        String purchaseData = data.getStringExtra(Constants.INAPP_PURCHASE_DATA);
        String dataSignature = data.getStringExtra(Constants.RESPONSE_INAPP_SIGNATURE);
        try {/*from   w w w .  j av  a2s .  c o m*/
            JSONObject purchase = new JSONObject(purchaseData);
            String productId = purchase.getString(Constants.RESPONSE_PRODUCT_ID);
            String developerPayload = purchase.getString(Constants.RESPONSE_PAYLOAD);
            if (developerPayload == null)
                developerPayload = "";
            boolean purchasedSubscription = purchasePayload.startsWith(Constants.PRODUCT_TYPE_SUBSCRIPTION);
            if (purchasePayload.equals(developerPayload)) {
                if (verifyPurchaseSignature(productId, purchaseData, dataSignature)) {
                    BillingCache cache = purchasedSubscription ? cachedSubscriptions : cachedProducts;
                    cache.put(productId, purchaseData, dataSignature);
                    if (eventHandler != null)
                        eventHandler.onProductPurchased(productId,
                                new TransactionDetails(new PurchaseInfo(purchaseData, dataSignature)));
                } else {
                    Log.e(LOG_TAG, "Public key signature doesn't match!");
                    if (eventHandler != null)
                        eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
                }
            } else {
                Log.e(LOG_TAG, String.format("Payload mismatch: %s != %s", purchasePayload, developerPayload));
                if (eventHandler != null)
                    eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
            if (eventHandler != null)
                eventHandler.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, null);
        }
    } else {
        if (eventHandler != null)
            eventHandler.onBillingError(responseCode, null);
    }
    return true;
}

From source file:com.otaupdater.SettingsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PROKEY_REQ_CODE) {
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseDataStr = data.getStringExtra("INAPP_PURCHASE_DATA");

        //TODO need moar verification!

        if (resultCode == RESULT_OK) {
            if (responseCode == 0) {
                try {
                    JSONObject purchaseData = new JSONObject(purchaseDataStr);
                    if (purchaseData.getString("productId").equals(Config.PROKEY_SKU)) {
                        cfg.setKeyPurchaseToken(purchaseData.getString("purchaseToken"));
                        updateProKeySummary();
                        Toast.makeText(this, R.string.prokey_success, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, R.string.prokey_error_other, Toast.LENGTH_SHORT).show();
                    }/*from  w  ww  .  jav  a2s  .  c om*/
                } catch (JSONException e) {
                    Toast.makeText(this, R.string.prokey_error_other, Toast.LENGTH_SHORT).show();
                }
            } else if (responseCode == 1) {
                Toast.makeText(this, R.string.prokey_error_cancelled, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, R.string.prokey_error_other, Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, R.string.prokey_error_other, Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.callba.phone.ui.GroupSimpleDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv_name = (TextView) findViewById(R.id.name);
    tv_admin = (TextView) findViewById(R.id.tv_admin);
    btn_add_group = (Button) findViewById(R.id.btn_add_to_group);
    tv_introduction = (TextView) findViewById(R.id.tv_introduction);
    tv_id = (TextView) findViewById(R.id.tv_id);
    tv_need_apply = (TextView) findViewById(R.id.tv_need_apply);
    introduction = (LinearLayout) findViewById(R.id.introduction);

    introduction.setOnClickListener(new View.OnClickListener() {
        @Override//  w  w w . j  a va  2 s .c o m
        public void onClick(View v) {
            if (!group.getDescription().equals("")) {
                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                        GroupSimpleDetailActivity.this);
                builder.setMessage(group.getDescription());
                android.app.AlertDialog alertDialog = builder.create();
                alertDialog.setCanceledOnTouchOutside(true);
                alertDialog.setCancelable(true);
                alertDialog.show();
            }
        }
    });
    final EMGroupInfo groupInfo = (EMGroupInfo) getIntent().getSerializableExtra("groupinfo");
    String groupname = groupInfo.getGroupName();
    groupid = groupInfo.getGroupId();
    tv_name.setText(groupname);
    tv_id.setText(groupid);
    if (group != null) {
        showGroupDetail();
        return;
    }
    new Thread(new Runnable() {

        public void run() {
            //??
            try {
                group = EMClient.getInstance().groupManager().getGroupFromServer(groupid);

                runOnUiThread(new Runnable() {
                    public void run() {
                        showGroupDetail();
                        tv_need_apply.setText(group.isMembersOnly() ? "" : "?");
                    }
                });
            } catch (final HyphenateException e) {
                e.printStackTrace();
                final String st1 = getResources().getString(R.string.Failed_to_get_group_chat_information);
                runOnUiThread(new Runnable() {
                    public void run() {
                        //progressBar.setVisibility(View.INVISIBLE);
                        Toast.makeText(GroupSimpleDetailActivity.this, st1 + e.getMessage(), Toast.LENGTH_SHORT)
                                .show();

                    }
                });
            }

        }
    }).start();
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getExtras() != null) {
                if (intent.getStringExtra("group_id").equals(groupInfo.getGroupId())) {
                    if (intent.getIntExtra("result", 0) == 1)
                        finish();
                    else
                        btn_add_group.setEnabled(true);

                }
            }
        }
    };
    broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(broadcastReceiver, new IntentFilter(Constant.ACTION_GROUP_CHANAGED));
}

From source file:com.cattle.PhotoViewerActivity.java

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

    setContentView(R.layout.activity_photo_viewer);
    mContentView = (ViewGroup) findViewById(R.id.fl_root);

    mController = PhotoUploadController.getFromContext(this);
    EventBus.getDefault().register(this);

    final Intent intent = getIntent();
    mMode = intent.getIntExtra(EXTRA_MODE, MODE_ALL_VALUE);

    if (mMode == MODE_ALL_VALUE) {
        mBucketId = intent.getStringExtra(EXTRA_BUCKET_ID);
    }/*from w  ww.j av  a2  s  . c  om*/

    mViewPager = (ViewPager) findViewById(R.id.vp_photos);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.viewpager_margin));
    mViewPager.setOnPageChangeListener(this);

    if (mMode == MODE_ALL_VALUE) {
        mAdapter = new UserPhotosViewPagerAdapter(this, this, this);
        getSupportLoaderManager().initLoader(0, null, this);
    } else {
        mAdapter = new SelectedPhotosViewPagerAdapter(this, this, this);
    }
    mViewPager.setAdapter(mAdapter);

    if (intent.hasExtra(EXTRA_POSITION)) {
        mRequestedPosition = intent.getIntExtra(EXTRA_POSITION, 0);
        mViewPager.setCurrentItem(mRequestedPosition);
    }

    mFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.photo_fade_out);
    mFriendsFragment = new FriendsListFragment();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(" ");

    /**
     * Nasty hack, basically we need to know when the ViewPager is laid out,
     * we then manually call onPageSelected. This is to fix onPageSelected
     * not being called on the first item.
     */
    mViewPager.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            mViewPager.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            onPageSelected(mViewPager.getCurrentItem());
            showTapToTagPrompt();
        }
    });

}