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.cwp.cmoneycharge.activity.AddPayActivity.java

@Override
protected void onStart() { // ?onstart
    super.onStart();// 
    updateDisplay();// ?

    Intent intentr = getIntent();
    userid = intentr.getIntExtra("cwp.id", 100000001);
    bundle = intentr.getExtras();// ??Bundle
    if (bundle.containsKey("cwp.message")) {
        strInfos = bundle.getStringArray("cwp.message");// ?Bundle?
        strno = strInfos[0];// id
        strType = strInfos[1];// 
        typemode = "ModifyInPActivity";
        if (strType.equals("btnininfo")) { // 
            type = "income";
        } else {//from   w  ww .j  a v a2s . co  m
            type = "pay";
        }
    }
    keyBoard = new KeyboardUtil(this, this, txtMoney, typemode); // 
    if (bundle.containsKey("cwp.voice")) { // ?
        if (firstin) {
            bottom_empty.setVisibility(View.GONE);
            bottom_full.setVisibility(View.VISIBLE);
            dialogShowUtil.dialogShow("rotatebottom", "first", "", "");
            firstin = false;
        }
    }
    if (bundle.containsKey("cwp.photo")) {// ??
        if (firstin) {
            bottom_empty.setVisibility(View.GONE);
            bottom_full.setVisibility(View.VISIBLE);
            Intent intent = new Intent(AddPayActivity.this, PublishedActivity.class);
            intent.putExtra("cwp.id", userid);
            intent.putExtra("cwp.photo", "photo");
            startActivityForResult(intent, 102);
            firstin = false;
        }
    }
    if (bundle.containsKey("keyboard")) { // ?
        if (keycount) {
            InputMethodManager imm = (InputMethodManager) getSystemService(
                    AddPayActivity.this.INPUT_METHOD_SERVICE); // 
            imm.hideSoftInputFromWindow(txtMoney.getWindowToken(), 0); // ??
            keyBoard.showKeyboard();
            keycount = false;
        }
    }
    updatetype();
    txtTime.setOnTouchListener(new OnTouchListener() { // ??
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            showDialog(DATE_DIALOG_ID);// ?
            return false;
        }
    });

    txtMoney.setOnTouchListener(new OnTouchListener() { // ?
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(
                    AddPayActivity.this.INPUT_METHOD_SERVICE); // 
            imm.hideSoftInputFromWindow(txtMoney.getWindowToken(), 0); // ??
            keyBoard.showKeyboard();
            return false;
        }
    });

    //TODO  
    btnVoice.setOnClickListener(new OnClickListener() {// ?
        @Override
        public void onClick(View v) {
            dialogShowUtil.dialogShow("rotatebottom", "first", "", "");
            //VoiceRecognition();

        }
    });

    // ??
    btnSaveButton.setOnClickListener(new OnClickListener() {
        private String textreAddres;
        private String textreMark;

        @SuppressLint("NewApi")
        @Override
        public void onClick(View arg0) {
            textreAddres = txtAddress.getText().toString();
            textreMark = txtMark.getText().toString();
            if (textphoto == null) {
                textphoto = "";
            }
            if (typemode == "add") { // ?
                String strMoney = txtMoney.getText().toString();// ??
                if (type == "pay") { // 
                    if (!strMoney.isEmpty()) {// ??
                        // InaccountDAO
                        PayDAO payDAO = new PayDAO(AddPayActivity.this);
                        // Tb_inaccount
                        Tb_pay tb_pay = new Tb_pay(userid, payDAO.getMaxNo(userid) + 1, get2Double(strMoney),
                                setTimeFormat(null), (spType.getSelectedItemPosition() + 1), textreAddres,
                                textreMark, textphoto);
                        payDAO.add(tb_pay);// ?
                        Toast.makeText(AddPayActivity.this, "???",
                                Toast.LENGTH_SHORT).show();
                        gotoback();
                    } else {
                        Toast.makeText(AddPayActivity.this, "??", Toast.LENGTH_SHORT)
                                .show();
                    }
                } else { // 
                    if (!strMoney.isEmpty()) {// ??
                        // InaccountDAO
                        IncomeDAO incomeDAO = new IncomeDAO(AddPayActivity.this);
                        // Tb_inaccount
                        Tb_income tb_income = new Tb_income(userid, payDAO.getMaxNo(userid) + 1,
                                get2Double(strMoney), setTimeFormat(null),
                                (spType.getSelectedItemPosition() + 1),
                                // txtInhandler.getText().toString(),
                                textreAddres, textreMark, textphoto, "");
                        incomeDAO.add(tb_income);// ?
                        // ???
                        Toast.makeText(AddPayActivity.this, "???",
                                Toast.LENGTH_SHORT).show();
                        gotoback();
                    } else {
                        Toast.makeText(AddPayActivity.this, "??", Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            } else { // ?
                if (type == "pay") { // 
                    if (!txtMoney.getText().toString().isEmpty()) {// ??
                        Tb_pay tb_pay = new Tb_pay(); // Tb_pay
                        tb_pay.set_id(userid); // userid
                        tb_pay.setNo(Integer.parseInt(strno)); // ?
                        tb_pay.setMoney(get2Double(txtMoney.getText().toString()));// ?
                        tb_pay.setTime(setTimeFormat(txtTime.getText().toString()));// 
                        tb_pay.setType(spType.getSelectedItemPosition() + 1);// 
                        tb_pay.setAddress(textreAddres);// 
                        tb_pay.setMark(textreMark);// 
                        tb_pay.setPhoto(textphoto);// 
                        payDAO.update(tb_pay);// ?
                        Toast.makeText(AddPayActivity.this, "???", Toast.LENGTH_SHORT)
                                .show();
                        gotoback();
                    } else {
                        Toast.makeText(AddPayActivity.this, "??", Toast.LENGTH_SHORT)
                                .show();
                    }
                } else { // 
                    if (!txtMoney.getText().toString().isEmpty()) {// ??
                        Tb_income tb_income = new Tb_income();// Tb_income
                        tb_income.set_id(userid);// ?
                        tb_income.setNo(Integer.parseInt(strno));// ?
                        tb_income.setMoney(get2Double(txtMoney.getText().toString()));// ?
                        tb_income.setTime(setTimeFormat(txtTime.getText().toString()));// 
                        tb_income.setType(spType.getSelectedItemPosition() + 1);// 
                        tb_income.setHandler(textreAddres);// 
                        tb_income.setMark(textreMark);// 
                        tb_income.setPhoto(textphoto);// 
                        incomeDAO.update(tb_income);// ?
                        Toast.makeText(AddPayActivity.this, "???", Toast.LENGTH_SHORT)
                                .show();
                        gotoback();
                    } else {
                        Toast.makeText(AddPayActivity.this, "??", Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            }
        }
    });
    btnCancelButton.setOnClickListener(new OnClickListener() {// ???
        @Override
        public void onClick(View arg0) {

            if (typemode == "add") { // ?
                txtMoney.setText("");// ?
                txtMoney.setHint("0.00");// ???
                txtTime.setText("");// 
                txtAddress.setText("");// ?
                txtMark.setText("");// 
                // txtInhandler.setText("");// 
                spType.setSelection(0);// 
                gotoback();
            } else { // ?
                if (type == "pay") { // 
                    payDAO.detele(userid, Integer.parseInt(strno));// ???
                    gotoback();
                } else { // 
                    incomeDAO.detele(userid, Integer.parseInt(strno));// ???
                    gotoback();
                }
                Toast.makeText(AddPayActivity.this, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private void sendMmsMessage(String text, String[] addresses, Bitmap[] image, String[] imageNames, byte[] media,
        String mimeType, String subject) {
    // merge the string[] of addresses into a single string so they can be inserted into the database easier
    String address = "";

    for (int i = 0; i < addresses.length; i++) {
        address += addresses[i] + " ";
    }//  ww w  .jav a  2 s  . co m

    address = address.trim();

    // create the parts to send
    ArrayList<MMSPart> data = new ArrayList<>();

    for (int i = 0; i < image.length; i++) {
        // turn bitmap into byte array to be stored
        byte[] imageBytes = Message.bitmapToByteArray(image[i]);

        MMSPart part = new MMSPart();
        part.MimeType = "image/jpeg";
        part.Name = (imageNames != null) ? imageNames[i] : ("image" + i);
        part.Data = imageBytes;
        data.add(part);
    }

    // add any extra media according to their mimeType set in the message
    //      eg. videos, audio, contact cards, location maybe?
    if (media.length > 0 && mimeType != null) {
        MMSPart part = new MMSPart();
        part.MimeType = mimeType;
        part.Name = mimeType.split("/")[0];
        part.Data = media;
        data.add(part);
    }

    if (!text.equals("")) {
        // add text to the end of the part and send
        MMSPart part = new MMSPart();
        part.Name = "text";
        part.MimeType = "text/plain";
        part.Data = text.getBytes();
        data.add(part);
    }

    MessageInfo info;

    try {
        info = getBytes(context, saveMessage, address.split(" "), data.toArray(new MMSPart[data.size()]),
                subject);
    } catch (MmsException e) {
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
        return;
    }

    try {
        MmsMessageSender sender = new MmsMessageSender(context, info.location, info.bytes.length);
        sender.sendMessage(info.token);

        IntentFilter filter = new IntentFilter();
        filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION);
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                int progress = intent.getIntExtra("progress", -3);
                if (LOCAL_LOGV)
                    Log.v(TAG, "progress: " + progress);

                // send progress broadcast to update ui if desired...
                Intent progressIntent = new Intent(MMS_PROGRESS);
                progressIntent.putExtra("progress", progress);
                context.sendBroadcast(progressIntent);

                if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) {
                    context.sendBroadcast(new Intent(REFRESH));

                    try {
                        context.unregisterReceiver(this);
                    } catch (Exception e) {
                        // TODO fix me
                        // receiver is not registered force close error... hmm.
                    }
                } else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) {
                    // This seems to get called only after the progress has reached 100 and then something else goes wrong, so here we will try and send again and see if it works
                    if (LOCAL_LOGV)
                        Log.v(TAG, "sending aborted for some reason...");
                }
            }

        };

        context.registerReceiver(receiver, filter);
    } catch (Throwable e) {
        Log.e(TAG, "exception thrown", e);
        // insert the pdu into the database and return the bytes to send
        if (settings.getWifiMmsFix()) {
            sendMMS(info.bytes);
        } else {
            sendMMSWiFi(info.bytes);
        }
    }
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private void trySending(final APN apns, final byte[] bytesToSend, final int numRetries) {
    try {//from ww w.ja  v  a  2s  .co m
        IntentFilter filter = new IntentFilter();
        filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION);
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                int progress = intent.getIntExtra("progress", -3);
                if (LOCAL_LOGV)
                    Log.v(TAG, "progress: " + progress);

                // send progress broadcast to update ui if desired...
                Intent progressIntent = new Intent(MMS_PROGRESS);
                progressIntent.putExtra("progress", progress);
                context.sendBroadcast(progressIntent);

                if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) {
                    if (saveMessage) {
                        Cursor query = context.getContentResolver().query(Uri.parse("content://mms"),
                                new String[] { "_id" }, null, null, "date desc");
                        if (query != null && query.moveToFirst()) {
                            String id = query.getString(query.getColumnIndex("_id"));
                            query.close();

                            // move to the sent box
                            ContentValues values = new ContentValues();
                            values.put("msg_box", 2);
                            String where = "_id" + " = '" + id + "'";
                            context.getContentResolver().update(Uri.parse("content://mms"), values, where,
                                    null);
                        }
                    }

                    context.sendBroadcast(new Intent(REFRESH));

                    try {
                        context.unregisterReceiver(this);
                    } catch (Exception e) {
                        /* Receiver not registered */ }

                    // give everything time to finish up, may help the abort being shown after the progress is already 100
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mConnMgr.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE_MMS, "enableMMS");
                            if (settings.getWifiMmsFix()) {
                                reinstateWifi();
                            }
                        }
                    }, 1000);
                } else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) {
                    // This seems to get called only after the progress has reached 100 and then something else goes wrong, so here we will try and send again and see if it works
                    if (LOCAL_LOGV)
                        Log.v(TAG, "sending aborted for some reason...");
                    context.unregisterReceiver(this);

                    if (numRetries < NUM_RETRIES) {
                        // sleep and try again in three seconds to see if that give wifi and mobile data a chance to toggle in time
                        try {
                            Thread.sleep(3000);
                        } catch (Exception f) {

                        }

                        if (settings.getWifiMmsFix()) {
                            sendMMS(bytesToSend);
                        } else {
                            sendMMSWiFi(bytesToSend);
                        }
                    } else {
                        markMmsFailed();
                    }
                }
            }

        };

        context.registerReceiver(receiver, filter);

        // This is where the actual post request is made to send the bytes we previously created through the given apns
        if (LOCAL_LOGV)
            Log.v(TAG, "attempt: " + numRetries);
        Utils.ensureRouteToHost(context, apns.MMSCenterUrl, apns.MMSProxy);
        HttpUtils.httpConnection(context, 4444L, apns.MMSCenterUrl, bytesToSend, HttpUtils.HTTP_POST_METHOD,
                !TextUtils.isEmpty(apns.MMSProxy), apns.MMSProxy, Integer.parseInt(apns.MMSPort));
    } catch (IOException e) {
        if (LOCAL_LOGV)
            Log.v(TAG, "some type of error happened when actually sending maybe?");
        Log.e(TAG, "exception thrown", e);

        if (numRetries < NUM_RETRIES) {
            // sleep and try again in three seconds to see if that give wifi and mobile data a chance to toggle in time
            try {
                Thread.sleep(3000);
            } catch (Exception f) {

            }

            trySending(apns, bytesToSend, numRetries + 1);
        } else {
            markMmsFailed();
        }
    }
}

