I was playing with a WebView app and couldn't figure out how to take a string value from the URL and add it to the "share" option.
The following is the app's share funtion
} else if (id == R.id.nav_share) {
String sharetext = "Here is the invitation code. http://example.net/invite.html?id=xxxx";
ShareItem(sharetext,"","Share with");
}
If the currently loaded URL has the same (id=xxxx) like this http://example.net/home.html?id=xxxx
, how can I take that id value to app's share feature.
I tried the following from stack overflow (just to test with fake url)
Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
//Then you can even get a specific element from the query parameters as such;
String chapter = uri.getQueryParameter("chapter"); //will return "V-Maths-Addition "
and
} else if (id == R.id.nav_share) {
String sharetext = "Here is the invitation code. http://example.net/invite.html?id=" + getResources().getString(R.string.chapter) + ";
ShareItem(sharetext,"","Share with");
}
and added <string name="chapter">Chapter</string>
in strings.xml, but it just shows the text "Chapter".
question from:
https://stackoverflow.com/questions/66059729/detect-value-from-url-and-add-it-to-text-for-sharing-in-android-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…