Java Code Examples for android.net.wifi.WifiManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project tagin, under directory /android-engine/src/ca/idi/taginsdk/tools/.

Source file: LoggerHelp.java

  24 
vote

public Boolean CheckWiFiEnabled(){
  WifiManager mWifiManager;
  mWifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
  if (mWifiManager.isWifiEnabled()) {
    return true;
  }
 else {
    return false;
  }
}
 

Example 2

From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/services/.

Source file: SyncServices.java

  24 
vote

synchronized private static WifiManager.WifiLock getPhoneWifiLock(Context context){
  if (wifilock == null) {
    WifiManager manager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    wifilock=manager.createWifiLock(WifiManager.WIFI_MODE_FULL,CLASS_TAG);
  }
  return wifilock;
}
 

Example 3

From project Gmote, under directory /gmoteclient/src/org/gmote/client/android/.

Source file: ActivityUtil.java

  23 
vote

public void onStart(Activity activity){
  mActivity=activity;
  if (wifiLock == null) {
    PowerManager powerManager=(PowerManager)mActivity.getSystemService(Context.POWER_SERVICE);
    wakeLock=powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,DEBUG_TAG);
    wakeLock.setReferenceCounted(true);
    WifiManager wifiManager=(WifiManager)mActivity.getSystemService(Context.WIFI_SERVICE);
    wifiLock=wifiManager.createWifiLock(DEBUG_TAG);
    wifiLock.setReferenceCounted(true);
  }
  Log.e(mActivity.getClass().getName(),"ACQUIRE");
  wifiLock.acquire();
  wakeLock.acquire();
}
 

Example 4

From project syplod, under directory /src/com/android/picasaphotouploader/.

Source file: CheckInternet.java

  23 
vote

/** 
 * Can we connect to the internet or not, checks if device has connection and if wifi is on if user has set that in the connection preference
 * @param context Application context
 * @param prefs User preferences
 * @return Can connect to internet or not
 */
@SuppressWarnings("static-access") public boolean canConnect(Context context,SharedPreferences prefs){
  WifiManager wifi=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  if (wifi.getWifiState() != wifi.WIFI_STATE_ENABLED && prefs.getString("connection","").equals(CON_WIFI)) {
    return false;
  }
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (manager.getActiveNetworkInfo() == null || !manager.getActiveNetworkInfo().isConnected()) {
    return false;
  }
  return true;
}
 

Example 5

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  22 
vote

private void setWifiStatus(){
  WifiManager wifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  Preference wifiMacAddressPref=findPreference(KEY_WIFI_MAC_ADDRESS);
  String macAddress=wifiInfo == null ? null : wifiInfo.getMacAddress();
  wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : getString(R.string.status_unavailable));
}
 

Example 6

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdkutility/.

Source file: DeviceId.java

  22 
vote

public static String getMACAddress(Context context){
  String macAddress=null;
  try {
    PackageManager pm=context.getPackageManager();
    if (PackageManager.PERMISSION_GRANTED == pm.checkPermission(Manifest.permission.ACCESS_WIFI_STATE,context.getPackageName())) {
      WifiManager wifiMan=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
      WifiInfo wifiInf=wifiMan.getConnectionInfo();
      macAddress=wifiInf.getMacAddress();
    }
  }
 catch (  Exception e) {
    return null;
  }
  return macAddress;
}
 

Example 7

From project BombusLime, under directory /src/org/bombusim/lime/service/.

Source file: XmppService.java

  22 
vote

private void setWiFiLock(boolean locked){
  if (!Lime.getInstance().prefs.wifiLock)   return;
  if (!locked) {
    if (mWiFiLock == null)     return;
    mWiFiLock.release();
    return;
  }
  WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  if (mWiFiLock == null)   mWiFiLock=wm.createWifiLock(WifiManager.WIFI_MODE_FULL,"org.bombusim.lime");
  mWiFiLock.setReferenceCounted(false);
  mWiFiLock.acquire();
}
 

Example 8

From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.

Source file: SystemLib.java

  22 
vote

/** 
 * get current wifi mac address
 */
public String getWlanMacAddress(){
  WifiManager wifiManager=(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  String macAddress=wifiInfo == null ? null : wifiInfo.getMacAddress();
  return !TextUtils.isEmpty(macAddress) ? macAddress : "Unavailable";
}
 

Example 9

From project CHMI, under directory /src/org/kaldax/app/chmi/.

Source file: CHMI.java

  22 
vote

private boolean anyNetworkActive(){
  TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  WifiInfo wi=wm.getConnectionInfo();
  return !((wi == null || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.IDLE) && tm.getDataState() != TelephonyManager.DATA_CONNECTED);
}
 

Example 10

From project connectbot, under directory /src/sk/vx/connectbot/service/.

Source file: ConnectivityReceiver.java

  22 
vote

public ConnectivityReceiver(TerminalManager manager,boolean lockingWifi){
  mTerminalManager=manager;
  final ConnectivityManager cm=(ConnectivityManager)manager.getSystemService(Context.CONNECTIVITY_SERVICE);
  final WifiManager wm=(WifiManager)manager.getSystemService(Context.WIFI_SERVICE);
  mWifiLock=wm.createWifiLock(TAG);
  final NetworkInfo info=cm.getActiveNetworkInfo();
  if (info != null) {
    mIsConnected=(info.getState() == State.CONNECTED);
  }
  mLockingWifi=lockingWifi;
  final IntentFilter filter=new IntentFilter();
  filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
  manager.registerReceiver(this,filter);
}
 

Example 11

From project creamed_glacier_app_settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  22 
vote

private void setWifiStatus(){
  WifiManager wifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  Preference wifiMacAddressPref=findPreference(KEY_WIFI_MAC_ADDRESS);
  String macAddress=wifiInfo == null ? null : wifiInfo.getMacAddress();
  wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : getString(R.string.status_unavailable));
}
 

