gpt4 book ai didi

java - 无法获取设备 IMEI

转载 作者:行者123 更新时间:2023-12-02 06:19:42 25 4
gpt4 key购买 nike

我想获取设备IMEI,但它总是显示日志:

E/GoogleTagManager: Invalid macro: _gtm.loadEventEnabled

我已经添加了以下内容

apply plugin: 'com.google.gms.google-services'在build.grade中

<uses-permission android:name="android.permission.READ_PHONE_STATE" />在 AndroidManifest.xml 中。

我该如何修复它?或者有什么办法获取设备IMEI吗?

这是我的代码:

public class MainActivity extends AppCompatActivity {

public static String deviceIMEI;

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

TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
deviceIMEI = TelephonyMgr.getDeviceId();
Log.e("MainActivity", "deviceIMEI: " + deviceIMEI);
}

}

这是我的 AndroidManifest.xml:

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

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

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@drawable/icon"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:allowBackup="true" >

<meta-data
android:name="com.google.android.gms.ads.playground-app-id"
android:value="ca-app-pub-8130601335284542~7374133691"/>

<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".CoverActivity"
android:screenOrientation="portrait" />

<activity android:name=".HomePageActivity"
android:screenOrientation="portrait" />

<activity android:name=".PostActivity"
android:screenOrientation="portrait"/>

<activity android:name=".PersonActivity"
android:screenOrientation="portrait"/>

<activity android:name=".FullPostActivity"
android:screenOrientation="portrait"/>

<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>

</manifest>

最佳答案

首先,您必须在 list 文件中请求用户访问电话权限:-

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

此后您可以获得 IMEI 号码

关于java - 无法获取设备 IMEI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55843980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com