Я хочу получить IMEI устройства, но он всегда показывает журнал:
E / GoogleTagManager: недопустимый макрос: _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>