Example 12

From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/.

Source file: ServerBonjourListActivity.java

  22 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  servers=new ArrayList<Map<String,String>>();
  WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  multicastLock=wm.createMulticastLock("mpdroid_bonjour");
  try {
    jmdns=JmDNS.create();
    jmdns.addServiceListener("_mpd._tcp.local.",this);
  }
 catch (  IOException e) {
  }
  listAdapter=new SimpleAdapter(this,servers,android.R.layout.simple_list_item_1,new String[]{SERVER_NAME},new int[]{android.R.id.text1});
  getListView().setAdapter(listAdapter);
}
 

Example 13

From project FileExplorer, under directory /src/net/micode/fileexplorer/.

Source file: FTPServerService.java

  22 
vote

private void takeWifiLock(){
  myLog.d("Taking wifi lock");
  if (wifiLock == null) {
    WifiManager manager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
    wifiLock=manager.createWifiLock("SwiFTP");
    wifiLock.setReferenceCounted(false);
  }
  wifiLock.acquire();
}
 

Example 14

From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/powerwidget/.

Source file: WifiApButton.java

  22 
vote

@Override public int getActualState(Context context){
  WifiManager wifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  if (wifiManager != null) {
    return wifiApStateToFiveState(wifiManager.getWifiApState());
  }
  return STATE_UNKNOWN;
}
 

Example 15

From project LoL-Chat, under directory /src/com/rei/lolchat/utils/.

Source file: BeemConnectivity.java

  22 
vote

/** 
 * Checks if is wifi.
 * @param ctx the ctx
 * @return true, if is wifi
 */
public static boolean isWifi(final Context ctx){
  WifiManager wm=(WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wi=wm.getConnectionInfo();
  if (wi != null && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)) {
    return false;
  }
  return false;
}
 

Example 16

From project madvertise-android-sdk, under directory /madvertiseSDK/src/de/madvertise/android/sdk/.

Source file: MadvertiseUtil.java

  22 
vote

public static String getHashedMacAddress(Context context,HashType hashType){
  String mac=null;
  if (MadvertiseUtil.checkPermissionGranted(android.Manifest.permission.ACCESS_WIFI_STATE,context)) {
    WifiManager wm=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    mac=wm.getConnectionInfo().getMacAddress();
  }
  if (mac == null) {
    mac="";
  }
 else {
    mac=MadvertiseUtil.getHash(mac,hashType);
  }
  return mac;
}
 

Example 17

From project milton, under directory /milton/apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.

Source file: CheckInternet.java

  22 
vote

/** 
 * Can we connect to the internet or not, checks if device has connection and if wifi is on if user has set that in the connection preference
 * @param context Application context
 * @param prefs User preferences
 * @return Can connect to internet or not
 */
@SuppressWarnings("static-access") public boolean canConnect(Context context,SharedPreferences prefs){
  WifiManager wifi=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  if (wifi.getWifiState() != wifi.WIFI_STATE_ENABLED && prefs.getString("connection","").equals(CON_WIFI)) {
    return false;
  }
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (manager.getActiveNetworkInfo() == null || !manager.getActiveNetworkInfo().isConnected()) {
    return false;
  }
  return true;
}
 

Example 18

From project milton2, under directory /apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.

Source file: CheckInternet.java

  22 
vote

/** 
 * Can we connect to the internet or not, checks if device has connection and if wifi is on if user has set that in the connection preference
 * @param context Application context
 * @param prefs User preferences
 * @return Can connect to internet or not
 */
@SuppressWarnings("static-access") public boolean canConnect(Context context,SharedPreferences prefs){
  WifiManager wifi=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  if (wifi.getWifiState() != wifi.WIFI_STATE_ENABLED && prefs.getString("connection","").equals(CON_WIFI)) {
    return false;
  }
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (manager.getActiveNetworkInfo() == null || !manager.getActiveNetworkInfo().isConnected()) {
    return false;
  }
  return true;
}
 

Example 19

From project Mobile-Tour-Guide, under directory /zxing-2.0/android/src/com/google/zxing/client/android/result/.

Source file: WifiResultHandler.java

  22 
vote

@Override public void handleButtonPress(int index){
  WifiParsedResult wifiResult=(WifiParsedResult)getResult();
  if (index == 0) {
    String ssid=wifiResult.getSsid();
    String password=wifiResult.getPassword();
    String networkType=wifiResult.getNetworkEncryption();
    WifiManager wifiManager=(WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
    Toast.makeText(getActivity(),R.string.wifi_changing_network,Toast.LENGTH_LONG).show();
    WifiConfigManager.configure(wifiManager,ssid,password,networkType);
    parent.restartPreviewAfterDelay(0L);
  }
}
 

Example 20

From project MobiPerf, under directory /android/src/com/mobiperf/util/.

Source file: PhoneUtils.java

  22 
vote

/** 
 * Returns current Wi-Fi SSID, or null if Wi-Fi is not connected. 
 */
private String getWifiCarrierName(){
  WifiManager wifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  if (wifiInfo != null) {
    return wifiInfo.getSSID();
  }
  return null;
}
 

Example 21

From project platform_packages_apps_settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  22 
vote

private void setWifiStatus(){
  WifiManager wifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  Preference wifiMacAddressPref=findPreference(KEY_WIFI_MAC_ADDRESS);
  String macAddress=wifiInfo == null ? null : wifiInfo.getMacAddress();
  wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : getString(R.string.status_unavailable));
}
 

Example 22

From project QuasselDroid, under directory /src/com/iskrembilen/quasseldroid/service/.