From source file:ch.ethz.twimight.activities.ShowUserListActivity.java

/** 
 * Called when the activity is first created. 
 *///from  w w w  . j av  a  2s  . co m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    //action bar
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Bundle bundle = new Bundle();
    bundle.putInt(ListViewPageAdapter.BUNDLE_TYPE, ListViewPageAdapter.BUNDLE_TYPE_USERS);
    ListViewPageAdapter pagAdapter = new ListViewPageAdapter(getFragmentManager(), bundle);
    viewPager = (ViewPager) findViewById(R.id.viewpager);

    viewPager.setAdapter(pagAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between pages, select the
            // corresponding tab.
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    Tab tab = actionBar.newTab().setText(R.string.friends).setTabListener(new TabListener(viewPager));
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.followers).setTabListener(new TabListener(viewPager));
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.peers).setTabListener(new TabListener(viewPager));
    actionBar.addTab(tab);

    //actionBar.setSelectedNavigationItem(intent.getIntExtra(USER_FILTER_REQUEST, FRIENDS_KEY));
    viewPager.setCurrentItem(intent.getIntExtra(USER_FILTER_REQUEST, 0));

}

From source file:fr.eyal.lib.data.service.DataLibService.java

/**
 * Send the result of a request to the linked {@link ServiceHelper}
 * // w w w  . ja  v  a  2s  .  c  om
 * @param request the request
 * @param response the response
 * @param code the status of the request
 */
