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:net.majorkernelpanic.spydroid.ui.HandsetFragment.java
@Override public void onStart() { super.onStart(); // Print version number Context mContext = SpydroidApplication.getContext(); try {//from www. j a v a 2 s . c o m //mVersion.setText("v"+mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0 ).versionName); mVersion.setText("v0.1"); } catch (Exception e) { mVersion.setText("v???"); } displayIpAddress(); WifiManager wifiManager = (WifiManager) SpydroidApplication.getContext() .getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); int i = info.getIpAddress(); final String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff, i >> 24 & 0xff); final String socketUrl = "http://192.168.1.10:3000/socket.io/1/"; final Properties handshakeHeaders = new Properties(); handshakeHeaders.setProperty("X-COLLAB-MEETINGID", "5161e2d4e83131372e000001"); handshakeHeaders.setProperty("X-COLLAB-CONNECTION", ip + ":8086"); mStartButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { Log.i(TAG, "Attempting to connect to " + socketUrl); socket = new SocketIO(socketUrl, handshakeHeaders); } catch (MalformedURLException e) { Log.e(TAG, e.getMessage()); } socket.connect(new IOCallback() { @Override public void onMessage(String data, IOAcknowledge ack) { Log.i(TAG, data); System.out.println("Server said: " + data); } @Override public void onError(SocketIOException socketIOException) { System.out.println("an Error occured"); socketIOException.printStackTrace(); Log.e(TAG, socketIOException.getLocalizedMessage()); } @Override public void onDisconnect() { System.out.println("Connection terminated."); } @Override public void onConnect() { System.out.println("Connection established"); } @Override public void on(String event, IOAcknowledge ack, Object... args) { System.out.println("Server triggered event '" + event + "'"); } @Override public void onMessage(JSONObject arg0, IOAcknowledge arg1) { Log.i(TAG, arg0.toString()); } }); /* //final String socketUrl = "http://192.168.1.10:3000/.io/1/?meeting=5161e2d4e83131372e000001&connection=" + ip + ":8086"; final String socketUrl = "http://192.168.1.10:3000/socket.io/1/"; List<BasicNameValuePair> extraHeaders = Arrays.asList( new BasicNameValuePair("X-COLLAB-MEETINGID", "5161e2d4e83131372e000001"), new BasicNameValuePair("X-COLLAB-CONNECTION", ip + ":8086" ) ); socket = new SocketIOClient(URI.create(socketUrl), new SocketIOClient.Handler() { @Override public void onConnect() { Log.d(TAG, "Connected!"); } @Override public void on(String event, JSONArray arguments) { Log.d(TAG, String.format("Got event %s: %s", event, arguments.toString())); } @Override public void onJSON(JSONObject json) { Log.d(TAG, String.format("Got JSON Object: %s", json.toString())); } @Override public void onMessage(String message) { Log.d(TAG, String.format("Got message: %s", message)); } @Override public void onDisconnect(int code, String reason) { Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason)); } @Override public void onError(Exception error) { Log.e(TAG, "Error!", error); } }, extraHeaders); socket.connect(); */ } }); mStopButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { socket.emit("kill"); socket.disconnect(); socket = null; } }); }
From source file:com.allthatseries.RNAudioPlayer.Playback.java
public Playback(Context context) { this.mContext = context; this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "playback_lock"); this.mState = PlaybackStateCompat.STATE_NONE; }
From source file:com.tml.sharethem.sender.SHAREthemService.java
@Override public void onCreate() { super.onCreate(); wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); hotspotControl = HotspotControl.getInstance(getApplicationContext()); m_notificationStopActionReceiver = new BroadcastReceiver() { @Override/*from w w w .j a va 2 s. c o m*/ public void onReceive(Context context, Intent intent) { if (null != intent && WIFI_AP_ACTION_STOP.equals(intent.getAction())) disableHotspotAndStop(); } }; registerReceiver(m_notificationStopActionReceiver, new IntentFilter(WIFI_AP_ACTION_STOP)); //Start a foreground with message saying 'Initiating Hotspot'. Message is later updated using SHARE_SERVICE_NOTIFICATION_ID startForeground(SHARE_SERVICE_NOTIFICATION_ID, getShareThemNotification(getString(R.string.p2p_sender_service_init_notification_header), false)); hotspotCheckHandler = new HotspotChecker(this); }
From source file:com.hbm.devices.scan.ui.android.DeviceListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /*/*from www. j av a 2 s .c o m*/ * Probably a good idea to update UI only after this method was called. * Then we should have a complete view. In onDestroyView we can stop updating UI. * Probably a better idea is to start/stop updating UI in onResume/onPause. * Has to be clarified if these methods are called when activity goes into background. */ final ScanActivity activity = (ScanActivity) getActivity(); final WifiManager wifi = (WifiManager) activity.getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifi == null) { final Toast failureToast = Toast.makeText(activity, activity.getString(R.string.could_not_get_wifimanager), Toast.LENGTH_SHORT); failureToast.show(); } else { if (wifiLock == null || !wifiLock.isHeld()) { wifiLock = wifi.createWifiLock("wifi lock"); wifiLock.acquire(); } if (mcLock == null || !mcLock.isHeld()) { mcLock = wifi.createMulticastLock("multicast lock"); mcLock.acquire(); } } if (adapter.get() != null) { updateList(); } prefUseFakeMessages = getString(R.string.pref_use_fake_messages); prefFakeMessageType = getString(R.string.pref_fake_message_type); }
From source file:com.lge.helloFriendsCamera.MainActivity.java
public boolean checkIsConnectedToDevice() { WifiManager wifimanager;/*from w w w .j a va2 s.c om*/ wifimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifimanager.getConnectionInfo(); String ssid = info.getSSID(); Log.d("HERE", " ssid = " + ssid); if (ssid.contains(".OSC")) { return true; } else { return false; } }
From source file:com.syncedsynapse.kore2.ui.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly *//*from w ww . ja v a2 s . c o m*/ public void startSearching() { LogUtils.LOGD(TAG, "Starting service discovery..."); searchCancelled = false; final Handler handler = new Handler(); final Thread searchThread = new Thread(new Runnable() { @Override public void run() { WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = null; try { // Get wifi ip address int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress(); InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress); // Acquire multicast lock multicastLock = wifiManager.createMulticastLock("kore2.multicastlock"); multicastLock.setReferenceCounted(false); multicastLock.acquire(); JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create(); // Get the json rpc service list final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT); synchronized (lock) { // If the user didn't cancel the search, and we are sill in the activity if (!searchCancelled && isAdded()) { handler.post(new Runnable() { @Override public void run() { if ((serviceInfos == null) || (serviceInfos.length == 0)) { noHostFound(); } else { foundHosts(serviceInfos); } } }); } } } catch (IOException e) { LogUtils.LOGD(TAG, "Got an IO Exception", e); } finally { if (multicastLock != null) multicastLock.release(); } } }); titleTextView.setText(R.string.searching); messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message))); messageTextView.setMovementMethod(LinkMovementMethod.getInstance()); progressBar.setVisibility(View.VISIBLE); hostListGridView.setVisibility(View.GONE); // Setup buttons nextButton.setVisibility(View.INVISIBLE); previousButton.setVisibility(View.VISIBLE); previousButton.setText(android.R.string.cancel); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { synchronized (lock) { searchCancelled = true; noHostFound(); } } }); searchThread.start(); }
From source file:com.example.chu.googleplaylibrary.playback.LocalPlayback.java
public LocalPlayback(Context context, String mMusicProvider) { this.mContext = context; this.mMusicProvider = mMusicProvider; this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "uAmp_lock"); this.mState = PlaybackStateCompat.STATE_NONE; }
From source file:dev.ukanth.ufirewall.InterfaceTracker.java
private static void getTetherStatus(Context context, InterfaceDetails d) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); Method[] wmMethods = wifi.getClass().getDeclaredMethods(); d.isTethered = false;//from w ww .j a va 2s . com d.tetherStatusKnown = false; for (Method method : wmMethods) { if (method.getName().equals("isWifiApEnabled")) { try { d.isTethered = ((Boolean) method.invoke(wifi)).booleanValue(); d.tetherStatusKnown = true; Log.d(TAG, "isWifiApEnabled is " + d.isTethered); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.mylovemhz.simplay.MusicService.java
private void initialize() { trackQueue = new ArrayList<>(); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setOnErrorListener(this); mediaPlayer.setOnPreparedListener(this); mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "music lock"); ComponentName receiver = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName()); mediaSession = new MediaSessionCompat(this, TAG_MUSIC_SERVICE, receiver, null); mediaSession.setFlags(// w ww. j av a 2s.c o m MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(new SimpleSessionCallback(this)); currentState = State.IDLE; mediaSession.setActive(true); isInitialized = true; Log.d(TAG_MUSIC_SERVICE, "Initialized..."); }
From source file:com.melchor629.musicote.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Set the user interface layout for this Activity // The layout file is defined in the project res/layout/main.xml file super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w. j ava 2s . c o m*/ appContext = getApplicationContext(); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.mainLayout); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorGrey600); final ListView list = (ListView) findViewById(android.R.id.list); list.setOnScrollListener(new ListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { boolean enable = false; if (list != null && list.getChildCount() > 0) { // check if the first item of the list is visible boolean firstItemVisible = list.getFirstVisiblePosition() == 0; // check if the top of the first item is visible boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0; // enabling or disabling the refresh layout enable = firstItemVisible && topOfFirstItemVisible; } swipeRefreshLayout.setEnabled(enable); } }); getActionBar().setIcon(R.drawable.ic_launcher); getActionBar().setDisplayUseLogoEnabled(true); // La app prueba en busca de la direccin correcta WifiManager mw = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wi = mw.getConnectionInfo(); String SSID = wi.getSSID(); Log.i("MainActivity", "Wifi conectado: " + SSID + " " + (SSID != null ? SSID.equals("Madrigal") : "")); if (SSID == null) { SSID = ""; Toast.makeText(this, getString(R.string.no_wifi), Toast.LENGTH_LONG).show(); } if (SSID.equals("Madrigal") || SSID.contains("Madrigal") || System.getProperty("os.version").equals("3.4.67+")) { MainActivity.HOST = "192.168.1.133"; } else { MainActivity.HOST = "reinoslokos.no-ip.org"; } Log.i("MainActivity", "HOST: " + HOST); //Deletes the notification if remains (BUG) NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Reproductor.a == -1) mn.cancel(1); mn.cancel(3); //Revisa la base de datos DB mDbHelper = new DB(getBaseContext()); SQLiteDatabase db = mDbHelper.getWritableDatabase(); //Actualizacin de la lista if (mDbHelper.isNecesaryUpgrade(db) && Utils.HostTest(HOST) == 200) async(); else cursordb(db); db.close(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }