Mehmet Ethem SULAN :: Android :: Get mac address, manufacturer and model of Android Device

Bu uygulama ile Android cihazının Mac Adresi, Modeli ve Manufacturer(Üretici) bilgilerini TextView’e yazmaya çalıştım. Android içinde

import android.os.Build; 

os paketinde bulunan Build static sınıfı ile bir Android cihazlarının birçok bilgilerine erişebiliyoruz. Mesela Build.HARDWARE gibi.

Android Device Information


Network bilgilerine
NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

erişmesi için izin vermemiz lazım.
Ayrıca Wifi erişme izni de vermek lazım.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

Android telefonumun bilgileri.

GetInfoActivity.java

package com.getinfo;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

public class GetInfoActivity extends Activity {
    
	private TextView mac,model,manufacturer;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        model=(TextView) findViewById(R.id.textView1_model);
        mac=(TextView) findViewById(R.id.textView2_mac);
        manufacturer=(TextView) findViewById(R.id.textView3_manufacture);
        model.setText("Model => "+ Build.MODEL);
        
        String mac_adresi=get_mac_address();
		mac.setText("Mac => "+mac_adresi);
        manufacturer.setText("Manufacturer => "+Build.MANUFACTURER);
        
    }
    
    private String get_mac_address()
	{
		ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
	    
	    try{
	    	WifiManager wifiMan = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
	        WifiInfo wifiInf = wifiMan.getConnectionInfo();
	        return wifiInf.getMacAddress();
	    }
	    catch (Exception e) {
	    	return "00:00:00";
		}	
	}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_height="wrap_content" android:text="" 
    android:layout_width="wrap_content" 
    android:id="@+id/textView1_model">
    </TextView>
    <TextView 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_height="wrap_content" android:text="" 
    android:layout_width="wrap_content" 
    android:id="@+id/textView2_mac">
    </TextView>
    <TextView 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_height="wrap_content" android:text="" 
    android:layout_width="wrap_content" 
    android:id="@+id/textView3_manufacture">
    </TextView>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.getinfo"
      android:versionCode="1"
      android:versionName="1.0">
      
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".GetInfoActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

Download GetInfo.tar.gz

Write a Comment

Let me know what you think?