protected void sendResult(final DataLibRequest request, final BusinessResponse response, final int code) {
    Out.d(TAG, "sendResult");

    final Intent intent = request.intent;
    final ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra(INTENT_EXTRA_RECEIVER);

    if (receiver != null) {
        final Bundle b = new Bundle();

        if (response != null && response.response != null) {

            //if the Business Object have to be transmit inside the Bundle
            if (request.isParcelableMethodEnabled())
                b.putParcelable(ServiceHelper.RECEIVER_EXTRA_RESULT, response.response);

            //we add the request id to the response
            if (response.response instanceof ResponseBusinessObjectDAO) {
                ResponseBusinessObjectDAO r = (ResponseBusinessObjectDAO) response.response;
                b.putLong(ServiceHelper.RECEIVER_EXTRA_RESULT_ID, r._id);
            } else {
                //in case of no data cache, we set an invalid ID
                b.putLong(ServiceHelper.RECEIVER_EXTRA_RESULT_ID, BusinessObjectDAO.ID_INVALID);
            }

        } else {
            Out.e(TAG, "Unfined response");
        }

        //we copy the content of the response in the intent's bundle
        b.putInt(ServiceHelper.RECEIVER_EXTRA_REQUEST_ID, intent.getIntExtra(INTENT_EXTRA_REQUEST_ID, -1));
        b.putInt(ServiceHelper.RECEIVER_EXTRA_WEBSERVICE_TYPE,
                intent.getIntExtra(INTENT_EXTRA_PROCESSOR_TYPE, -1));
        b.putInt(ServiceHelper.RECEIVER_EXTRA_RETURN_CODE, response.returnCode);
        b.putInt(ServiceHelper.RECEIVER_EXTRA_RESULT_CODE, response.status);
        b.putString(ServiceHelper.RECEIVER_EXTRA_RESULT_MESSAGE, "");

        receiver.send(code, b);
    }
}