Source file: CoreConnService.java

  22 
vote

private void acquireWakeLockIfEnabled(){
  if (preferenceUseWakeLock) {
    PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
    wakeLock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"quasseldroid wakelock");
    wakeLock.acquire();
    Log.i(TAG,"WakeLock acquired");
    WifiManager wifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
    wifiLock=wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL,"quasseldroid wifilock");
    wifiLock.acquire();
    Log.i(TAG,"WifiLock acquired");
  }
}
 

Example 23

From project Sage-Mobile-Calc, under directory /src/org/connectbot/service/.

Source file: ConnectivityReceiver.java

  22 
vote

public ConnectivityReceiver(TerminalManager manager,boolean lockingWifi){
  mTerminalManager=manager;
  final ConnectivityManager cm=(ConnectivityManager)manager.getSystemService(Context.CONNECTIVITY_SERVICE);
  final WifiManager wm=(WifiManager)manager.getSystemService(Context.WIFI_SERVICE);
  mWifiLock=wm.createWifiLock(TAG);
  final NetworkInfo info=cm.getActiveNetworkInfo();
  if (info != null) {
    mIsConnected=(info.getState() == State.CONNECTED);
  }
  mLockingWifi=lockingWifi;
  final IntentFilter filter=new IntentFilter();
  filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
  manager.registerReceiver(this,filter);
}
 

Example 24

From project SimpleMoney-Android, under directory /Zxing/bin/src/com/google/zxing/client/android/result/.

Source file: WifiResultHandler.java

  22 
vote

@Override public void handleButtonPress(int index){
  WifiParsedResult wifiResult=(WifiParsedResult)getResult();
  if (index == 0) {
    String ssid=wifiResult.getSsid();
    String password=wifiResult.getPassword();
    String networkType=wifiResult.getNetworkEncryption();
    WifiManager wifiManager=(WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
    Toast.makeText(getActivity(),R.string.wifi_changing_network,Toast.LENGTH_LONG).show();
    WifiConfigManager.configure(wifiManager,ssid,password,networkType);
    parent.restartPreviewAfterDelay(0L);
  }
}
 

Example 25

From project SMSSync, under directory /smssync/src/org/addhen/smssync/services/.

Source file: SmsSyncServices.java

  22 
vote

synchronized private static WifiManager.WifiLock getPhoneWifiLock(Context context){
  if (wifilock == null) {
    WifiManager manager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    wifilock=manager.createWifiLock(WifiManager.WIFI_MODE_FULL,CLASS_TAG);
  }
  return wifilock;
}
 

Example 26

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/util/.

Source file: PhoneUtils.java

  22 
vote

/** 
 * Returns current Wi-Fi SSID, or null if Wi-Fi is not connected. 
 */
private String getWifiCarrierName(){
  WifiManager wifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  if (wifiInfo != null) {
    return wifiInfo.getSSID();
  }
  return null;
}
 

Example 27

From project Synodroid, under directory /src/com/bigpupdev/synodroid/ui/.

Source file: DownloadPreferenceActivity.java

  22 
vote

private void autoCreate(){
  WifiManager wifiMgr=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  boolean wifiOn=wifiMgr.isWifiEnabled();
  final WifiInfo currentWifi=wifiMgr.getConnectionInfo();
  boolean wifiConnected=(wifiOn && currentWifi.getNetworkId() != -1);
  if (wifiConnected) {
    ServerWizard wiz=new ServerWizard(DownloadPreferenceActivity.this,wifiMgr.getConnectionInfo().getSSID(),((Synodroid)getApplication()).DEBUG);
    wiz.start();
  }
 else {
    AddServerWizard wiz=new AddServerWizard(DownloadPreferenceActivity.this,((Synodroid)getApplication()).DEBUG);
    wiz.start();
  }
}
 

Example 28

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: NearbyActivity.java

  21 
vote

@Override protected void onPreExecute(){
  WifiManager wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  if (wifi == null) {
    Log.d(TAG,"No wifi available.");
    return;
  }
  mLock=wifi.createMulticastLock("msb-scanner");
  mLock.acquire();
  try {
    mSocket=new MulticastSocket(NEARBY_PORT);
  }
 catch (  IOException e) {
    Log.w(TAG,"error multicasting",e);
    mSocket=null;
  }
  mWifiBSSID=wifi.getConnectionInfo().getBSSID();
  mWifiSSID=wifi.getConnectionInfo().getSSID();
  mSeenUris.add(FriendRequest.getMusubiUri(NearbyActivity.this));
}
 

Example 29

From project groundy, under directory /src/main/java/com/codeslap/groundy/.

Source file: DeviceStatus.java

  21 
vote

/** 
 * Register a WiFi lock to WiFi management in the device
 * @param context Context to use
 * @param on      if true the device WiFi radio will keep awake untilfalse is called back. if true is passed several times only the first time after a false call will take effect, also if false is passed and previously the WiFi radio was not turned on (true call) does nothing.
 */
public static void keepWiFiOn(Context context,boolean on){
  if (wifiLock == null) {
    WifiManager wm=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    if (wm != null) {
      wifiLock=wm.createWifiLock(WifiManager.WIFI_MODE_FULL,TAG);
      wifiLock.setReferenceCounted(true);
    }
  }
  if (wifiLock != null) {
    if (on) {
      wifiLock.acquire();
      L.d(TAG,"Adquired WiFi lock");
    }
 else     if (wifiLock.isHeld()) {
      wifiLock.release();
      L.d(TAG,"Released WiFi lock");
    }
  }
}
 

Example 30

From project IOCipherServer, under directory /src/info/guardianproject/iocipher/server/.

Source file: IOCipherServerActivity.java

  21 
vote

private String getNetworkAddress(){
  ConnectivityManager connMgr=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
  final android.net.NetworkInfo wifi=connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  final android.net.NetworkInfo mobile=connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
  if (wifi.isAvailable()) {
    WifiManager myWifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
    WifiInfo myWifiInfo=myWifiManager.getConnectionInfo();
    int ip=myWifiInfo.getIpAddress();
    String ipString=android.text.format.Formatter.formatIpAddress(ip);
    Log.w(TAG,"Wifi address: " + ipString);
    return ipString;
  }
 else   if (mobile.isAvailable()) {
    Log.w(TAG,"No wifi available (mobile, yes)");
  }
 else {
    Log.w(TAG,"No network available");
  }
  return null;
}
 

Example 31

From project mp3tunes-android, under directory /src/com/mp3tunes/android/service/.

Source file: Mp3tunesService.java

  21 
vote

@Override public void onCreate(){
  super.onCreate();
  mNm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  mBufferPercent=0;
  setForeground(true);
  PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
  mWakeLock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MP3tunes Player");
  WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  mWifiLock=wm.createWifiLock("MP3tunes Player");
  mTelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  mTrackHistory=new Stack<Integer>();
  mLocker=(Locker)MP3tunesApplication.getInstance().map.get("mp3tunes_locker");
  try {
    mDb=new LockerDb(this,null);
  }
 catch (  Exception ex) {
    System.out.println(ex.getMessage());
    ex.printStackTrace();
    mServiceState=STATE.STOPPED;
    notifyChange(DATABASE_ERROR);
    mNm.cancel(NOTIFY_ID);
    if (mWakeLock.isHeld())     mWakeLock.release();
    if (mWifiLock.isHeld())     mWifiLock.release();
  }
}
 

Example 32

From project ohmagePhone, under directory /src/org/ohmage/triggers/types/location/.

Source file: LocTrigService.java

  21 
vote

@Override public void onCreate(){
  Analytics.service(this,Status.ON);
  setKeepAliveAlarm();
  mLocList=new LinkedList<LocListItem>();
  populateLocList();
  initState();
  PowerManager powerMan=(PowerManager)getSystemService(POWER_SERVICE);
  mWakeLock=powerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,WAKE_LOCK_TAG);
  if (LocTrigConfig.useNetworkLocation) {
    Log.i(TAG,"LocTrigService: Using network location");
    WifiManager wifiMan=(WifiManager)getSystemService(WIFI_SERVICE);
    mWifiLock=wifiMan.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY,TAG);
  }
  if (LocTrigConfig.useMotionDetection) {
    Log.i(TAG,"LocTrigService: Using motion detection");
  }
  mMotionDetectCB=new ILocationChangedCallback.Stub(){
    @Override public void locationChanged() throws RemoteException {
      if (LocTrigConfig.useMotionDetection) {
        mHandler.sendMessage(mHandler.obtainMessage());
      }
    }
  }
