Il peut être fait, mais d'une manière délicate.
Vous pouvez créer un petit fichier html avec un formulaire de soumission automatique, le lire dans une chaîne, remplacer les paramètres et l'incorporer dans l'intention sous la forme d'un uri de données au lieu d'un URL. Il y a quelques petites choses négatives, cela fonctionne uniquement en appelant le navigateur par défaut directement, et le truc sera stocké dans l'historique du navigateur, il apparaîtra si vous revenez en arrière.
Voici un exemple:
fichier HTML (/ res/raw):
<html>
<body onLoad="document.getElementById('form').submit()">
<form id="form" target="_self" method="POST" action="${url}">
<input type="hidden" name="param1" value="${value}" />
...
</form>
</body>
</html>
code source:
private void browserPOST() {
Intent i = new Intent();
// MUST instantiate android browser, otherwise it won't work (it won't find an activity to satisfy intent)
i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
i.setAction(Intent.ACTION_VIEW);
String html = readTrimRawTextFile(this, R.raw.htmlfile);
// Replace params (if any replacement needed)
// May work without url encoding, but I think is advisable
// URLEncoder.encode replace space with "+", must replace again with %20
String dataUri = "data:text/html," + URLEncoder.encode(html).replaceAll("\\+","%20");
i.setData(Uri.parse(dataUri));
startActivity(i);
}
private static String readTrimRawTextFile(Context ctx, int resId) {
InputStream inputStream = ctx.getResources().openRawResource(resId);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
StringBuilder text = new StringBuilder();
try {
while ((line = buffreader.readLine()) != null) {
text.append(line.trim());
}
}
catch (IOException e) {
return null;
}
return text.toString();
}
Avez-vous jamais ce travail? J'essaie de faire la même chose. – jax