Example usage for android.net.wifi WifiInfo getMacAddress

List of usage examples for android.net.wifi WifiInfo getMacAddress

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo getMacAddress.

Prototype

public String getMacAddress() 

Source Link

Usage

From source file:de.teambluebaer.patientix.activities.LoginActivity.java

/**
 * Method to get the MACAddress of the device
 *
 * @return String of the MACAddress of the device
 */// ww w . java2  s. c  o m
private String getMacAddress() {
    WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = manager.getConnectionInfo();
    return info.getMacAddress();
}

From source file:biz.easymenu.easymenung.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.settings, container, false);

    String strVersion = "";

    PackageInfo packageInfo;/*from   www  .  java  2 s.  c  om*/
    try {
        packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        strVersion = packageInfo.versionName;
    } catch (NameNotFoundException e) {
        //e.printStackTrace();
        strVersion = "Cannot load Version!";
    }

    WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String macAddress = wifiInfo == null ? "" : wifiInfo.getMacAddress();

    ((EditText) v.findViewById(R.id.txtVersion)).setText(strVersion);
    ((EditText) v.findViewById(R.id.txtMac)).setText(macAddress);
    (etServer = (EditText) v.findViewById(R.id.txtServer)).setText(emp.getValue("server"));
    (etPassword = (EditText) v.findViewById(R.id.txtPassword)).setText(emp.getValue("password"));

    rg = (RadioGroup) v.findViewById(R.id.rgSync);
    pbar = (ProgressBar) v.findViewById(R.id.pBarSync);

    btnSync = (Button) v.findViewById(R.id.btnSync);
    btnSave = (Button) v.findViewById(R.id.btnConfSave);
    btnClose = (Button) v.findViewById(R.id.btnConfClose);

    btnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            emp.setKeyValue("server", etServer.getText().toString());
            emp.setKeyValue("password", etPassword.getText().toString());
            emp.commit();

            /*FragmentManager fm = getActivity().getSupportFragmentManager();
             FragmentTransaction ft ;
             Fragment f = null;
             if(fm.findFragmentByTag("rightfragment")!=null){
              ft = fm.beginTransaction();
              ft.setCustomAnimations(android.R.anim.fade_in,
                  android.R.anim.fade_out);
              ft.remove(fm.findFragmentByTag("rightfragment"));
              ft.commit();
            }
             f = new TableListFragment();
             ft = fm.beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in,
                android.R.anim.fade_out);
            ft.add(R.id.rightcontent,f,"rightfragment");
            ft.commit();
            getActivity().findViewById(R.id.btnConfig).setVisibility(View.GONE);
            */}
    });

    btnClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*emp.setKeyValue("server", etServer.getText().toString());
            emp.setKeyValue("password", etPassword.getText().toString());
            emp.commit();
            */
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft;
            Fragment f = null;
            if (fm.findFragmentByTag("rightfragment") != null) {
                ft = fm.beginTransaction();
                ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
                ft.remove(fm.findFragmentByTag("rightfragment"));
                ft.commit();
            }
            f = new TableListFragment();
            ft = fm.beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
            ft.add(R.id.rightcontent, f, "rightfragment");
            ft.commit();
            getActivity().findViewById(R.id.btnConfig).setVisibility(View.GONE);
        }
    });

    btnSync.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int rbid = rg.getCheckedRadioButtonId();
            pbar.setVisibility(View.VISIBLE);
            new Thread(new syncRun(rbid)).start();
        }
    });

    return v;
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the device WiFi MAC//from w  ww .ja  v  a 2 s.c o  m
*/
public String getMACAddress() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifiManager.getConnectionInfo();
    mac = wInfo.getMacAddress();
    return mac;
}

From source file:org.pidome.client.phone.services.SystemService.java

/**
 * Generate an unique id for this device.
 * @param context/*from w w w  .  jav a2s.c  o m*/
 * @return 
 */
private String generateDeviceId(Context context) {
    final String macAddr, androidId;
    WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInf = wifiMan.getConnectionInfo();
    macAddr = wifiInf.getMacAddress();
    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid;
    try {
        deviceUuid = new UUID(androidId.hashCode(), macAddr.hashCode());
    } catch (NullPointerException ex) {
        deviceUuid = new UUID(androidId.hashCode(), androidId.hashCode());
    }
    return deviceUuid.toString();
}

From source file:org.teleal.cling.android.browser.MainActivity.java

