Shaikh Danish
Shaikh Danish

Reputation: 1

Is it possible to get IMEI number for above android 11? I want to use it within organization. App won't be uploaded on play store

hope you are doing well, basically I want save the value unique id for device which is non-resettable Is it possible to get IMEI, Serial number for above android 11? I want to use it within organization. App won't be uploaded on play store. Is there any workaround for it?

and also you can suggest me the solution for how to find uniqueness in each devices.

thank you!

I am trying multiple solution for this but tired to get any solution for fetch the MAC Address,IME and Serail Number.

Upvotes: 0

Views: 578

Answers (1)

Sarmad Ali
Sarmad Ali

Reputation: 142

Android has become increasingly restrictive in providing access to certain device identifiers like IMEI and serial number for privacy and security reasons.

Device Fingerprinting is something we can do. We can create a device fingerprint by collecting various device attributes such as device model, OS version, Build ID (a unique identifier for the software build running on the device. It includes information about the Android version and build date.), and available sensors. This can provide a reasonably unique identifier for each device within your organization.

Here is the code

activity_main.xml

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:gravity = "center"
    android:layout_height = "match_parent"
    tools:context = ".MainActivity">
    <TextView
        android:id = "@+id/text"
        android:textSize = "30sp"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent" />
</LinearLayout>

MainActivity.java

import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import android.Manifest;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;


public class MainActivity extends AppCompatActivity {

    TextView textView;
    @RequiresApi(api = Build.VERSION_CODES.P)

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

        textView = findViewById(R.id.text);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_PHONE_STATE}, 101);
        }

    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case 101:
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                textView.setText(Build.FINGERPRINT);
            } else {
                //not granted
            }
            break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onResume() {
        super.onResume();
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        textView.setText(Build.FINGERPRINT);
    }
}

Add these permissions to the manifest

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

You can find the code here as well: My GitHub

I hope it helps!

Upvotes: 0

Related Questions