List of usage examples for android.net.wifi.p2p WifiP2pManager WIFI_P2P_PEERS_CHANGED_ACTION
String WIFI_P2P_PEERS_CHANGED_ACTION
To view the source code for android.net.wifi.p2p WifiP2pManager WIFI_P2P_PEERS_CHANGED_ACTION.
Click Source Link
From source file:comingle.directory.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialization stuff for P2P WiFi intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); // Indicates a change in the list of available peers. intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); // Indicates the state of Wi-Fi P2P connectivity has changed. intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); // Indicates this device's details have changed. intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); mChannel = mManager.initialize(this, getMainLooper(), null); // wifiDir = new WifiDirectDirectory(this, ADMIN_PORT, REQ_CODE); wifiDir = new WifiDirectComingleDirectory(this, ADMIN_PORT, REQ_CODE); wifiDir.addDefaultRoleEstablishedAction(); wifiDir.addDefaultConnectionEstablishedAction(); final MainActivity self = this; DirectoryChangedListener dir_listener = new DirectoryChangedListener() { @Override/*from ww w.j a va2 s. c om*/ public void doDirectoryChangedAction(List<NodeInfo> peers, List<NodeInfo> added, List<NodeInfo> dropped, int role) { self.refresh(); } }; wifiDir.addDirectoryChangedListener(dir_listener); wifiDirList = new PeerInfoListFragment(R.layout.device_list, R.layout.row_devices, R.id.row_name, R.id.row_location, R.id.row_ip, R.id.row_role, R.id.my_name, R.id.my_location, R.id.my_ip, R.id.my_role, wifiDir); LocalNodeInfoAvailableListener node_listener = new LocalNodeInfoAvailableListener() { @Override public void doLocalNodeInfoAvailableAction(NodeInfo local, int role) { wifiDirList.refreshMyDevice(); } }; wifiDir.addLocalNodeInfoAvailableListener(node_listener); getSupportFragmentManager().beginTransaction().replace(R.id.frag_list, wifiDirList).commit(); }
From source file:com.example.android.wifidirect.WiFiDirectBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { // UI update to indicate wifi p2p status. int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) { // Wifi Direct mode is enabled activity.setIsWifiP2pEnabled(true); //Wi-Fi direct?? } else {/* w ww. j a va2 s.c om*/ activity.setIsWifiP2pEnabled(false); activity.resetData(); } Log.d(WiFiDirectActivity.TAG, "P2P state changed - " + state); } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { // request available peers from the wifi p2p manager. This is an // asynchronous call and the calling activity is notified with a // callback on PeerListListener.onPeersAvailable() //Wi-Fi P2P??PeerListListener.onPeersAvailable()? if (manager != null) { FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_list); manager.requestPeers(channel, (PeerListListener) fragment); } Log.d(WiFiDirectActivity.TAG, "P2P peers changed"); } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { if (manager == null) { return; } NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); if (networkInfo.isConnected()) { // we are connected with the other device, request connection // info to find group owner IP FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceDetailFragment fragment = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_detail); manager.requestConnectionInfo(channel, fragment); //??onConnectionInfoAvailable } else { // It's a disconnect activity.resetData(); } } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { //???? //DeviceListFragment fragment = (DeviceListFragment) activity.getSupportFragmentManager().findFragmentByTag("devicelistfragment"); FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity.getSupportFragmentManager() .findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_list); fragment.updateThisDevice( (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE)); //activity.getSupportFragmentManager().beginTransaction().add(R.id.list_fragment, fragment).commit(); //DeviceDetailFragment fragment2 = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager().findFragmentById(R.id.frag_detail); //fragment2.getrootView().setVisibility(View.VISIBLE); /*Log.d(WiFiDirectActivity.TAG,"Fragment2:"+fragment2); Log.d(WiFiDirectActivity.TAG,"Fragment2.getView():"+fragment2.getView()); Log.d(WiFiDirectActivity.TAG,"Fragment2.getrootView():"+fragment2.getrootView()); Log.d(WiFiDirectActivity.TAG, "Fragment:"+fileTransmitfragment); Log.d(WiFiDirectActivity.TAG, "device:"+(WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));*/ } }
From source file:com.example.locationproject.wifidirect.WiFiDirectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from ww w . j a v a 2 s.co m*/ // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); Log.d(TAG, "Deleting healthplus folder at slave"); File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/location"); if (f.exists()) { try { FileUtils.deleteDirectory(f); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Log.d("WifiDirectActivity", "downloads folder for slave is empty"); } Log.d("WifiDirectACtivity", "calling FileLocatoe service"); Intent i = new Intent(this, FileLocator.class); // Add extras to the bundle //i.putExtra("foo", "bar"); // Start the service startService(i); }
From source file:com.example.healthplus.wifidirect.WiFiDirectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//w w w. jav a2 s . co m // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); Log.d(TAG, "Deleting healthplus folder at slave"); File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/healthplus"); if (f.exists()) { try { FileUtils.deleteDirectory(f); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Log.d("WifiDirectActivity", "downloads folder for slave is empty"); } Intent i = new Intent(this, FileLocator.class); // Add extras to the bundle //i.putExtra("foo", "bar"); // Start the service startService(i); }
From source file:android.csulb.edu.wifidirecttest.WiFiDirectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*ww w. ja v a2s . c o m*/ int PERMISSION_ALL = 1; String[] PERMISSIONS = { Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.CHANGE_WIFI_STATE, Manifest.permission.CHANGE_NETWORK_STATE, Manifest.permission.INTERNET, Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_NETWORK_STATE }; ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL); // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); }
From source file:edu.nust.distributed.downloader.ClientActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client); getActionBar().setDisplayHomeAsUpEnabled(true); wifiManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); wifichannel = wifiManager.initialize(this, getMainLooper(), null); wifiClientReceiver = new WiFiClientBroadcastReceiver(wifiManager, wifichannel, this); wifiClientReceiverIntentFilter = new IntentFilter(); ;/* w w w .ja v a 2 s. com*/ wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); connectedAndReadyToSendFile = false; filePathProvided = false; fileToSend = null; transferActive = false; clientServiceIntent = null; targetDevice = null; wifiInfo = null; registerReceiver(wifiClientReceiver, wifiClientReceiverIntentFilter); setClientFileTransferStatus("Client is currently idle"); //setTargetFileStatus("testing"); }
From source file:com.prgpascal.qrdatatransfer.TransferActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Prevent from Screen rotation MyCustomScreenOrientationManager.lockScreen(TransferActivity.this); // First, get the Intent Extras... checkAndGetIntentExtras(getIntent().getExtras()); // Add the required intent filter values for the WIFI Direct connection intentFilter = new IntentFilter(); intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); // Initialize the WiFiP2PManager and get the Channel manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); // Delete previous persistent Wifi Direct groups deletePreviousPersistentGroups();//from w ww. j a v a 2 s .c o m // Create the layout createLayout(); }
From source file:com.example.ramesh.p2pfileshare.ClientActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client); getActionBar().setDisplayHomeAsUpEnabled(true); sendFileButton = (Button) findViewById(R.id.send_file_button); discoverPeersButton = (Button) findViewById(R.id.discover_peers_button); wifiManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); wifichannel = wifiManager.initialize(this, getMainLooper(), null); wifiClientReceiver = new WiFiClientBroadcastReceiver(wifiManager, wifichannel, this); wifiClientReceiverIntentFilter = new IntentFilter(); ;// w w w . j av a 2 s . c o m wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); wifiClientReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); connectedAndReadyToSendFile = false; filePathProvided = false; fileToSend = null; transferActive = false; clientServiceIntent = null; targetDevice = null; wifiInfo = null; registerReceiver(wifiClientReceiver, wifiClientReceiverIntentFilter); setClientFileTransferStatus("Client is currently idle"); //setTargetFileStatus("testing"); }
From source file:com.monkey.entonado.MainActivity.java
/** * Inicializa la actividad//w w w.j a va2s. c o m */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); mChannel = mManager.initialize(this, getMainLooper(), null); mReceiver = new WiFiDirectBroadCastReceiver(mManager, mChannel, this); mIntentFilter = new IntentFilter(); mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); btnBuscar = (TextView) findViewById(R.id.btnBuscar); btnBuscar.setOnClickListener(this); radioTitulo = (Button) findViewById(R.id.btnTitulo); radioArtista = (Button) findViewById(R.id.btnArtista); campoBusqueda = (EditText) findViewById(R.id.campoBusqueda); busqueda = (TextView) findViewById(R.id.txtBusqueda); out = null; in = null; canciones = new ArrayList(); milista = new ArrayList(); mensajeConexion = "No se estableci la conexion"; intentoConectar = false; ip = ""; }
From source file:com.example.android.listentgt.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); PACKAGE_NAME = getApplicationContext().getPackageName(); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent./*w w w.j ava2s . c om*/ actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab(actionBar.newTab().setText(pages[i]).setTabListener(this)); } //Initalize fragments fragment1 = new FragmentPlayList(); fragment2 = new DeviceListFragment(); fragment3 = new FragmentSettingsPage(); //wifiP2pManagerActivity intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); }