Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9077351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:19:12+00:00 2026-06-16T19:19:12+00:00

I have a basic Login Screen that the tablet user will log in to,

  • 0

I have a basic Login Screen that the tablet user will log in to, I want to display that particular device’s MAC address onscreen when the app starts.

Later as I learn more about Android development, and I’m learning slowly, I want to insert the users name, the time they logged in, and the MAC address to a database via a RESTful webservice. But for now I’m just trying to display the MAC address.

I found some code for obtaining the MAC address from the WIFI Manager as you’ll see in my code below and put it in a method. It seems when I call this method in the onCreate method the app bombs. What is the correct work flow? Should I call showMACAddress() from within the onCreate() method? Should it be in a try / catch??

BTW i’m testing this on my 7 inch Kenton tablet with Android 4.0 as I work, and I have specified in the Android Manifest file that the app is Landscape orientation only.
Thank you in advance.

here is my java class

package za.co.crcode.Inspector;

import android.net.wifi.WifiInfo;  
import android.net.wifi.WifiManager;  
import android.os.Bundle;  
import android.app.Activity;  
import android.content.Context;  
import android.view.Menu;  
import android.widget.TextView;  

public class DeviceLogin extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_login);
        showMACAddress();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_device_login, menu);
        return true;        
    }

    public void showMACAddress(){
        WifiManager wifiMan = (WifiManager) this.getSystemService(
            Context.WIFI_SERVICE);
        WifiInfo wifiInf = wifiMan.getConnectionInfo();
        String macAddr = wifiInf.getMacAddress();

        TextView loginDeviceMACAddress = (TextView)findViewById(R.id.LoginDeviceMACAddress);
        CharSequence macAddy = (String) macAddr.toString();     

        loginDeviceMACAddress.setText(macAddy);
    }

}

here is my Android GUI XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DeviceLogin" >

    <LinearLayout
        android:id="@+id/LoginFieldsLayoutLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="50dp"
        android:gravity="left"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/LoginScreenHeading"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_marginTop="20dp"
            android:text="@string/loginScreenHeading"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/LoginFirstName"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="@string/loginFirstNameHint"
            android:inputType="textPersonName"
            android:text="@string/loginFirstName" />

        <EditText
            android:id="@+id/LoginLastName"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="@string/loginLastNameHint"
            android:inputType="textPersonName"
            android:text="@string/loginLastName" />

        <EditText
            android:id="@+id/LoginEmployeeID"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="@string/loginEmployeeIDHint"
            android:inputType="number"
            android:text="@string/loginEmployeeID" />

        <EditText
            android:id="@+id/loginPassword"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="@string/loginPasswordHint"
            android:inputType="textPassword" >


        </EditText>

        <TextView
            android:id="@+id/LoginMACAddressLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="@string/LoginMACAddressLabel"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <TextView
            android:id="@+id/LoginDeviceMACAddress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="@string/LoginMACAddress"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LoginFieldsLayoutRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"        
        android:layout_marginTop="75dp"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/LoginIdPic"
            android:contentDescription="@string/EmployeeImage"          
            android:layout_width ="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxWidth="200dp"
            android:maxHeight="200dp"
            android:scaleType="fitCenter"           
            android:src="@drawable/idpic" >         
        </ImageView>

        <Button
            android:id="@+id/LoginScreenButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/loginButtonText"
            android:layout_gravity="center" />                      

    </LinearLayout>  

</RelativeLayout>

here is my Strings.XML

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

    <string name="app_name">Inspector</string>
    <string name="hello_world">Hello World!</string>
    <string name="menu_settings">Settings</string>
    <string name="loginScreenHeading">Device Login</string>    
    <string name="loginFirstName">First Name</string>
    <string name="loginFirstNameHint">Enter your first name</string>
    <string name="loginLastName">Last Name</string>
    <string name="loginLastNameHint">Enter your last name</string>
    <string name="loginEmployeeID">Employee ID</string>
    <string name="loginEmployeeIDHint">Enter your employee ID</string>
    <string name="loginPasswordHint">Password</string>
    <string name="LoginMACAddressLabel">Device ID</string>
    <string name="LoginMACAddress">00:00:00:00</string>
    <string name="loginButtonText">Login</string>
    <string name="EmployeeImage">Employee_image</string>
</resources>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:19:13+00:00Added an answer on June 16, 2026 at 7:19 pm

    The setText() should work and you don’t have to cast macAddr from String to CharSequence(CharSequence is an Interface and String implements it). I believe why your app crashes is because you *don’t add the permission * to the AndroidManifest.xml file.

    Put <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> in the AndroidManifest.xml and your problem should be solved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small app that attempts to do basic login with FB using
I have got a basic login script at the moment. When the user logs
I am having an issue w/ a pretty basic login screen. It does have
I have a basic authentication process that uses Zend_Auth_Adapter_DbTable . I have login and
I have a basic PHP form (a few fields and 2 checkboxes, I want
I have a basic web service that returns the following object as JSON: public
I'm currently building a GWT login screen and I managed to get a basic
I have a custom shell script that runs each time a user logs in
I have created basic login module in ASP.net using C#. I am using C#
I have a login function in my controller that was getting called before, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.