;
  mSamplingStarted=false;
  super.onCreate();
}
 

Example 33

From project Ohmage_Phone, under directory /src/org/ohmage/triggers/types/location/.

Source file: LocTrigService.java

  21 
vote

@Override public void onCreate(){
  Log.i(DEBUG_TAG,"LocTrigService: onCreate");
  setKeepAliveAlarm();
  mLocList=new LinkedList<LocListItem>();
  populateLocList();
  initState();
  PowerManager powerMan=(PowerManager)getSystemService(POWER_SERVICE);
  mWakeLock=powerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,WAKE_LOCK_TAG);
  if (LocTrigConfig.useNetworkLocation) {
    Log.i(DEBUG_TAG,"LocTrigService: Using network location");
    WifiManager wifiMan=(WifiManager)getSystemService(WIFI_SERVICE);
    mWifiLock=wifiMan.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY,DEBUG_TAG);
  }
  if (LocTrigConfig.useMotionDetection) {
    Log.i(DEBUG_TAG,"LocTrigService: Using motion detection");
  }
  mMotionDetectCB=new ILocationChangedCallback.Stub(){
    @Override public void locationChanged() throws RemoteException {
      if (LocTrigConfig.useMotionDetection) {
        mHandler.sendMessage(mHandler.obtainMessage());
      }
    }
  }
;
  mSamplingStarted=false;
  super.onCreate();
}
 

Example 34

From project OpenMEAP, under directory /clients/java/openmeap-slic-android/src/com/openmeap/android/.

Source file: MainActivity.java

  21 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  CredentialsProviderFactory.setDefaultCredentialsProviderFactory(new OmSlicCredentialsProvider.Factory(this));
  HttpRequestExecuterFactory.setDefaultType(HttpRequestExecuterImpl.class);
  DigestInputStreamFactory.setDigestInputStreamForName("md5",Md5DigestInputStream.class);
  DigestInputStreamFactory.setDigestInputStreamForName("sha1",Sha1DigestInputStream.class);
  Preferences prefs=new SharedPreferencesImpl(getSharedPreferences(SLICConfig.PREFERENCES_FILE,MODE_PRIVATE));
  try {
    Properties props=new Properties();
    props.load(getAssets().open(SLICConfig.PROPERTIES_FILE));
    config=new AndroidSLICConfig(this,prefs,props);
  }
 catch (  IOException ioe) {
    throw new RuntimeException("The primary configuration file (" + SLICConfig.PROPERTIES_FILE + ") could not be opened.");
  }
  Object o=getSystemService(Context.WIFI_SERVICE);
  if (o instanceof WifiManager) {
    WifiManager wifiManager=(WifiManager)o;
    WifiInfo wifiInfo=wifiManager.getConnectionInfo();
    if (wifiInfo != null && wifiInfo.getMacAddress() != null) {
      Runnable firstRunCheck=new FirstRunCheck(config,wifiInfo.getMacAddress(),HttpRequestExecuterFactory.newDefault());
      new Thread(firstRunCheck).start();
    }
  }
  if (config.isDevelopmentMode()) {
    System.setProperty(HttpRequestExecuter.SSL_PEER_NOVERIFY_PROPERTY,"true");
  }
 else {
    System.setProperty(HttpRequestExecuter.SSL_PEER_NOVERIFY_PROPERTY,"false");
  }
  storage=new LocalStorageImpl(this);
  updateHandler=new UpdateHandler(this,config,storage);
  setupWindowTitle();
}
 

