android.content.Intent.getIntExtra()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(693)

本文整理了Java中android.content.Intent.getIntExtra()方法的一些代码示例,展示了Intent.getIntExtra()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getIntExtra()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getIntExtra

Intent.getIntExtra介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public void onCreate() {
  BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
    int scale = -1;
    int level = -1;
    int voltage = -1;
    int temp = -1;
    @Override
    public void onReceive(Context context, Intent intent) {
      level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
      scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
      temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
      voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
      Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage);
    }
  };
  IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  registerReceiver(batteryReceiver, filter);
}

代码示例来源:origin: stackoverflow.com

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

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
      final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                         BluetoothAdapter.ERROR);
      switch (state) {
      case BluetoothAdapter.STATE_OFF:
        setButtonText("Bluetooth off");
        break;
      case BluetoothAdapter.STATE_TURNING_OFF:
        setButtonText("Turning Bluetooth off...");
        break;
      case BluetoothAdapter.STATE_ON:
        setButtonText("Bluetooth on");
        break;
      case BluetoothAdapter.STATE_TURNING_ON:
        setButtonText("Turning Bluetooth on...");
        break;
      }
    }
  }
};

代码示例来源:origin: stackoverflow.com

public class Main extends Activity {
 private TextView batteryTxt;
 private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
  @Override
  public void onReceive(Context ctxt, Intent intent) {
   int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
   batteryTxt.setText(String.valueOf(level) + "%");
  }
 };

 @Override
 public void onCreate(Bundle b) {
  super.onCreate(b);
  setContentView(R.layout.main);
  batteryTxt = (TextView) this.findViewById(R.id.batteryTxt);
  this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
 }
}

代码示例来源:origin: stackoverflow.com

public void onCreate() {
  BroadcastReceiver receiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
      int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
      if (plugged == BatteryManager.BATTERY_PLUGGED_AC) {
        // on AC power
      } else if (plugged == BatteryManager.BATTERY_PLUGGED_USB) {
        // on USB power
      } else if (plugged == 0) {
        // on battery power
      } else {
        // intent didnt include extra info
      }
    }
  };
  IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  registerReceiver(receiver, filter);
}

代码示例来源:origin: stackoverflow.com

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if ("android.net.wifi.WIFI_AP_STATE_CHANGED".equals(action)) {

       // get Wi-Fi Hotspot state here 
      int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);

      if (WifiManager.WIFI_STATE_ENABLED == state % 10) {
        // Wifi is enabled
      }

    }
  }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBondingBroadcastReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(final Context context, final Intent intent) {
    final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    final int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
    final int previousBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);

    Logger.d(TAG, "Bond state changed for: " + device.getAddress() + " new state: " + bondState + " previous: " + previousBondState);

    // skip other devices
    if (!device.getAddress().equals(mBluetoothGatt.getDevice().getAddress()))
      return;

    if (bondState == BluetoothDevice.BOND_BONDED) {
      // Continue to do what you've started before
      enableGlucoseMeasurementNotification(mBluetoothGatt);

      mContext.unregisterReceiver(this);
      mCallbacks.onBonded();
    }
  }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context arg0, Intent intent) {
    int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
    int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
    Log.v("MainActivity", "temperature " + temperature);
    Log.v("MainActivity", "health " + health);
  }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
  @Override
  public void onReceive(Context arg0, Intent intent) {

    int level = intent.getIntExtra("level", 0);

    int batteryIconId = intent.getIntExtra("icon-small", 0);
    Button toolBarBattery = (Button) findViewById(R.id.toolBarButton);

    LevelListDrawable batteryLevel = (LevelListDrawable) getResources().getDrawable(batteryIconId);
    batteryLevel.setLevel(level);

    toolBarBattery.setBackgroundDrawable(batteryLevel);

  }
};

代码示例来源:origin: stackoverflow.com

BroadcastReceiver mybatteryReceiver= new BroadcastReceiver() {
     public void onReceive(Context context, Intent intent) {
       int rawlevel = intent.getIntExtra("level", -1);
       int scale = intent.getIntExtra("scale", -1);
       int level = -1;
       if (rawlevel >= 0 && scale > 0) {
         level = (rawlevel * 100) / scale;
       }
       Log.d("TEMP","Battery Level in % is:: " + level + "%");
     }
   };

代码示例来源:origin: stackoverflow.com

// Broadcast receiver for PROGRESS BAR
BroadcastReceiver receiveProgress = new BroadcastReceiver(){
public void onReceive(android.content.Context context, Intent intent) {
  int progress    = intent.getIntExtra("int", 0);
  int progCounter = intent.getIntExtra("resultCounter", 0);
}

代码示例来源:origin: stackoverflow.com

BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
  int scale = -1;
  int level = -1;
  int voltage = -1;
  int temp = -1;
  @Override
  public void onReceive(Context context, Intent intent) {
    level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
    voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
    Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage);
  }
};

代码示例来源:origin: stackoverflow.com

BroadcastReceiver mColorChangedReceiver = new BroadcastReceiver()
{
  @Override
  public void onReceive(Context context, Intent intent)
  {
    int color = intent.getIntExtra("color", -1);
    myLO.setBackgroundColor(color);
  }
};

代码示例来源:origin: stackoverflow.com

final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
  @Override
   public void onReceive(Context context, Intent intent) {
    int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
    if (bondState == BluetoothDevice.BOND_BONDED) {
      //Trigger the sending via the above mentioned method
    }
  }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver myBatteryReceiver
    = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);

  }

};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
   @Override
   public void onReceive(Context arg0, Intent intent) {          
     int level = intent.getIntExtra("level", 0);
     // level...... it will show the battery information
     // you can use this variable to show the battery information.               
   }
};

代码示例来源:origin: stackoverflow.com

private final BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
  @Override
  public void onReceive(Context arg0, Intent intent) {
    int rawLevel = intent.getIntExtra("level", -1);
    int scale = intent.getIntExtra("scale", -1);
    int status = intent.getIntExtra("status", -1);
    // Do something
  }
};

public void onCreate() {
  registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}

public void onDestroy() {
   unregisterReceiver(this.mBatInfoReceiver);
}

代码示例来源:origin: stackoverflow.com

public class BatCheck extends Service {
 public void onCreate() {
  super.onCreate();

      BroadcastReceiver br = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
         boolean isCharged = status == BatteryManager.BATTERY_STATUS_FULL;

           if(isCharged){

             // write your code

             }
    }
  };

}

代码示例来源:origin: stackoverflow.com

public void onCreate(Bundle savedInstanceState) {
  ...
  this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  ...
}

private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    Estbatterylevel.setText("estimated battery" + level);
  }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver()  {
 @Override
 public void onReceive(Context arg0, Intent intent) {          
   int level = intent.getIntExtra("level", 0); 
     System.out.println("battery level" + level);            
 }
};

代码示例来源:origin: stackoverflow.com

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
         @Override
         public void onReceive(Context ctxt, Intent intent) {
          int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
          Log.e("ebre", level+"**");
     batteryTxt.setText(String.valueOf(level) + "");
         }
        };

相关文章

Intent类方法