Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

Detect value from URL and add it to text for sharing in Android Java

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...