Example 35

From project proxydroid, under directory /src/org/proxydroid/.

Source file: ConnectivityBroadcastReceiver.java

  21 
vote

public String onlineSSID(Context context,String ssid){
  String ssids[]=ListPreferenceMultiSelect.parseStoredValue(ssid);
  if (ssids == null)   return null;
  if (ssids.length < 1)   return null;
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null)   return null;
  if (networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
    for (    String item : ssids) {
      if (item.equals(Constraints.WIFI_AND_3G))       return item;
      if (item.equals(Constraints.ONLY_3G))       return item;
    }
    return null;
  }
  WifiManager wm=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wInfo=wm.getConnectionInfo();
  if (wInfo == null)   return null;
  String current=wInfo.getSSID();
  if (current == null || current.equals(""))   return null;
  for (  String item : ssids) {
    if (item.equals(Constraints.WIFI_AND_3G))     return item;
    if (item.equals(Constraints.ONLY_WIFI))     return item;
    if (item.equals(current))     return item;
  }
  return null;
}
 

Example 36

From project SamyGo-Android-Remote, under directory /src/de/quist/app/samyGoRemote/.

Source file: CSeriesKeyCodeSenderFactory.java

  21 
vote

@Override protected Sender create(Context ctx,SharedPreferences prefs,ExceptionReporter reporter){
  String host=prefs.getString(Remote.PREFS_SERVER_HOST_KEY,"");
  Log.v(TAG,"Factoring C-Series sender for host " + host);
  WifiManager wifiManager=(WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo=wifiManager.getConnectionInfo();
  String mac=wifiInfo.getMacAddress();
  int i=0;
  while (mac == null && i < MAC_ADDRESS_FILES.length) {
    mac=getNetworkAddress(MAC_ADDRESS_FILES[i]);
    i++;
  }
  if (mac == null) {
    mac="00:50:C2:00:11:22";
    Log.v(TAG,"No wifi-interface. Set mac address to a virtual address " + mac);
  }
  Log.v(TAG,"Obtained MAC address " + mac);
  return new CSeriesSender(host,mac,reporter);
}
 

Example 37

From project sms-backup-plus, under directory /src/com/zegoggles/smssync/.

Source file: ServiceBase.java

  21 
vote

/** 
 * Acquire locks
 * @param background if service is running in background (no UI)
 * @throws com.zegoggles.smssync.ServiceBase.ConnectivityErrorException when unable to connect
 */
protected void acquireLocks(boolean background) throws ConnectivityErrorException {
  if (sWakeLock == null) {
    PowerManager pMgr=(PowerManager)getSystemService(POWER_SERVICE);
    sWakeLock=pMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
  }
  sWakeLock.acquire();
  WifiManager wMgr=(WifiManager)getSystemService(WIFI_SERVICE);
  if (wMgr.isWifiEnabled() && getConnectivityManager().getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && getConnectivityManager().getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
    if (sWifiLock == null) {
      sWifiLock=wMgr.createWifiLock(TAG);
    }
    sWifiLock.acquire();
  }
 else   if (background && PrefStore.isWifiOnly(this)) {
    throw new ConnectivityErrorException(getString(R.string.error_wifi_only_no_connection));
  }
  NetworkInfo active=getConnectivityManager().getActiveNetworkInfo();
  if (active == null || !active.isConnectedOrConnecting()) {
    throw new ConnectivityErrorException(getString(R.string.error_no_connection));
  }
}
 

Example 38

From project alljoyn_java, under directory /ice/org/alljoyn/bus/alljoyn/.

Source file: DaemonInit.java

  19 
vote

/** 
 * Initialize daemon service if needed. First it checks whether any daemon is running; if no daemon is running, then it starts the APK daemon if it is installed; If no APK daemon is installed, then starts the bundled daemon. This is a blocking call; it blocks until the daemon is ready or no daemon is found. Thus only non-UI thread is allowed to call PrepareDaemon().
 * @param context The application context
 * @return true  if the daemon is ready for connectionfalse if no daemon is available
 */
public static boolean PrepareDaemon(Context context){
  sContext=context.getApplicationContext();
  Log.v(TAG,"Saved Application Context");
  alljoynAndroidExt=new AllJoynAndroidExt(sContext);
  if (receiver == null) {
    receiver=new ScanResultsReceiver(alljoynAndroidExt);
    sContext.registerReceiver(receiver,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
  }
  return true;
}
 

Example 39

From project Android-File-Manager, under directory /src/com/nexes/manager/.

Source file: WirelessManager.java

  19 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.info_layout);
  wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  TextView[] titles=new TextView[6];
  data_labels=new TextView[6];
  int[] left_views={R.id.first_title,R.id.second_title,R.id.third_title,R.id.fourth_title,R.id.fifth_title};
  int[] right_views={R.id.dirs_label,R.id.files_label,R.id.time_stamp,R.id.total_size,R.id.free_space};
  String[] labels={"Signal strength","WIFI State","ip address","mac address","SSID","link speed"};
  for (int i=0; i < 5; i++) {
    titles[i]=(TextView)findViewById(left_views[i]);
    titles[i].setText(labels[i]);
    data_labels[i]=(TextView)findViewById(right_views[i]);
    data_labels[i].setText("N/A");
  }
  name_label=(TextView)findViewById(R.id.name_label);
  enable_label=(TextView)findViewById(R.id.path_label);
  state_button=(Button)findViewById(R.id.back_button);
  back_button=(Button)findViewById(R.id.zip_button);
  back_button.setText(" Back ");
  state_button.setOnClickListener(new ButtonHandler());
  back_button.setOnClickListener(new ButtonHandler());
  ImageView icon=(ImageView)findViewById(R.id.info_icon);
  icon.setImageResource(R.drawable.wireless);
  get_wifi();
}
 

