Android Open Source - tapad-android-sdk Wifi Mac






From Project

Back to project page tapad-android-sdk.

License

The source code is released under:

MIT License

If you think the Android project tapad-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tapad.tracking.deviceidentification;
//from   w  w  w .  j  a  va  2 s .c  o  m
import android.content.Context;
import android.net.wifi.WifiManager;
import com.tapad.util.DigestUtil;
import com.tapad.util.Logging;

import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

/**
 * This class knows how to fetch and encode the WIFI MAC address
 * <p/>
 * Gets the WIFI MAC address hashed with MD5 and formatted as a 32 byte hexadecimal number.
 * Gets the WIFI MAC address hashed with SHA1 and formatted as a 40 byte hexadecimal number.
 * <p/>
 * Usage of this class requires adding the following to the AndroidManifest.xml
 * <p/>
 * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
 */
public class WifiMac implements IdentifierSource {
    @Override
    public List<TypedIdentifier> get(Context context) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        String wifiMac = wifiManager.getConnectionInfo().getMacAddress();
        List<TypedIdentifier> ids = new ArrayList<TypedIdentifier>();
        if (wifiMac != null) {
            try {
                ids.add(new TypedIdentifier(TypedIdentifier.TYPE_WIFI_MAC_MD5, DigestUtil.md5Hash(wifiMac)));
            } catch (NoSuchAlgorithmException nsae) {
                Logging.error("Tracking", "Error hashing WIFI_MAC - MD5 not supported");
            }
            try {
                ids.add(new TypedIdentifier(TypedIdentifier.TYPE_WIFI_MAC_SHA1, DigestUtil.sha1Hash(wifiMac)));
            } catch (NoSuchAlgorithmException nsae) {
                Logging.error("Tracking", "Error hashing WIFI_MAC - SHA1 not supported");
            }
        } else {
            Logging.warn("Tracking", "Error retrieving WIFI_MAC.");
        }
        return (ids);
    }
}




Java Source Code List

com.tapad.adserving.AdRequestDispatcher.java
com.tapad.adserving.AdRequest.java
com.tapad.adserving.AdResource.java
com.tapad.adserving.AdResponse.java
com.tapad.adserving.AdServingServiceImpl.java
com.tapad.adserving.AdServingService.java
com.tapad.adserving.AdServing.java
com.tapad.adserving.AdSize.java
com.tapad.adserving.ui.AdView.java
com.tapad.sample.AdViewActivity.java
com.tapad.sample.MainActivity.java
com.tapad.sample.MainApplication.java
com.tapad.sample.ManualMarkupActivity.java
com.tapad.sample.SampleConstants.java
com.tapad.tracking.DeviceIdentifier.java
com.tapad.tracking.DeviceInfo.java
com.tapad.tracking.EventDispatcher.java
com.tapad.tracking.EventResource.java
com.tapad.tracking.Event.java
com.tapad.tracking.InstallReferrerReceiver.java
com.tapad.tracking.TrackingServiceImpl.java
com.tapad.tracking.TrackingService.java
com.tapad.tracking.Tracking.java
com.tapad.tracking.deviceidentification.AndroidId.java
com.tapad.tracking.deviceidentification.IdentifierSourceAggregator.java
com.tapad.tracking.deviceidentification.IdentifierSource.java
com.tapad.tracking.deviceidentification.PhoneId.java
com.tapad.tracking.deviceidentification.TypedIdentifier.java
com.tapad.tracking.deviceidentification.WifiMac.java
com.tapad.util.DigestUtil.java
com.tapad.util.HttpClientUtil.java
com.tapad.util.IoUtil.java
com.tapad.util.Logging.java