Blog purpose for android basic example for android app developer. any query please my contact

Sunday, 22 March 2020

how to create mobile display information app android studio

how to create mobile display information app android studio



In this tutorial, today learn how to create mobile display information app android studio. this example included the mobile version, display information. follow the how to create mobile display information app android studio.



1.MainActivity.java:


package com.aboutinfo;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView tView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tView = (TextView) findViewById(R.id.logTextView);
showInfo(); // initial display
}
/** Update the info if the screen is rotated, etc. */
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
showInfo();
}
/** Compute the current info, and add it to the textarea. */
void showInfo() {
tView.append("AboutInfo v 0.0" + "\n");
// Get Android information
String manufacturer = Build.MANUFACTURER;
String deviceCode = Build.BOARD;
String device = Build.DEVICE;
String version = Build.DISPLAY;
String codename = Build.VERSION.CODENAME;
String release = Build.VERSION.RELEASE;
int sdk = Build.VERSION.SDK_INT;
tView.append("Make: " + manufacturer + "; Code " + deviceCode + "; Device " + device + "\n");
tView.append("Android: " + codename + " " + release + " API " + sdk + " Load " + version + "\n");

// Get view information
tView.append("\n");
tView.append("Display info:" + "\n");
final Display display = getWindowManager().getDefaultDisplay();

int width, height;

// This method added in API level 13.
Point point = new Point();
display.getSize(point); // READ DISCLAIMER ON METHOD DOCUMENT!!
width = point.x;
height = point.y;
dump("display.getSize()", width, height);

width = display.getWidth();
height = display.getHeight();

dump("display.getWidth(),getHeight", width, height);

DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);

width = metrics.widthPixels;
height = metrics.heightPixels;
dump("metrics.fields", width, height);
}

private void dump(String m, int w, int h) {
tView.append(String.format("Via %s: Width %d, Height %d%n", m, w, h));
}

}





2.activity_main.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" >

    <TextView
        android:id="@+id/logTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="false"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        tools:context=".MainActivity" />

</RelativeLayout>




3.dimens.xml:


<resources>

    <dimen name="padding_small">8dp</dimen>
    <dimen name="padding_medium">8dp</dimen>
    <dimen name="padding_large">16dp</dimen>

</resources>



4.strings.xml :


<resources>
    <string name="app_name">About Info</string>
</resources>


5.AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aboutinfo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


6.Output:




No comments:

Post a Comment