Example 40

From project android-tether, under directory /src/og/android/tether/.

Source file: TetherService.java

  19 
vote

@Override public void onCreate(){
  Log.d(MSG_TAG,"onCreate()");
  super.onCreate();
  TetherService.singleton=this;
  this.application=(TetherApplication)getApplication();
  this.configAdv=this.application.isConfigurationAdv();
  this.wifiManager=(WifiManager)this.getSystemService(Context.WIFI_SERVICE);
  this.bluetoothService=BluetoothService.getInstance();
  this.bluetoothService.setApplication(this.application);
  try {
    startForeground=getClass().getMethod("startForeground",startForegroundSignature);
    stopForeground=getClass().getMethod("stopForeground",stopForegroundSignature);
  }
 catch (  NoSuchMethodException e) {
    startForeground=stopForeground=null;
    Log.d(MSG_TAG,"No startForeground method.");
  }
  if (this.application.coretask.getProp("tether.status").equals("running")) {
    Log.d(MSG_TAG,"tether.status already running!");
    this.serviceState=STATE_RUNNING;
  }
  sendBroadcastManage(MANAGE_STARTED);
}
 

Example 41

From project android-xbmcremote, under directory /src/org/xbmc/android/util/.

Source file: WifiHelper.java

  19 
vote

public void aquireWifiLock(){
  if (mWifiLock == null) {
    Log.d(TAG,"creating new WifiLock");
    mWifiLock=mManager.createWifiLock(WifiManager.WIFI_MODE_FULL,WIFI_LOCK_TAG);
  }
  if (!mWifiLock.isHeld()) {
    Log.d(TAG,"aquiring WifiLock");
    mWifiLock.acquire();
  }
}
 

Example 42

From project AndroidCommon, under directory /src/com/asksven/android/common/wifi/.

Source file: WifiManagerProxy.java

  19 
vote

/** 
 * returns the number of help WifiLocks
 * @return
 */
public static int getWifiLocks(Context ctx){
  init(ctx);
  int ret=0;
  try {
    Field privateStringField=WifiManager.class.getDeclaredField("mActiveLockCount");
    privateStringField.setAccessible(true);
    Integer fieldValue=(Integer)privateStringField.get(m_manager);
    Log.d(TAG,"mActiveLockCount is " + fieldValue);
    ret=fieldValue;
  }
 catch (  Exception e) {
    Log.e(TAG,"An exception occured in getWifiLocks(): " + e.getMessage());
    ret=-1;
  }
  Log.d(TAG,ret + " Wifilocks detected");
  return ret;
}
 

Example 43

From project cw-advandroid, under directory /SystemEvents/OnWiFiChange/src/com/commonsware/android/sysevents/wifi/.

Source file: OnWiFiChangeReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  int state=intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,-1);
  String msg=null;
switch (state) {
case WifiManager.WIFI_STATE_DISABLED:
    msg="is disabled";
  break;
case WifiManager.WIFI_STATE_DISABLING:
msg="is disabling";
break;
case WifiManager.WIFI_STATE_ENABLED:
msg="is enabled";
break;
case WifiManager.WIFI_STATE_ENABLING:
msg="is enabling";
break;
case WifiManager.WIFI_STATE_UNKNOWN:
msg="has an error";
break;
default :
msg="is acting strangely";
break;
}
if (msg != null) {
Log.d("OnWiFiChanged","WiFi " + msg);
}
}
 

Example 44

From project cw-omnibus, under directory /SystemEvents/OnWiFiChange/src/com/commonsware/android/sysevents/wifi/.

Source file: OnWiFiChangeReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  int state=intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,-1);
  String msg=null;
switch (state) {
case WifiManager.WIFI_STATE_DISABLED:
    msg="is disabled";
  break;
case WifiManager.WIFI_STATE_DISABLING:
msg="is disabling";
break;
case WifiManager.WIFI_STATE_ENABLED:
msg="is enabled";
break;
case WifiManager.WIFI_STATE_ENABLING:
msg="is enabling";
break;
case WifiManager.WIFI_STATE_UNKNOWN:
msg="has an error";
break;
default :
msg="is acting strangely";
break;
}
if (msg != null) {
Log.d("OnWiFiChanged","WiFi " + msg);
}
}
 

Example 45

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
    handleChange((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR));
  }
 else   if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
    handleNetworkStateChanged((NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
  }
 else   if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    ConnectivityManager con=(ConnectivityManager)parent.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] s=con.getAllNetworkInfo();
    for (    NetworkInfo i : s) {
      if (i.getTypeName().contentEquals("WIFI")) {
        NetworkInfo.State state=i.getState();
        String ssid=mWifiManager.getConnectionInfo().getSSID();
        if (state == NetworkInfo.State.CONNECTED && ssid != null) {
          mWifiManager.saveConfiguration();
          String label=parent.getString(R.string.wifi_connected);
          statusView.setText(label + '\n' + ssid);
          Runnable delayKill=new Killer(parent);
          delayKill.run();
        }
        if (state == NetworkInfo.State.DISCONNECTED) {
          Log.d(TAG,"Got state: " + state + " for ssid: "+ ssid);
          parent.gotError();
        }
      }
    }
  }
}
 