From source file:com.android.ex.photo.PhotoViewActivity.java

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

    final ActivityManager mgr = (ActivityManager) getApplicationContext()
            .getSystemService(Activity.ACTIVITY_SERVICE);
    sMemoryClass = mgr.getMemoryClass();

    Intent mIntent = getIntent();

    int currentItem = -1;
    if (savedInstanceState != null) {
        currentItem = savedInstanceState.getInt(STATE_ITEM_KEY, -1);
        mFullScreen = savedInstanceState.getBoolean(STATE_FULLSCREEN_KEY, false);
    }/*from  w  w w. j a v a  2 s  .c om*/

    // uri of the photos to view; optional
    if (mIntent.hasExtra(Intents.EXTRA_PHOTOS_URI)) {
        mPhotosUri = mIntent.getStringExtra(Intents.EXTRA_PHOTOS_URI);
    }

    // projection for the query; optional
    // I.f not set, the default projection is used.
    // This projection must include the columns from the default projection.
    if (mIntent.hasExtra(Intents.EXTRA_PROJECTION)) {
        mProjection = mIntent.getStringArrayExtra(Intents.EXTRA_PROJECTION);
    } else {
        mProjection = null;
    }

    // Set the current item from the intent if wasn't in the saved instance
    if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) {
        currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1);
    }
    mPhotoIndex = currentItem;

    setContentView(R.layout.photo_activity_view);

    // Create the adapter and add the view pager
    mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null);

    mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOnInterceptTouchListener(this);

    // Kick off the loader
    getLoaderManager().initLoader(LOADER_PHOTO_LIST, null, this);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    mActionBarHideDelayTime = getResources().getInteger(R.integer.action_bar_delay_time_in_millis);
    actionBar.addOnMenuVisibilityListener(this);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
}

