Kotlin получить модель телефона

How to get and store device ID in Android using Kotlin?

This example demonstrates how to get and store device ID in Android using Kotlin.

Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

Example

Step 3 − Add the following code to src/MainActivity.kt

import android.os.Bundle import android.provider.Settings import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() < override fun onCreate(savedInstanceState: Bundle?) < super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val textView: TextView = findViewById(R.id.textView) val id: String = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) textView.text = "Device ID: $id" >>

Step 4 − Add the following code to androidManifest.xml

Let’s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project’s activity files and click the Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen

Читайте также:  and

Click here to download the project code.

Источник

How to check Android Phone Model programmatically using Kotlin?

This example demonstrates how to check Android Phone Model programmatically using kotlin.

Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

Example

Step 3 − Add the following code to src/MainActivity.kt

Example

import android.os.Build import android.os.Bundle import android.view.View import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() < lateinit var textView: TextView override fun onCreate(savedInstanceState: Bundle?) < super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" textView = findViewById(R.id.textView) >fun getModel(view: View) < textView.text = getPhoneModel() >private fun getPhoneModel(): String? < return Build.MODEL >>

Step 4 − Add the following code to androidManifest.xml

Example

Let’s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project’s activity files and click the Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen

Источник

Android & Kotlin Examples code

Android kotlin tutorials and examples code for android apps developers.

how to get device model name programmatically in Android Kotlin

1. How to get device name programmatically in Kotlin (using Kotlin function)
2. Android get device model name in Android (using Android/Java function)
3. Android get device manufacturer information programmatically

Android.os.Build.MODEL

public static final String MODEL, Added in API level 1
The end-user-visible name for the end product.

Android java function getDeviceName() code:
Utils.java :

public class Utils <
public static String getDeviceName() <
String deviceName = android.os.Build.MODEL; // returns model name
return deviceName;
>
>

import android.os.Build
class K_utils companion object @JvmStatic
fun getPhoneDeviceName():String val model = Build.MODEL // returns model name
return model;
>

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.example.espl.myapplication.K_utils.Companion.getPhoneDeviceName
import com.example.espl.myapplication.Utils.getDeviceName

class MainActivity : AppCompatActivity() override fun onCreate(savedInstanceState: Bundle?) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val tv_java_utils_output: TextView = findViewById(R.id.tv_java_utils_output) as TextView
//using java function getDeviceName()
tv_java_utils_output.text = «Using java Function::»+getDeviceName();

//using kotlin function getPhoneDeviceName()
val tv_kotlin_utils_output: TextView = findViewById(R.id.tv_kotlin_utils_output) as TextView
tv_kotlin_utils_output.text =»Using Kotlin version of Function::»+getPhoneDeviceName();
>
>

xmlns:android=»http://schemas.android.com/apk/res/android»
xmlns:tools=»http://schemas.android.com/tools»
xmlns:app=»http://schemas.android.com/apk/res-auto»
android:layout_width=»match_parent»
android:layout_height=»match_parent»
android:gravity=»center_horizontal»
android:orientation=»vertical»
tools:context=».MainActivity»>

android:gravity=»center_vertical|center_horizontal»
android:layout_width=»wrap_content»
android:id=»@+id/tv_java_utils_output»
android:layout_height=»wrap_content»
android:padding=»10dp»
android:background=»@color/colorGray»
android:layout_margin=»10dp»
android:textColor=»@color/colorPrimary»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintLeft_toLeftOf=»parent»
app:layout_constraintRight_toRightOf=»parent»
app:layout_constraintTop_toTopOf=»parent»/>

android:padding=»10dp»
android:layout_margin=»10dp»
android:textColor=»@color/colorPrimary»
android:id=»@+id/tv_kotlin_utils_output»
android:layout_width=»wrap_content»
android:layout_height=»wrap_content»
android:background=»@color/colorGray»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintLeft_toLeftOf=»parent»
app:layout_constraintRight_toRightOf=»parent»
app:layout_constraintTop_toTopOf=»parent»/>

Output on HTC Desire 620G dual sim phone device model:

android.os.Build.MODEL- get device model name programmatically in Android Kotlin
get android mobile phone model name programmatically — Kotlin

android.os.Build.MANUFACTURER returns public static final String MANUFACTURER — Added in API level 4
The manufacturer of the product/hardware.

Similarly to get the device manufacturer name in android programmatically use below code that returns a manufacturer name as a string.

What is my device manufacturer — detect a android device manufacturer name

String manufacturer = Build.MANUFACTURER;
//For HTC Desire 620G dual sim phone device it returns HTC

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

The easiest Kotlin Library for Android Runtime Permissions & Device Info.

AnirudhLoya/Kotlin-Android-Permissions-DeviceInfo

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

The easiest Kotlin Library for Android Runtime Permissions & Device Info. #ScreenShots

#Usage For Kotlin Your Activity must extends with PermissionsActivity

