Intent getIntExtra - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Intent getIntExtra method.

This code example shows how to use the following methods:getAction, getIntExtra, getStringExtra
    private BroadcastReceiver mBroadcastReceiver =
                                             new BroadcastReceiver() { 
 
        @Override 
        public void onReceive(Context context, Intent intent) { 
            String action = intent.getAction(); 
            // ACTION_BATTERY_CHANGEDを受け取った時だけ処理する 
            if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { 
                // インテントから値を取得 
                int status = intent.getIntExtra("status", 0); 
                int health = intent.getIntExtra("health", 0); 
                int level = intent.getIntExtra("level", 0); 
                int plugged = intent.getIntExtra("plugged", 0); 
                int temperature = 
                    intent.getIntExtra("temperature", 0); 
                String technology = 
                    intent.getStringExtra("technology"); 
 
                // バッテリー状態を定数で判定して 
                // 意味の分かる文字列にする 
                String statusStr = ""; 
8
CodeRank
This code example shows how to use the following methods:getAction, getBooleanExtra, getIntExtra
        } 
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
            Log.e(LOGTAG, "Got an unexpected intent!");
            return; 
        } 
 
        boolean previousCharging = isCharging();
        double previousLevel = getLevel();
 
        // NOTE: it might not be common (in 2012) but technically, Android can run 
        // on a device that has no battery so we want to make sure it's not the case 
        // before bothering checking for battery state. 
        // However, the Galaxy Nexus phone advertizes itself as battery-less which 
        // force us to special-case the logic. 
        // See the Google bug: https://code.google.com/p/android/issues/detail?id=22035 
        if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false) ||

8
CodeRank
This code example shows how to use the following methods:getAction, getIntExtra
    } 
 
    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override 
        public void onReceive(Context context, Intent intent) { 
            String action = intent.getAction(); 
 
            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 
                mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); 
                mBatteryCharging = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0) == BatteryManager.BATTERY_STATUS_CHARGING; 
                if (mBatteryCharging && mBatteryLevel < 100) { 
                    start(); 
                } else { 
                    stop(); 
                } 
                setProgress(mBatteryLevel); 
            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { 
                stop(); 
            } else if (Intent.ACTION_SCREEN_ON.equals(action)) { 
                if (mBatteryCharging && mBatteryLevel < 100) { 
7
CodeRank
This code example shows how to use the following methods:getAction, getIntExtra
    private boolean mStateMachineEvent;
    private final IntentFilter mIntentFilter;
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override 
        public void onReceive(Context context, Intent intent) { 
            String action = intent.getAction(); 
            if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { 
                handleWifiStateChanged(intent.getIntExtra( 
                        WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)); 
            } else if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) { 
                if (!mConnected.get()) { 
                    handleStateChanged(WifiInfo.getDetailedStateOf((SupplicantState) 
                            intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE))); 
                } 
            } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { 
                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( 
                        WifiManager.EXTRA_NETWORK_INFO); 
                mConnected.set(info.isConnected()); 
                handleStateChanged(info.getDetailedState()); 
            } 
7
CodeRank
This code example shows how to use the following methods:getIntExtra
     * @return a JSONObject containing the battery status information 
     */ 
    private JSONObject getBatteryInfo(Intent batteryIntent) {
        JSONObject obj = new JSONObject();
        try { 
            obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0));
            obj.put("isPlugged", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false);
        } catch (JSONException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } 
        return obj;
    } 
 
    /** 
     * Updates the JavaScript side whenever the battery changes 
     * 
     * @param batteryIntent the current battery information 
     * @return 
     */ 
    private void updateBatteryInfo(Intent batteryIntent) {
7
CodeRank
This code example shows how to use the following methods:getIntExtra
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);                    
        mIntent = this.getIntent();
         
        quality = mIntent.getIntExtra("quality", 100);
         
         
        stopButton.setOnClickListener(mSnapListener);
    } 
     
    private OnClickListener mSnapListener = new OnClickListener() {
        public void onClick(View v) { 
        	mCamera.takePicture(null, null, mPictureCallback); 
        } 
    }; 
 
    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        MenuItem item = menu.add(0, 0, 0, "goto gallery");
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
7
CodeRank
This code example shows how to use the following methods:getIntExtra
This code example shows how to use the following methods:getAction, getIntExtra
	} 
 
	@Override 
	public void onReceive(Context context, Intent intent) {
		//MPDApplication app = (MPDApplication) context.getApplicationContext(); 
		String action = intent.getAction();
		if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
			System.out.println("WIFI-STATE:" + intent.getAction().toString());
			System.out.println("WIFI-STATE:" + (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)));
		} else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
			System.out.println("NETW-STATE:" + intent.getAction().toString());
			NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
			System.out.println("NETW-STATE: Connected: " + networkInfo.isConnected());
			System.out.println("NETW-STATE: Connected: " + networkInfo.getState().toString());
		} 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:getAction, getIntExtra
 
    private BroadcastReceiver headsetReceiver = new BroadcastReceiver() {
 
        @Override 
        public void onReceive(Context context, Intent intent) { 
            final String action = intent.getAction(); 
 
            if (Intent.ACTION_HEADSET_PLUG.equals(action)) { 
                final int userPreferenceAudioMode = getUserHeadphoneAudioMode(context); 
 
                if (userPreferenceAudioMode == MODE_UNTOUCHED) { 
                    return; 
                } 
 
                final int state = intent.getIntExtra("state", 0); 
 
                final AudioManager am = (AudioManager) context 
                        .getSystemService(Context.AUDIO_SERVICE); 
 
                if (state == 1) { 
6
CodeRank
This code example shows how to use the following methods:getIntExtra
    class HeadphonesReceiver extends BroadcastReceiver{
 
    	@Override 
    	public void onReceive(Context context, Intent intent) {
    		 
    		if(intent.getIntExtra("state",0)==0){
    			Log.i("OF","Headphones disconnected " + intent.getIntExtra("state",0));
    			headphonesConnected(false); 
    		}else{ 
    			Log.i("OF","Headphones connected " + intent.getIntExtra("state",0));
    			headphonesConnected(true); 
    		} 
    	} 
    	 
    } 
 
	 
} 
7
CodeRank

Related Intent getIntExtra Questions & Answers:

Other Intent getIntExtra Examples

6:	
7:	// Are we charging / charged?
8:	int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
9:	boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
10:	  || status == BatteryManager.BATTERY_STATUS_FULL;
-
13:	
14:	// How are we charging?
15:	int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
16:	boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
17:	boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

Read More

getIntExtra Method Overview
Retrieve extended data from the intent.
See Code Examples for other Android Intent Methods: