List of usage examples for android.content Context WIFI_SERVICE
String WIFI_SERVICE
To view the source code for android.content Context WIFI_SERVICE.
Click Source Link
From source file:com.heneryh.aquanotes.io.ApexExecutor.java
/** * Execute a {@link HttpGet} request, passing a valid response through * to the specified XML parser. This common method can then be used to parse * various kinds of XML feeds.//ww w. ja v a 2s . c o m */ public void executeGet(Uri ctrlUri, DefaultHandler xmlParser) throws HandlerException { controllerUri = ctrlUri; Cursor cursor = null; String username = null; String password = null; String apexBaseURL = null; String apexWANURL = null; String apexWiFiURL = null; String apexWiFiSID = null; String controllerType = null; /** * Poll the database for facts about this controller */ try { cursor = mDbResolver.query(controllerUri, ControllersQuery.PROJECTION, null, null, null); if (cursor != null && cursor.moveToFirst()) { username = cursor.getString(ControllersQuery.USER); password = cursor.getString(ControllersQuery.PW); apexWANURL = cursor.getString(ControllersQuery.WAN_URL); apexWiFiURL = cursor.getString(ControllersQuery.LAN_URL); apexWiFiSID = cursor.getString(ControllersQuery.WIFI_SSID); controllerType = cursor.getString(ControllersQuery.MODEL); } } catch (SQLException e) { throw new HandlerException("Database error getting controller data."); } finally { if (cursor != null) { cursor.close(); } } /** * Depending on whether or not we are on the 'Home' wifi network we want to use either the * WAN or LAN URL. * * Uhg, WifiManager stuff below crashes if wifi not enabled so first we have to check if * on wifi. */ ConnectivityManager cm = (ConnectivityManager) mActContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { /** * Get the currently connected SSID, if it matches the 'Home' one then use the local WiFi URL rather than the public one */ WifiManager wm = (WifiManager) mActContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wm.getConnectionInfo(); // somewhere read this was a quoted string but appears not to be if (wInfo.getSSID().equalsIgnoreCase(apexWiFiSID)) { apexBaseURL = apexWiFiURL; } else { apexBaseURL = apexWANURL; } } else { apexBaseURL = apexWANURL; } /** * for this function we need to append to the URL. To be safe we try to catch various * forms of URL that might be entered by the user: * * check if the "/" was put on the end */ if (!apexBaseURL.endsWith("/")) { String tmp = apexBaseURL + "/"; apexBaseURL = tmp; } /** * check if it starts with an "http://" */ if (!apexBaseURL.toLowerCase().startsWith("http://")) { String tmp = "http://" + apexBaseURL; apexBaseURL = tmp; } // oh, we should also check if it ends with an "status.sht" on the end and remove it. /** * When all cleaned up, add the xml portion of the url to grab the status. * * TODO: we tried to make this call handle various xml feeds but this call is hardcoded * for the status feed. */ String apexURL = apexBaseURL + "cgi-bin/status.xml"; final HttpUriRequest request = new HttpGet(apexURL); executeWhySeparate(request, xmlParser, username, password); }
From source file:com.tml.sharethem.receiver.ReceiverActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_receiver); if (Utils.isShareServiceRunning(getApplication())) { Toast.makeText(this, "Share mode is active, stop Share service to proceed with Receiving files", Toast.LENGTH_SHORT).show(); return;//from ww w.j av a 2 s . c o m } m_p2p_connection_status = (TextView) findViewById(R.id.p2p_receiver_wifi_info); m_goto_wifi_settings = (TextView) findViewById(R.id.p2p_receiver_wifi_switch); m_sender_files_header = (TextView) findViewById(R.id.p2p_sender_files_header); m_receiver_control = (SwitchCompat) findViewById(R.id.p2p_receiver_ap_switch); m_goto_wifi_settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { gotoWifiSettings(); } }); m_toolbar = (Toolbar) findViewById(R.id.toolbar); m_toolbar.setTitle(getString(R.string.send_title)); setSupportActionBar(m_toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); m_wifiScanHandler = new WifiTasksHandler(this); m_receiver_control_switch_listener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (!startSenderScan()) changeReceiverControlCheckedStatus(false); } else { changeReceiverControlCheckedStatus(true); showOptionsDialogWithListners(getString(R.string.p2p_receiver_close_warning), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { changeReceiverControlCheckedStatus(false); disableReceiverMode(); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }, getString(R.string.Action_Ok), getString(R.string.Action_cancel)); } } }; m_receiver_control.setOnCheckedChangeListener(m_receiver_control_switch_listener); if (!wifiManager.isWifiEnabled()) wifiManager.setWifiEnabled(true); //start search by default m_receiver_control.setChecked(true); }
From source file:com.example.dds_subscriber.DDS_Subscriber.java
@Override public void onCreate(Bundle savedInstanceState) { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); mcastLock = wifi.createMulticastLock("Tablet"); mcastLock.acquire();// w w w.j a v a2 s.c o m // open CoreDX DDS license file: BufferedReader br = null; String license = new String("<"); try { Log.i("Debug", "...Opening License"); br = new BufferedReader(new InputStreamReader(this.getAssets().open("coredx_dds.lic"))); } catch (IOException e) { Log.i("Debug", "...License did not open"); Log.e("Tablet", e.getMessage()); } if (br != null) { String ln; try { while ((ln = br.readLine()) != null) { license = new String(license + ln + "\n"); } } catch (IOException e) { Log.e("Tablet", e.getMessage()); } } license = new String(license + ">"); Log.i("Tablet", "...License seems to be good"); Log.i("Tablet", "Creating Subscriber"); class TestDataReaderListener implements DataReaderListener { @Override public long get_nil_mask() { return 0; } @Override public void on_requested_deadline_missed(DataReader dr, RequestedDeadlineMissedStatus status) { System.out.println(" @@@@@@@@@@@ REQUESTED DEADLINE MISSED @@@@@"); System.out.println(" @@@@@@@@@@@ @@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; @Override public void on_requested_incompatible_qos(DataReader dr, RequestedIncompatibleQosStatus status) { System.out.println(" @@@@@@@@@@@ REQUESTED INCOMPAT QOS @@@@@@@@"); System.out.println(" @@@@@@@@@@@ dr = " + dr); System.out.println(" @@@@@@@@@@@ @@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; @Override public void on_sample_rejected(DataReader dr, SampleRejectedStatus status) { }; @Override public void on_liveliness_changed(DataReader dr, LivelinessChangedStatus status) { TopicDescription td = dr.get_topicdescription(); System.out.println(" @@@@@@@@@@@ LIVELINESS CHANGED @@@@@@@@@@"); } @Override public void on_subscription_matched(DataReader dr, SubscriptionMatchedStatus status) { TopicDescription td = dr.get_topicdescription(); System.out.println(" @@@@@@@@@@@ SUBSCRIPTION MATCHED @@@@@@@@@@"); System.out.println( " @@@@@@@@@@@ topic = " + td.get_name() + " (type: " + td.get_type_name() + ")"); System.out.println(" @@@@@@@@@@@ current = " + status.get_current_count()); System.out.println(" @@@@@@@@@@@ @@@@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); } @Override public void on_sample_lost(DataReader dr, SampleLostStatus status) { System.out.println(" @@@@@@@@@@@ SAMPLE LOST @@@@@@@@@@"); }; @Override public void on_data_available(DataReader dr) { TopicDescription td = dr.get_topicdescription(); dataDDSDataReader data_message = (dataDDSDataReader) dr; System.out.println(" @@@@@@@@@@@ DATA AVAILABLE @@@@@@@@@@"); System.out.println( " @@@@@@@@@@@ topic = " + td.get_name() + " (type: " + td.get_type_name() + ")"); samples = new dataDDSSeq(); SampleInfoSeq si = new SampleInfoSeq(); ReturnCode_t retval = data_message.take(samples, si, 100, coredx.DDS_ANY_SAMPLE_STATE, coredx.DDS_ANY_VIEW_STATE, coredx.DDS_ANY_INSTANCE_STATE); System.out.println(" @@@@@@@@@@@ DR.read() ===> " + retval); if (retval == ReturnCode_t.RETCODE_OK) { if (samples.value == null) System.out.println(" @@@@@@@@@@@ samples.value = null"); else { System.out.println(" @@@@@@@@@@@ samples.value.length= " + samples.value.length); for (int i = 0; i < samples.value.length; i++) { System.out.println(" State : " + (si.value[i].instance_state == coredx.DDS_ALIVE_INSTANCE_STATE ? "ALIVE" : "NOT ALIVE")); System.out.println(" TimeStamp : " + si.value[i].source_timestamp.sec + "." + si.value[i].source_timestamp.nanosec); System.out.println(" Handle : " + si.value[i].instance_handle.value); System.out.println(" WriterHandle: " + si.value[i].publication_handle.value); System.out.println(" SampleRank : " + si.value[i].sample_rank); if (si.value[i].valid_data) System.out.println(" XVel: " + samples.value[i].XVel_DDS); System.out.println(" YVel: " + samples.value[i].YVel_DDS); System.out.println(" CompassDir: " + samples.value[i].CompassDir_DDS); System.out.println(" GPS_LT: " + samples.value[i].GPS_LT_DDS); System.out.println(" GPS_LN: " + samples.value[i].GPS_LN_DDS); } } data_message.return_loan(samples, si); } else { } System.out.println(" @@@@@@@@@@@ @@@@@@@@@@"); System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); }; } ; System.out.println("STARTING -------------------------"); DomainParticipantFactory dpf = DomainParticipantFactory.get_instance(); // dpf.set_license(license); dpf.get_default_participant_qos(dp_qos_tablet); DomainParticipant dp = null; System.out.println("CREATE PARTICIPANT ---------------"); dp = dpf.create_participant(0, /* domain Id */ dp_qos_tablet, //null, /* default qos */ null, /* no listener */ 0); if (dp == null) { //failed to create DomainParticipant -- bad license android.util.Log.e("CoreDX DDS", "Unable to create Tablet DomainParticipant."); // new AlertDialog.Builder(this) // .setTitle("CoreDX DDS Shapes Error") // .setMessage("Unable to create Tablet DomainParticipant.\n(Bad License?)") // .setNeutralButton("Close", new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dlg, int s) { /* do nothing */ } }) // .show(); } SubscriberQos sub_qos_tablet = new SubscriberQos(); Log.i("Tablet", "creating publisher/subscriber"); sub_tablet = dp.create_subscriber(sub_qos_tablet, null, 0); System.out.println("REGISTERING TYPE -----------------"); dataDDSTypeSupport ts = new dataDDSTypeSupport(); ReturnCode_t returnValue = ts.register_type(dp, null); if (returnValue != ReturnCode_t.RETCODE_OK) { System.out.println("ERROR registering type\n"); return; } System.out.println("CREATE TOPIC ---------------------"); /* create a DDS Topic with the FilterMsg data type. */ Topic topics = dp.create_topic("dataDDS", ts.get_type_name(), DDS.TOPIC_QOS_DEFAULT, null, 0); if (topics == null) { System.out.println("Error creating topic"); return; } System.out.println("CREATE SUBSCRIBER ----------------"); SubscriberQos sub_qos = null; SubscriberListener sub_listener = null; Subscriber sub = dp.create_subscriber(sub_qos, sub_listener, 0); System.out.println("READER VARIABLES ----------------"); DataReaderQos dr_qos = new DataReaderQos(); sub.get_default_datareader_qos(dr_qos); dr_qos.entity_name.value = "JAVA_DR"; dr_qos.history.depth = 10; DataReaderListener dr_listener = new TestDataReaderListener(); System.out.println("CREATE DATAREADER ----------------"); //Create DDS Data reader dataDDSDataReader dr = (dataDDSDataReader) sub.create_datareader(topics, DDS.DATAREADER_QOS_DEFAULT, dr_listener, DDS.DATA_AVAILABLE_STATUS); System.out.println("DATAREADER CREATED ----------------"); //Cheack to see if DDS Data Reader worked if (dr == null) { System.out.println("ERROR creating data reader\n"); //return; } while (true) { try { Thread.currentThread().sleep(1000); // 5 second sleep } catch (Exception e) { e.printStackTrace(); } // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_dds__subscriber); // } // } // @Override // public boolean onCreateOptionsMenu(Menu menu) { // getMenuInflater().inflate(R.menu.activity_dds__subscriber, menu); // return true; // } } }
From source file:com.scooter1556.sms.android.activity.VideoPlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_player); restService = RESTService.getInstance(); player = new SMSVideoPlayer(); surface = (SurfaceView) findViewById(R.id.video_surface); surface.setOnSystemUiVisibilityChangeListener(onSystemUiVisibilityChanged); surface.setOnTouchListener(new View.OnTouchListener() { @Override//from w w w .j ava2 s . c om public boolean onTouch(View view, MotionEvent motionEvent) { togglePlayback(); return false; } }); holder = surface.getHolder(); holder.addCallback(this); videoOverlay = (ImageView) findViewById(R.id.video_overlay); videoOverlay.setImageResource(R.drawable.play_overlay); timeline = (SeekBar) findViewById(R.id.video_controller_timeline); timeline.setOnSeekBarChangeListener(onSeek); formatBuilder = new StringBuilder(); formatter = new Formatter(formatBuilder, Locale.getDefault()); duration = (TextView) findViewById(R.id.video_controller_duration); duration.setText(stringForTime(0)); currentTime = (TextView) findViewById(R.id.video_controller_current_time); currentTime.setText(stringForTime(0)); playButton = (ImageButton) findViewById(R.id.video_controller_play); playButton.setImageResource(R.drawable.ic_play_light); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { togglePlayback(); } }); wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "sms"); controller = findViewById(R.id.video_controller); }
From source file:git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
public WifiManager getWifiManager() { return (WifiManager) this.getActivity().getSystemService(Context.WIFI_SERVICE); }
From source file:com.example.qrpoll.MainActivity.java
/** * sprawdzenie stanu wifi//from w ww. j a va 2 s . c om * @return */ public boolean checkWifi() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); return wifi.isWifiEnabled(); }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
@Override public void onCreate() { // Create the service super.onCreate(); restService = RESTService.getInstance(); currentListPosition = 0;//from w ww. jav a 2s . c o m mediaElementList = new ArrayList<>(); // Setup media session mediaSessionCallback = new MediaSessionCallback(); mediaSession = new MediaSessionCompat(this, "SMSPlayer"); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mediaSessionCallback); mediaState = PlaybackStateCompat.STATE_NONE; updatePlaybackState(); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sms"); wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "sms"); }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
@Override public void onStart(Intent intent, int startId) { Log.i(LOG_TAG, "onStart"); setForeground(true);//from w ww.java 2s . c o m super.onStart(intent, startId); pid = intent.getExtras().getInt("pid"); uid = intent.getExtras().getInt("uid"); processName = intent.getExtras().getString("processName"); packageName = intent.getExtras().getString("packageName"); settingTempFile = intent.getExtras().getString("settingTempFile"); cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid)); readSettingInfo(intent); delaytime = Integer.parseInt(time) * 1000; if (isFloating) { viFloatingWindow = LayoutInflater.from(this).inflate(R.layout.emmagee_floating, null); txtUnusedMem = (TextView) viFloatingWindow.findViewById(R.id.memunused); txtTotalMem = (TextView) viFloatingWindow.findViewById(R.id.memtotal); txtTraffic = (TextView) viFloatingWindow.findViewById(R.id.traffic); btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { btnWifi.setText(R.string.closewifi); } else { btnWifi.setText(R.string.openwifi); } txtUnusedMem.setText(",??..."); txtUnusedMem.setTextColor(android.graphics.Color.RED); txtTotalMem.setTextColor(android.graphics.Color.RED); txtTraffic.setTextColor(android.graphics.Color.RED); imgClose = (ImageView) viFloatingWindow.findViewById(R.id.emmagee_close); linLayout = (LinearLayout) viFloatingWindow.findViewById(R.id.Lin); imgMeminfo = (ImageView) viFloatingWindow.findViewById(R.id.emmagee_meminfo); createFloatingWindow(); } createResultCsv(); handler.postDelayed(task, 1000); }
From source file:com.murati.oszk.audiobook.playback.LocalPlayback.java
public LocalPlayback(Context context, MusicProvider musicProvider) { Context applicationContext = context.getApplicationContext(); this.mContext = applicationContext; this.mMusicProvider = musicProvider; this.mAudioManager = (AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) this.mWifiLock = ((WifiManager) applicationContext.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "uAmp_lock"); }
From source file:it.evilsocket.dsploit.core.System.java
public static void init(Context context) throws Exception { mContext = context;//from ww w . ja v a 2s . c o m try { mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "dsploit-session-" + java.lang.System.currentTimeMillis(); mUpdateManager = new UpdateManager(mContext); mPlugins = new ArrayList<Plugin>(); mTargets = new Vector<Target>(); mOpenPorts = new SparseIntArray(3); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (mWifiLock.isHeld() == false) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true) == true) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (mWakeLock.isHeld() == false) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; } mNmap = new NMap(mContext); mArpSpoof = new ArpSpoof(mContext); mEttercap = new Ettercap(mContext); mIptables = new IPTables(); mHydra = new Hydra(mContext); mTcpdump = new TcpDump(mContext); // initialize network data at the end mNetwork = new Network(mContext); Target network = new Target(mNetwork), gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()), device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware()); gateway.setAlias(mNetwork.getSSID()); device.setAlias(android.os.Build.MODEL); mTargets.add(network); mTargets.add(gateway); mTargets.add(device); mInitialized = true; } catch (Exception e) { errorLogging(TAG, e); throw e; } }