Bonjours à tous,
Je suis en train de me familiariser avec le concept d'implicit intents et je me heurte à un comportement que je n'arrive pas à expliquer ...
J'ai créé une app toute bête qui comprend un bouton appelant la méthode openWebsite décrite ci-dessous :
L'idée est d'appeler une activité capable d’interagir avec l'url passé dans l'intent (un navigateur donc).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public void openWebsite(View view) { // Parse de l'url et création l'Intent Uri webpage = Uri.parse("http://www.developper.net"); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); // Vérifie l'existence d'au moins une app prenant en charge l'intent if (intent.resolveActivity(getPackageManager()) != null) { // <========================= Return toujours null ?? startActivity(intent); } else { Log.d(LOG_TAG, "Method openWebsite Error"); }
Le problème est que la condition de vérification de l'activité n'est jamais validée, et la fonction startActivity(intent) ne s'exécute donc pas !
Je n'arrive pas à comprendre pourquoi, d'autant que cela fonctionne parfaitement sans cette vérification (je pourrais faire sans mais ça ne me parait pas être une bonne pratique).
Si quelqu'un à une piste / idée / explication, je suis preneur parce que jusqu'à présent je n'ai trouvé aucune infos autour de ce problème.
Voici un extrait du LogCat si ça peut aider :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 2020-07-08 16:03:03.935 9396-9396/com.example.implicitintents D/MainActivity: =============================== 2020-07-08 16:03:03.935 573-882/system_process I/AppsFilter: interaction: PackageSetting{d862084 com.example.implicitintents/10150} -> PackageSetting{370a098 com.example.implicitintentsreceiver/10149} BLOCKED 2020-07-08 16:03:03.936 573-882/system_process I/AppsFilter: interaction: PackageSetting{d862084 com.example.implicitintents/10150} -> PackageSetting{1b53bf2 org.chromium.webview_shell/10115} BLOCKED 2020-07-08 16:03:03.936 573-882/system_process I/AppsFilter: interaction: PackageSetting{d862084 com.example.implicitintents/10150} -> PackageSetting{19a7243 com.android.chrome/10122} BLOCKED 2020-07-08 16:03:03.936 9396-9396/com.example.implicitintents D/MainActivity: Method openWebsite Error 2020-07-08 16:03:03.936 573-1529/system_process I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4 2020-07-08 16:03:03.937 573-1529/system_process I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4 2020-07-08 16:03:03.937 1044-4227/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16273869 , only wrote 16273820 2020-07-08 16:03:04.036 573-9461/system_process D/AudioTrack: logBufferSizeUnderruns(), mMetricsId = audio.track.8 2020-07-08 16:03:04.088 461-1223/? D/AudioAnalytics: (key=audio.track.8) Track latencyMs:54.499245 startupMs:45.767480 detected on port:8 device:(AUDIO_DEVICE_OUT_SPEAKER, ) 2020-07-08 16:03:04.136 573-1529/system_process I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4 2020-07-08 16:03:07.070 1044-1044/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16548245 , only wrote 16411969 2020-07-08 16:03:07.072 573-882/system_process I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4 2020-07-08 16:03:09.763 1102-1908/com.google.android.apps.nexuslauncher E/ActivityThread: Failed to find provider info for com.google.android.apps.wellbeing.api 2020-07-08 16:03:20.055 428-428/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument 2020-07-08 16:03:20.186 437-437/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
Partager