class MainActivity : PermissionsActivity() 
requestPermissions(Manifest.permission.CALL_PHONE, object : PermissionCallBack < override fun permissionGranted() < super.permissionGranted() Log.v("Call permissions", "Granted") > override fun permissionDenied() < super.permissionDenied() Log.v("Call permissions", "Denied") > >)
import android.Manifest import android.os.Bundle import android.util.Log import io.vrinda.kotlinpermissions.PermissionCallBack import io.vrinda.kotlinpermissions.PermissionsActivity import kotlinx.android.synthetic.main.activity_main.* class MainActivity : PermissionsActivity() < override fun onCreate(savedInstanceState: Bundle?) < super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) callPermission.setOnClickListener < requestPermissions(Manifest.permission.CALL_PHONE, object : PermissionCallBack < override fun permissionGranted() < super.permissionGranted() Log.v("Call permissions", "Granted") >override fun permissionDenied() < super.permissionDenied() Log.v("Call permissions", "Denied") >>) > cameraPermission.setOnClickListener < requestPermissions(arrayOf(android.Manifest.permission.CAMERA, android.Manifest.permission.WRITE_EXTERNAL_STORAGE), object : PermissionCallBack < override fun permissionGranted() < super.permissionGranted() Log.v("Camera permissions", "Denied") >override fun permissionDenied() < super.permissionDenied() Log.v("Camera permissions", "Denied") >>) > > > 

#Dependencies Add this to your app build.gradle

compile 'io.vrinda.kotlinpermissions:kotlinpermissions:1.1' 
DeviceInfo.getBuildBrand() DeviceInfo.getAppName(applicationContext) 
Value functionName returns
Android ID getAndroidID() String
Device Model getModel() String
Manufacturer getManufacturer() String
Product getProduct() String
Fingerprint getFingerprint() String
Hardware getHardware() String
Radio Version getRadioVer() String
Device getDevice() String
Board getBoard() String
Display Version getDisplayVersion() String
Build Brand getBuildBrand() String
Build Host getBuildHost() String
Build Time getBuildTime() long
Build Tags getBuildTags() String
Build User getBuildUser() String
Build version Release getBuildVersionRelease() String
Build version Name getBuildVersionCodename() String
Build version Incremental getBuildVersionIncremental() String
Build version Sdk getBuildVersionSDK() Int
Screen Display Id getScreenDisplayID() String
Get Resolution getResolution(applicationContext) String
Get Display version getDisplayVersion() String
Serial getSerial() String
Os Version getOsVersion() String
Carrier getCarrier() String
Language getLanguage() String
Coutnry getCountry(applicationContext) String
Network Type getNetworkType(applicationContext) String
OS code name getOSCodename() String
OS Version getOSVersion() String
IMEI getIMEI() String
IMSI getIMSI() String
Serial getSerial(applicationContext) String
SIM Serial getSIMSerial(applicationContext) String
GSFID getGSFID(applicationContext) String
BluetoothMac getBluetoothMAC(applicationContext) String
PsuedoUniqueID getPsuedoUniqueID() String
PhoneNo getPhoneNo(applicationContext) String
TIME getTime() String
AppName getAppName(applicationContext) String
AppVersion getAppVersion(applicationContext) String
AppVersion Code getAppVersionCode(applicationContext) String
ActivityName getActivityName(applicationContext) String
PackageName getPackageName(applicationContext) String
Accounts getAccounts(applicationContext) Array
Network Availabilty isNetworkAvailable(applicationContext) Boolean
Running On Emulator isRunningOnEmulator(applicationContext) Boolean

About

The easiest Kotlin Library for Android Runtime Permissions & Device Info.

Источник

Get IMEI Android Kotlin

Get IMEI Android kotlin

In this article, we will discuss getting IMEI of Android device SIM in Kotlin.

2. Get IMEI Android Kotlin

Over time, Android provided functions such as getDeviceId() , getImei() (IMEI for GSM) or getMeid() (MEID for CDMA) to get IMEI information programmatically.

Android deprecated the getDeviceId in Android 8.0 (API level 26) and above devices.

Starting in Android 10 (API level 29), all the APIs getDeviceId() , getImei() (IMEI for GSM) or getMeid() (MEID for CDMA) are restricted to third-party apps and cannot access the device’s IMEI and serial number (non-resettable identifiers). This is to guard the device identifiers.

The app must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to get the details. This permission is available only to system apps. So, the third-party apps installed from the Google Play Store cannot declare privileged permissions.

  • If your app targets Android 9 (API level 28) or lower, and the app has the READ_PHONE_STATE permission then the method returns null.
  • If your app targets Android 9 (API level 28) or lower, and the app does not have the READ_PHONE_STATE permission, or
  • Your app targets Android 10 (API level 29) or higher, then throws a SecurityException .

3. Get IMEI Android Kotlin in System app

If your app is a system app, then declare the READ_PRIVILEGED_PHONE_STATE permission in your manifest file and access IMEI:

val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager if (VERSION.SDK_INT >= 26) < imei = telephonyManager.getImei() >else

4. Get unique identifier in third-party apps

Since third-party apps cannot access IMEI information, Android recommends using resettable identifiers. However, if the third-party apps meet any of the following criteria, then they can collect IMEI information from the device.

  • If your app is the device owner of a fully managed device, a profile owner of an organization owned device, or their delegates. Refer the official documentation DevicePolicyManager.getEnrollmentSpecificId() for more information.
  • App with carrier privileges and TelephonyManager. hasCarrierPrivileges() returns true on any active subscription.
  • App is the default SMS role holder and RoleManager.isRoleHeld(RoleManager.ROLE _SMS) returns true.

5. Conclusion

To sum up, we have learned about getting the IMEI number of Android devices programmatically in Kotlin. Refer to Android 12 articles for the latest updates on Android.

1 thought on “Get IMEI Android Kotlin”

Источник

Оцените статью