Почему я не могу войти в свою учетную запись Adafruit MQTT с телефона Android, но могу из эмулятора с помощью приложенияAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Почему я не могу войти в свою учетную запись Adafruit MQTT с телефона Android, но могу из эмулятора с помощью приложения

Сообщение Anonymous »

Я пытаюсь создать приложение с помощью Android Studio, которое будет входить в мою учетную запись Adafruit MQTT и взаимодействовать с ней. Я создал приложение на Xcode, и оно отлично работает как на симуляторе, так и на моем iPhone.
При использовании студии Android у меня есть начальная страница, на которой пользователю предоставляются пробелы для ввода имени пользователя и ключа пользователя Adafruit. Затем он сохраняется на телефоне и используется для подключения при будущих взаимодействиях.
Это отлично работает, когда в Android Studio используется эмулятор, но когда я устанавливаю приложение на свой телефон, я получаю сообщение журнала

Код: Выделить всё

D/com.example.mqttkotlinsample.ClientFragment$onViewCreated$1: Connection failure: Not authorized to connect (5)
Вот код, который я использую для подключения.

Код: Выделить всё

class ConnectFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_connect, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
var switch = 1
val appContext = requireContext().applicationContext
val prefs = appContext.getSharedPreferences("sharedPref", MODE_PRIVATE)

val user = prefs.getString("UserName",null)
val key = prefs.getString("UserKey",null)
val switched = prefs.getString("switchKey",null)
val switch3 =switched.toString()
//val cameraip = prefs.getString("cameraIP",null)
if (user == null &&
key == null) {
// the key does not exist
view.findViewById(R.id.edittext_username).setText("")
view.findViewById(R.id.edittext_password).setText("")
} else {
// handle the value
val s1 = "tcp://io.adafruit.com:1883"
val clientIDFromEditText =
view.findViewById(R.id.edittext_client_id).text.toString()
view.findViewById(R.id.edittext_username).setText(user)
view.findViewById(R.id.edittext_password).setText(key)
//view.findViewById(R.id.edittext_server_uri).setText(cameraip)

val mqttCredentialsBundle = bundleOf(
MQTT_SERVER_URI_KEY to s1,
MQTT_CLIENT_ID_KEY to clientIDFromEditText,
MQTT_USERNAME_KEY to user,
MQTT_PWD_KEY to key,
//MQTT_CAMERAIP_KEY to cameraip
)

//PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_IMMUTABLE

if (switch3 == "1"){
findNavController().navigate(
R.id.action_ConnectFragment_to_ClientFragment,
mqttCredentialsBundle
)}

}

view.findViewById(R.id.button_prefill).setOnClickListener {
// Set default values in edit texts
//view.findViewById(R.id.edittext_server_uri).setText(MQTT_SERVER_URI)
view.findViewById(R.id.edittext_client_id).setText(MQTT_CLIENT_ID)
view.findViewById(R.id.edittext_username).setText(MQTT_USERNAME)
view.findViewById(R.id.edittext_password).setText(MQTT_PWD)
}

view.findViewById(R.id.button_clean).setOnClickListener {
// Clean values in edit texts

//view.findViewById(R.id.edittext_server_uri).setText("")
view.findViewById(R.id.edittext_client_id).setText("")

}

view.findViewById(R.id.imageButton2).setOnClickListener{

val button1 = view.findViewById(R.id.imageButton2)
if (switch==1) {

val pwdFromEditText = view.findViewById(R.id.edittext_password)
val cursorPosition: Int = pwdFromEditText.selectionStart
pwdFromEditText.transformationMethod = HideReturnsTransformationMethod.getInstance()

pwdFromEditText.setSelection(cursorPosition)
switch = 2
button1.setImageResource(R.drawable.no_see_copy)
}

else if (switch == 2){
val pwdFromEditText = view.findViewById(R.id.edittext_password)
val cursorPosition:  Int = pwdFromEditText.selectionStart
pwdFromEditText.transformationMethod = PasswordTransformationMethod.getInstance()
pwdFromEditText.setSelection(cursorPosition)
switch = 1
button1.setImageResource(R.drawable.see_copy)
}
}

view.findViewById(R.id.button_connect).setOnClickListener {
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {

//PendingIntent.FLAG_IMMUTABLE
//}

val s1 = "tcp://io.adafruit.com:1883"

// val serverURIFromEditText =
// view.findViewById(R.id.edittext_server_uri).text.toString()
val clientIDFromEditText =
view.findViewById(R.id.edittext_client_id).text.toString()
val usernameFromEditText =
view.findViewById(R.id.edittext_username).text.toString()
val pwdFromEditText =
view.findViewById(R.id.edittext_password).text.toString()

val mqttCredentialsBundle = bundleOf(
MQTT_SERVER_URI_KEY to s1,
MQTT_CLIENT_ID_KEY to clientIDFromEditText,
MQTT_USERNAME_KEY to usernameFromEditText,
MQTT_PWD_KEY to pwdFromEditText,
//MQTT_CAMERAIP_KEY to serverURIFromEditText
)

findNavController().navigate(
R.id.action_ConnectFragment_to_ClientFragment,
mqttCredentialsBundle
)

//val appContext = requireContext().applicationContext
//val prefs = appContext.getSharedPreferences("sharedPref", MODE_PRIVATE)
val editor = prefs.edit()
editor.putString("UserName", usernameFromEditText)
editor.putString("UserKey", pwdFromEditText)
editor.putString("switchKey", "1")
//editor.putString("cameraIP",serverURIFromEditText)
editor.apply()

}
}
Я не получаю ошибок в коде, и журнал показывает, что serverURI правильный, как и имя пользователя и userKey. В соответствии с инструкциями Adafruit идентификатор клиента оставлен пустым, и, как я уже сказал, он подключается с помощью того же приложения в эмуляторе.
Единственная разница, которую я вижу, заключается в том, что физическое устройство Pixel 3 XL использует API 31, а эмулятор использует 33. , однако у меня есть настройки, позволяющие ему работать минимум 30 минут. На телефоне работает только Android 12.0, поскольку его больше нельзя обновлять, а эмулятор работает под управлением Android 13.
Я действительно могу не думаю, в чем проблема. Если кто-нибудь может придумать решение, дайте мне знать.
Вот полный журнал:

Код: Выделить всё

2024-09-17 15:03:59.294 12625-12625/com.example.mqttkotlinsample D/CompatibilityChangeReporter: Compat change id reported: 171979766; UID 10259; state: ENABLED
2024-09-17 15:03:59.213 12625-12625/? I/qttkotlinsampl: Late-enabling -Xcheck:jni
2024-09-17 15:03:59.268 12625-12625/? D/ProcessState: Binder ioctl to enable oneway spam detection failed: Invalid argument
2024-09-17 15:03:59.422 12625-12625/com.example.mqttkotlinsample V/GraphicsEnvironment: ANGLE Developer option for 'com.example.mqttkotlinsample' set to: 'default'
2024-09-17 15:03:59.422 12625-12625/com.example.mqttkotlinsample V/GraphicsEnvironment: App is not on the allowlist for updatable production driver.
2024-09-17 15:03:59.424 12625-12625/com.example.mqttkotlinsample D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2024-09-17 15:03:59.425 12625-12625/com.example.mqttkotlinsample D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2024-09-17 15:03:59.436 12625-12625/com.example.mqttkotlinsample D/WM-WrkMgrInitializer: Initializing WorkManager with default configuration.
2024-09-17 15:03:59.509 12625-12675/com.example.mqttkotlinsample D/CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10259; state: ENABLED
2024-09-17 15:04:00.128 12625-12625/com.example.mqttkotlinsample W/qttkotlinsampl: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
2024-09-17 15:04:00.128 12625-12625/com.example.mqttkotlinsample W/qttkotlinsampl: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
2024-09-17 15:04:00.353 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment: LAUNCHED!!!!!!!!!!!!!!!!!!!
2024-09-17 15:04:00.680 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment: a2.4
2024-09-17 15:04:00.680 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment: g1008.00006
2024-09-17 15:04:00.680 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment: TRYING!!!!!!!!!!!!!!!!!!!
2024-09-17 15:04:00.682 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment: FLAG!!!!!!!!!!!!!!!!!!!
2024-09-17 15:04:00.682 12625-12625/com.example.mqttkotlinsample D/serverURI: tcp://io.adafruit.com:1883
2024-09-17 15:04:00.682 12625-12625/com.example.mqttkotlinsample D/clientID:
2024-09-17 15:04:00.682 12625-12625/com.example.mqttkotlinsample D/username: xxxxxx
2024-09-17 15:04:00.682 12625-12625/com.example.mqttkotlinsample D/pwd: XXXXXXXXXXX
2024-09-17 15:04:00.758 12625-12680/com.example.mqttkotlinsample I/AdrenoGLES-0: QUALCOMM build                   : 781e7d0, I46ff5fc46f
Build Date                       : 12/01/20
OpenGL ES Shader Compiler Version: EV031.31.04.01
Local Branch                     : QPR1
Remote Branch                    :
Remote Branch                    :
Reconstruct Branch               :
2024-09-17 15:04:00.758 12625-12680/com.example.mqttkotlinsample I/AdrenoGLES-0: Build Config                     : C P 11.0.1 AArch64
2024-09-17 15:04:00.758 12625-12680/com.example.mqttkotlinsample I/AdrenoGLES-0: Driver Path                      : /vendor/lib64/egl/libGLESv2_adreno.so
2024-09-17 15:04:00.761 12625-12680/com.example.mqttkotlinsample I/AdrenoGLES-0: PFP: 0x016ee190, ME: 0x00000000
2024-09-17 15:04:00.762 12625-12680/com.example.mqttkotlinsample W/AdrenoUtils: : Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
2024-09-17 15:04:00.762 12625-12680/com.example.mqttkotlinsample W/AdrenoUtils: : Failed to read chip ID from gpu_model.  Fallback to use the GSL path
2024-09-17 15:04:00.770 12625-12680/com.example.mqttkotlinsample D/hw-ProcessState: Binder ioctl to enable oneway spam detection failed: Invalid argument
2024-09-17 15:04:00.771 12625-12698/com.example.mqttkotlinsample I/Gralloc4: mapper 4.x is not supported
2024-09-17 15:04:00.772 12625-12698/com.example.mqttkotlinsample W/Gralloc3: mapper 3.x is not supported
2024-09-17 15:04:00.774 12625-12698/com.example.mqttkotlinsample W/Gralloc4: allocator 4.x is not supported
2024-09-17 15:04:00.774 12625-12698/com.example.mqttkotlinsample W/Gralloc3: allocator 3.x is not supported
2024-09-17 15:04:01.449 12625-12707/com.example.mqttkotlinsample D/AlarmPingSender: Unregister alarmreceiver to MqttService
2024-09-17 15:04:02.017 12625-12712/com.example.mqttkotlinsample D/AlarmPingSender: Unregister alarmreceiver to MqttService
2024-09-17 15:04:02.050 12625-12625/com.example.mqttkotlinsample D/com.example.mqttkotlinsample.ClientFragment$onViewCreated$1: Connection failure: Not authorized to connect (5)
Надеюсь, кто-нибудь сможет помочь. Если вам нужна дополнительная информация, дайте мне знать.

Подробнее здесь: https://stackoverflow.com/questions/789 ... -i-can-fro
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»