Example 46

From project jamendo-android, under directory /src/com/teleca/jamendo/service/.

Source file: PlayerService.java

  19 
vote

@Override public void onCreate(){
  Log.i(JamendoApplication.TAG,"Player Service onCreate");
  mPlayerEngine=new PlayerEngineImpl();
  mPlayerEngine.setListener(mLocalEngineListener);
  mTelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  mPhoneStateListener=new PhoneStateListener(){
    @Override public void onCallStateChanged(    int state,    String incomingNumber){
      Log.e(JamendoApplication.TAG,"onCallStateChanged");
      if (state == TelephonyManager.CALL_STATE_IDLE) {
      }
 else {
        if (mPlayerEngine != null) {
          mPlayerEngine.pause();
        }
      }
    }
  }
;
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  mWifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  mWifiLock=mWifiManager.createWifiLock(JamendoApplication.TAG);
  mWifiLock.setReferenceCounted(false);
  JamendoApplication.getInstance().setConcretePlayerEngine(mPlayerEngine);
  mRemoteEngineListener=JamendoApplication.getInstance().fetchPlayerEngineListener();
}
 

Example 47

From project OpenAndroidWeather, under directory /OpenAndroidWeather/src/no/firestorm/weathernotificatonservice/.

Source file: InternetEnabledIntentReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  final String action=intent.getAction();
  if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    final NetworkInfo info=(NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
      final Intent serviceIntent=new Intent(context,WeatherNotificationService.class);
      intent.putExtra(WeatherNotificationService.INTENT_EXTRA_ACTION,WeatherNotificationService.INTENT_EXTRA_ACTION_GET_TEMP);
      context.startService(serviceIntent);
      setEnableReciver(context,false);
    }
  }
}
 

Example 48

From project PartyWare, under directory /android/src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
    handleChange((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR));
  }
 else   if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
    handleNetworkStateChanged((NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
  }
 else   if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    ConnectivityManager con=(ConnectivityManager)parent.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] s=con.getAllNetworkInfo();
    for (    NetworkInfo i : s) {
      if (i.getTypeName().contentEquals("WIFI")) {
        NetworkInfo.State state=i.getState();
        String ssid=mWifiManager.getConnectionInfo().getSSID();
        if (state == NetworkInfo.State.CONNECTED && ssid != null) {
          mWifiManager.saveConfiguration();
          String label=parent.getString(R.string.wifi_connected);
          statusView.setText(label + '\n' + ssid);
          Runnable delayKill=new Killer(parent);
          delayKill.run();
        }
        if (state == NetworkInfo.State.DISCONNECTED) {
          Log.d(TAG,"Got state: " + state + " for ssid: "+ ssid);
          ((WifiActivity)parent).gotError();
        }
      }
    }
  }
}
 

Example 49

From project Playlist, under directory /src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
    handleChange((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR));
  }
 else   if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
    handleNetworkStateChanged((NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
  }
 else   if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    ConnectivityManager con=(ConnectivityManager)parent.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] s=con.getAllNetworkInfo();
    for (    NetworkInfo i : s) {
      if (i.getTypeName().contentEquals("WIFI")) {
        NetworkInfo.State state=i.getState();
        String ssid=mWifiManager.getConnectionInfo().getSSID();
        if (state == NetworkInfo.State.CONNECTED && ssid != null) {
          mWifiManager.saveConfiguration();
          String label=parent.getString(R.string.wifi_connected);
          statusView.setText(label + '\n' + ssid);
          Runnable delayKill=new Killer(parent);
          delayKill.run();
        }
        if (state == NetworkInfo.State.DISCONNECTED) {
          Log.d(TAG,"Got state: " + state + " for ssid: "+ ssid);
          ((WifiActivity)parent).gotError();
        }
      }
    }
  }
}
 

Example 50

From project PowerTutor, under directory /src/edu/umich/PowerTutor/components/.

Source file: Wifi.java

  19 
vote

public Wifi(Context context,PhoneConstants phoneConstants){
  this.phoneConstants=phoneConstants;
  wifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  sysInfo=SystemInfo.getInstance();
  String interfaceName=SystemInfo.getInstance().getProperty("wifi.interface");
  if (interfaceName == null)   interfaceName="eth0";
  lastLinkSpeed=-1;
  wifiState=new WifiStateKeeper(phoneConstants.wifiHighLowTransition(),phoneConstants.wifiLowHighTransition());
  uidStates=new SparseArray<WifiStateKeeper>();
  transPacketsFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/tx_packets";
  readPacketsFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/rx_packets";
  transBytesFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/tx_bytes";
  readBytesFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/rx_bytes";
  uidStatsFolder=new File("/proc/uid_stat");
}
 

Example 51

From project pulWifi, under directory /src/es/pulimento/wifi/ui/dialogs/.

Source file: EnableWifiDialog.java

  19 
vote

public EnableWifiDialog(Context context,WeakReference<Activity> activity){
  super(context);
  mContext=context;
  mActivity=activity;
  mWifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  this.setCancelable(false);
  this.setTitle(R.string.mainactivity_ask_dialog_title);
  this.setMessage(context.getText(R.string.mainactivity_ask_dialog_msg));
  this.setButton(BUTTON_POSITIVE,context.getText(R.string.mainactivity_ask_dialog_yes_button),this);
  this.setButton(BUTTON_NEGATIVE,context.getText(R.string.mainactivity_ask_dialog_no_button),this);
}
 

Example 52

