Esa2gjk1dh1k Basics: instructions for mqtt package encapsulated by Android
•
Android
<iframe frameborder="0" height="800" name="ifd" scrolling="auto" src="%20https://mnif.cn/%20Development%20board%20/%20esa2gjk1dh1k%20/%20basics%20/%20directory.html%20"width =" 100% "> < / iframe >
In order to avoid repetition, this section uses the works of the previous section as the works of this section
The current project mentioned later is the project of this section
First, copy the mymqttclient in the app source code in the first section of the test to the current project
Second, in the source code, the IMEI of the mobile phone is used as the ClientID of mqtt. Copy the IMEI in the source code to obtain the IMEI
Code to current project
public static String TelephonyIMEI = "";//获取手机IMEI
TelephonyIMEI = getTelephonyIMEI(getApplicationContext());//获取手机 IMEI
/*获取手机IMEI号*/ private String getTelephonyIMEI(Context context) { String id = "IMEI"; TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { if (mTelephony.getdeviceid() != null) { id = mTelephony.getdeviceid(); } } else { id = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID); } return id; }
3、 Add permissions
Computer stuck, restarting
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码