From source file:com.horizondigital.delta.UpdateService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (ACTION_CHECK.equals(intent.getAction())) {
            checkForUpdates(true);// w w w.  j  a  va2s .  c o  m
        } else if (ACTION_FLASH.equals(intent.getAction())) {
            flashUpdate();
        } else if (ACTION_ALARM.equals(intent.getAction())) {
            scheduler.alarm(intent.getIntExtra(EXTRA_ALARM_ID, -1));
            autoState();
        } else if (ACTION_NOTIFICATION_DELETED.equals(intent.getAction())) {
            Logger.i("Snoozing for 24 hours");
            prefs.edit().putLong(PREF_LAST_SNOOZE_TIME_NAME, System.currentTimeMillis()).commit();
            autoState();
        }
    }

    return START_STICKY;
}

From source file:com.commontime.plugin.LocationManager.java

private void initBluetoothListener() {

    //check access
    if (!hasBlueToothPermission()) {
        debugWarn("Cannot listen to Bluetooth service when BLUETOOTH permission is not added");
        return;/*from   w  w  w. java 2s .co m*/
    }

    //check device support
    try {
        iBeaconManager.checkAvailability();
    } catch (Exception e) {
        //if device does not support iBeacons an error is thrown
        debugWarn("Cannot listen to Bluetooth service: " + e.getMessage());
        return;
    }

    if (broadcastReceiver != null) {
        debugWarn("Already listening to Bluetooth service, not adding again");
        return;
    }

    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();

            // Only listen for Bluetooth server changes
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {

                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
                final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                        BluetoothAdapter.ERROR);

                debugLog("Bluetooth Service state changed from " + getStateDescription(oldState) + " to "
                        + getStateDescription(state));

                switch (state) {
                case BluetoothAdapter.ERROR:
                    beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusNotDetermined");
                    break;
                case BluetoothAdapter.STATE_OFF:
                case BluetoothAdapter.STATE_TURNING_OFF:
                    if (oldState == BluetoothAdapter.STATE_ON)
                        beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusDenied");
                    break;
                case BluetoothAdapter.STATE_ON:
                    beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusAuthorized");
                    break;
                case BluetoothAdapter.STATE_TURNING_ON:
                    break;
                }
            }
        }

        private String getStateDescription(int state) {
            switch (state) {
            case BluetoothAdapter.ERROR:
                return "ERROR";
            case BluetoothAdapter.STATE_OFF:
                return "STATE_OFF";
            case BluetoothAdapter.STATE_TURNING_OFF:
                return "STATE_TURNING_OFF";
            case BluetoothAdapter.STATE_ON:
                return "STATE_ON";
            case BluetoothAdapter.STATE_TURNING_ON:
                return "STATE_TURNING_ON";
            }
            return "ERROR" + state;
        }
    };

    // Register for broadcasts on BluetoothAdapter state change
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    cordova.getActivity().registerReceiver(broadcastReceiver, filter);
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

private int getScrollToMessagePosition() {
    final Activity activity = getActivity();
    if (activity == null) {
        return -1;
    }/*from  w ww  .j a v  a  2  s.  co  m*/

    final Intent intent = activity.getIntent();
    if (intent == null) {
        return -1;
    }

    return intent.getIntExtra(UIIntents.UI_INTENT_EXTRA_MESSAGE_POSITION, -1);
}