From project roboguice, under directory /roboguice/src/main/java/roboguice/config/.

Source file: RoboModule.java

  19 
vote

/** 
 * Configure this module to define Android related bindings.<br /> <br /> If you want to provide your own bindings, you should <strong>NOT</strong> override this method, but rather create a  {@link Module} implementationand add it to the configuring modules by overriding {@link roboguice.application.RoboApplication#addApplicationModules(List)}.<br />
 */
@SuppressWarnings("unchecked") @Override protected void configure(){
  bindScope(ContextScoped.class,contextScope);
  bind(ContextScope.class).toInstance(contextScope);
  bind(Context.class).toProvider(throwingContextProvider).in(ContextScoped.class);
  bind(Activity.class).toProvider(ActivityProvider.class);
  bind(AssetManager.class).toProvider(AssetManagerProvider.class);
  bind(SharedPreferences.class).toProvider(SharedPreferencesProvider.class);
  bind(Resources.class).toProvider(ResourcesProvider.class);
  bind(ContentResolver.class).toProvider(ContentResolverProvider.class);
  bind(EventManager.class).toInstance(eventManager);
  for (Class<?> c=application.getClass(); c != null && Application.class.isAssignableFrom(c); c=c.getSuperclass())   bind((Class<Object>)c).toInstance(application);
  bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
  bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
  bind(LayoutInflater.class).toProvider(new SystemServiceProvider<LayoutInflater>(Context.LAYOUT_INFLATER_SERVICE));
  bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
  bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
  bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
  bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
  bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
  bind(SearchManager.class).toProvider(new SystemServiceProvider<SearchManager>(Context.SEARCH_SERVICE));
  bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
  bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
  bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
  bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
  bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
  bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
  bindListener(Matchers.any(),resourceListener);
  bindListener(Matchers.any(),extrasListener);
  bindListener(Matchers.any(),viewListener);
  if (preferenceListener != null)   bindListener(Matchers.any(),preferenceListener);
  if (eventManager.isEnabled())   bindListener(Matchers.any(),new ObservesTypeListener(contextProvider,eventManager));
  requestInjection(eventManager);
  requestStaticInjection(Ln.class);
  requestStaticInjection(RoboThread.class);
  requestStaticInjection(RoboAsyncTask.class);
}
 

Example 53

From project SOCIETIES-SCE-Services, under directory /3rdPartyServices/StudentServices/NearMe/Android/src/com/asocom/model/.

Source file: Manager.java

  19 
vote

public static String getSSID(){
  if (getCurrentActivity() == null)   return "dame";
  String res=((WifiManager)getCurrentActivity().getSystemService(Activity.WIFI_SERVICE)).getConnectionInfo().getBSSID();
  if (res == null)   res="Online Social Network";
  return res;
}
 

Example 54

From project SqueezeControl, under directory /src/com/squeezecontrol/.

Source file: ServiceUtils.java

  19 
vote

/** 
 * If we're not connected to a valid network, complain and allow the user to turn on WiFi. FIXME This should really allow the user to connect ethernet as well...
 */
public static void requireValidNetworkOrFinish(final Activity context){
  if (!validNetworkAvailable(context)) {
    AlertDialog.Builder dialog=new AlertDialog.Builder(context);
    dialog.setMessage(R.string.wlan_required);
    dialog.setTitle("WLAN required");
    dialog.setPositiveButton("Yes",new OnClickListener(){
      @Override public void onClick(      DialogInterface dialog,      int which){
        ((WifiManager)context.getSystemService(Context.WIFI_SERVICE)).setWifiEnabled(true);
      }
    }
);
    dialog.setNegativeButton("No",new OnClickListener(){
      @Override public void onClick(      DialogInterface dialog,      int which){
        context.finish();
      }
    }
);
    dialog.create().show();
  }
}
 

Example 55

From project SWE12-Drone, under directory /catroid/src/at/tugraz/ist/catroid/plugin/Drone/other/.

Source file: DroneWifiConnectionActivity.java

  19 
vote

@Override public synchronized void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
    if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,10) == WifiManager.WIFI_STATE_ENABLED) {
      Log.d(DroneConsts.DroneLogTag,"WIFI_STATE_CHANGED_ACTION -> WIFI_STATE_ENABLED");
      unregisterReceiver(wifiStateChangedReceiver);
      IntentFilter intentFilter=new IntentFilter();
      intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
      registerReceiver(wifiStateChangedReceiver,intentFilter);
      changeStatus(DroneConsts.SCANNING);
    }
  }
  if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) && wifiManager.isWifiEnabled()) {
    Log.d(DroneConsts.DroneLogTag,"SCAN_RESULTS_AVAILABLE_ACTION");
    scanned=true;
    unregisterReceiver(wifiStateChangedReceiver);
    IntentFilter intentFilter=new IntentFilter();
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    registerReceiver(wifiStateChangedReceiver,intentFilter);
    if (foundDrone()) {
      changeStatus(DroneConsts.CONNECTING_TO_DRONE_WIFI);
    }
 else {
      changeStatus(DroneConsts.ERROR_FINDING_DRONE);
      return;
    }
  }
  if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) && wifiManager.isWifiEnabled()) {
    NetworkInfo info=intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    Log.d(DroneConsts.DroneLogTag,"SUPPLICANT_CONNECTION_CHANGE_ACTION " + info.isConnected() + " "+ wifiManager.getConnectionInfo().getSSID());
    if (info.isConnected()) {
      if (checkConnectionToDrone()) {
        changeStatus(DroneConsts.CHECKING_FIRMWARE);
      }
 else       if (errorCount++ > 3) {
        changeStatus(DroneConsts.ERROR_CONNECTING_DRONE);
        return;
      }
    }
  }
}