Android Studio Mac adresi, Model ve Üretici Bilgileri

Android Studio Mac adresi, Model ve Üretici Bilgileri

Android programlama yazarken bazen Mac Adresi , Model ya da Üretici bilgileri gibi bazı şeyler ihtiyacımıza yarayabilir. Şimdi onlarla ilgili bilgilere ulaşıcaksınız.

import android.os.Build; Build sınıfında bir çok bilgilere erişebiliyoruz. Mesela Şuan üstte yazdığım bilgiler.

Şimdi Hemen başlıyalım. Yeni Projemizde Öncelikle boş 3 tane textView atıyoruz.. Tasarım kısmı ve Kodu..
Layout Kodumuz :

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

<?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:id="@+id/textView2_mac"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge" >

 

    </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>

 

Java Kodumuz :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

package com.example.myapplication;

 

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 startingPage 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";

        }

    }

}

 

ve android Manifest Dosyamız.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.myapplication" >

 

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

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

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

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

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name=".MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity

            android:name=".startingPage"

            android:label="@string/app_name" >

 

        </activity>

    </application>

 

</manifest>

 

Uygulamanın Çalışması :


 

Henüz Yorum Yapılmamış, İlk Yorumu Siz Yapın

Yorum Yollayın