public void switchToDeviceList() {
    setListAdapter(deviceListAdapter);/*from ww  w  .  ja  va 2 s  . c o m*/

    /*
     * Executes when the user (long) clicks on a device:
     */
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DeviceDisplay clickedDisplay = deviceListAdapter.getItem(position);
            if (clickedDisplay != null) {
                // ... clickedDisplay.getDevice();
                Service service = clickedDisplay.getDevice().findService(new UDAServiceId("SwitchPower"));
                if (service != null) {
                    Action getStatusAction = service.getAction("GetTarget");
                    ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);

                    new ActionCallback.Default(getStatusInvocation, upnpService.getControlPoint()).run();

                    boolean value = ((Boolean) getStatusInvocation.getOutput("RetTargetValue").getValue())
                            .booleanValue();

                    Action setTargetAction = service.getAction("SetTarget");
                    ActionInvocation setTargetInvocation = new ActionInvocation(setTargetAction);
                    setTargetInvocation.setInput("NewTargetValue", !value);

                    ActionCallback setTargetCallback = new ActionCallback(setTargetInvocation) {

                        @Override
                        public void success(ActionInvocation invocation) {
                            ActionArgumentValue[] output = invocation.getOutput();
                            // assertEquals(output.length, 0);
                        }

                        @Override
                        public void failure(ActionInvocation invocation, UpnpResponse operation,
                                String defaultMsg) {
                            System.err.println(defaultMsg);
                        }
                    };

                    upnpService.getControlPoint().execute(setTargetCallback);
                }

                Service service2 = clickedDisplay.getDevice().findService(new UDAServiceId("ContentDirectory"));
                if (service2 != null) {
                    DeviceIdentity identity = clickedDisplay.getDevice().getIdentity();

                    WifiManager mng = (WifiManager) getSystemService(WIFI_SERVICE);
                    WifiInfo info = mng.getConnectionInfo();
                    String mac = info.getMacAddress();

                    SendPost2 sendPost = new SendPost2(MainActivity.this);
                    sendPost.execute(mac.toString());

                    switchToContentList(identity);
                }
            }
        }
    });

}

From source file:uk.ac.horizon.ubihelper.service.Service.java

public String getDeviceId() {
    WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
    if (wifi != null) {
        WifiInfo wi = wifi.getConnectionInfo();
        if (wi != null) {
            return wi.getMacAddress();
        }/* ww  w  .j a va 2  s.  com*/
    }
    Log.w(TAG, "Could not get device ID");
    return "UNKNOWNID";
}

From source file:RhodesService.java

/**
 * This method is used only for non-Motorola devices as the UUID needs to be computed by other parameters.
 * @return 32-byte long UUID//from w  ww.  j av a  2 s .  c om
 */
private static String computeUUID() {
    RhodesService srv = RhodesService.getInstance();
    if (srv == null)
        throw new IllegalStateException("No rhodes service instance at this moment");
    String res = "";
    WifiManager wifi = (WifiManager) srv.getSystemService(Context.WIFI_SERVICE);
    // Get WiFi status
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    String macAddress = wifiInfo.getMacAddress();
    macAddress = macAddress.replaceAll(":", "");
    UUID localUuid = UUID.nameUUIDFromBytes(macAddress.getBytes());
    res = localUuid.toString().replaceAll("-", "");
    return res.toUpperCase();
}

From source file:system.info.reader.java

public String refresh() {
    //wifi/*from w  w  w. j  av a 2 s.  com*/
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null))
        Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress());
    else
        Properties.setInfo((String) propertyItems[4], "not avaiable");

    //String tmpsdcard = runCmd("df", "");
    //if (tmpsdcard != null) result += tmpsdcard + "\n\n";

    //setMap("dpi", dpi);

    //location
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    List ll = lm.getProviders(true);
    Boolean foundLoc = false;
    for (int i = 0; i < ll.size(); i++) {
        Location lo = lm.getLastKnownLocation((String) ll.get(i));
        if (lo != null) {
            Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude());
            foundLoc = true;
            break;
        }
    }
    if (!foundLoc)
        Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint));

    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List serviceList = am.getRunningServices(10000);
    serviceInfo = "";
    for (int i = 0; i < serviceList.size(); i++) {
        RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i);
        serviceInfo += rs.service.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nService) + serviceList.size() + "\n";//service number

    psInfo = "";
    List appList = am.getRunningAppProcesses();
    for (int i = 0; i < appList.size(); i++) {
        RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i);
        psInfo += as.processName + "\n";
    }
    //result += getString(R.string.nProcess) + appList.size() + "\n";//process number

    taskInfo = "";
    List taskList = am.getRunningTasks(10000);
    for (int i = 0; i < taskList.size(); i++) {
        RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i);
        taskInfo += ts.baseActivity.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number

    //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number

    //setMap(getString(R.string.nApk), nApk);

    //send message to let view redraw.
    Message msg = mRedrawHandler.obtainMessage();
    mRedrawHandler.sendMessage(msg);
    //properListItemAdapter.notifyDataSetChanged();//no use?

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(400);
    return "";
}

From source file:com.yozio.android.YozioHelper.java

private void setMacAddress() {
    try {//w  w w . ja va 2  s  .co  m
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

        if (wifiManager != null) {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();

            if (wifiInfo != null) {
                macAddress = wifiInfo.getMacAddress();
            }
        }
    } catch (Exception e) {
    }
}

From source file:cn.apputest.ctria.section2.Lucha2Activity.java

public String getLocalMacAddress() {
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    return info.getMacAddress();
}