So I'm writing an app for a specific area where the user really doesn't need to see the full address. I want to turn a textview into a map address link, but don't want to have to explicitly type the full address.
Pretty simple, I only want to display the address number and street name, but leave the city, state, and zip out. Does anyone know how I can do this? Here's a chunk of my code.
textView.setText(towedVehicle.getAddress());
Linkify.addLinks(textView, Linkify.MAP_ADDRESSES);
After a little searching I was able to solve it pretty easily
Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=address+of+location"));
startActivity(searchAddress);
I made the textview clickable and underlined it to look like a normal link.
SpannableString towedToAddress = new SpannableString(towedVehicle.getTowedToAddress());
towedToAddress.setSpan(new UnderlineSpan(), 0,towedToAddress.length(), 0);
towedToAddress.setSpan(new ForegroundColorSpan(0x990000FF), 0, towedToAddress.length(), 0);
textView.setText(towedToAddress);
textView.setClickable(true);
Opens up in Google maps and works great.
You should be able to do this using Transformfilters in the addLinks method. For an example please check this link.
Related
I'm trying to share a post on my FB wall by an Android native app.
I'm following the official guide available # FBOfficial
I would know if it's possible to share a text, an image and an hashtag and also tag place or friends in the same post.
I tried to use the ShareContent class with no results.
If I use
new SharePhotoContent.Builder()...
it's not possible to add text, because the method "setQuote" is not available.
Otherwise, if I use
new ShareLinkContent.Builder()
it's not possible to add a picture.
I would also know why
setShareHashtag(new ShareHashtag.Builder())
works perfectly but
setPlaceId(String placeId)
never works, also if I add a valid placeId taken from PlaceIds
Is there a way to solve my problem?
TY in advance
I'm preparing an application it's 50% Native 50% Webview. Some users doesn't know how to paste from clipboard on mobile that's why I wanna make an button and user when click this button, it's must paste from clipboard to input. Javascript or Android or PHP I need.
Can you help me about it?
CharSequence pasteData="";
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
pasteData = item.getText();
Then use the pasteData.
As you want to give it to the web, use the message transport from java to javascript. See this: How to call javascript from Android?
Then you only need to send the pasteData to js, use js to change the data of the input.
(If you find it helpful, please mark this as the accepted answer.)
i have a url link am trying to send to my user, but the link breaks up cause. it sends the full link but about half of it is not underlined as a link. this is what am trying to send
String locateUrl="http://maps.google.com?q="+latitude()+","+longitude();
first it does not recognize this ?q= as a link and it just breaks up from there, have checked other answers and tried them but seems not to be working
Just solved this by putting "/" before ?q= thereby making sure the link doesn't break
full link will then be
String locateUrl="http://maps.google.com/?q="+latitude()+","+longitude();
Your link may be breaking because of space at the beginning or in between trim it and then use it.
String locateUrl="http://maps.google.com?q="+latitude()+","+longitude();
locateUrl = locateUrl.trim();
I have Android WebView which displays search results. Using the contextMenu and WebView HitTestResult, I have successfully implemented a list of options like open, save, copy link url.Now, I would like to implement copy link text feature as present in Google chrome android which should copy only link text (title). A similar(not exact) feature is present in default Android browser as "Select text" option. I don't want the code for copying text using clipboard instead my main motto is to determine the way of retrieving the link title. The link url can be retrieved using HitTestResult getExtra() method likewise is there any way to retrieve the link text (title) ?
I have referred How to get loaded web page title in Android WebView? but it gives title after the webpage is loaded not when the link is pressed.
Unfortunately, the link you posted is the fastest way to get the page title (you may refer to the second answer, which is probably faster).
The reason behind this is that a website needs to be loaded before you can read the page title. The advantage of onReceivedTitle() (the second answer of your link) is that it doesn't wait until the whole page is loaded. It waits until enough is loaded to retrieve the title from the document. It also notifies you every time the page title gets change (due to JavaScript or whatever).
Edit:
What chrome does with Copy link text is to copy the text of the link like this:
Linktext
This is very difficult to achieve via a webview, since you need access to the html-content of the webpage. There are some workarounds out there (see here).
The are two APIs (selectText and copySelection) which are pending API council approval, they would help you to do this, but they are not available at the moment.
A clear, official way to do this is not available.
For copy the text try this:-
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(mPostCode);
Toast.makeText(getApplicationContext(), "Your code is copied.", Toast.LENGTH_SHORT).show();
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", mPostCode);
clipboard.setPrimaryClip(clip);
}
I am trying to open email activity and to display in the email's body the following:
Display a hyperlink to a web site.
Display (not attach) an image logo (.png file).
I tried using html/text/image mime type and nothing works for both things.
I even tried to copy the png file to an sdcard and displaying it from sdcard path instead of using the "Assets" location that may be restricted and private only to the application, but it did not help as well!
Can anyone give me a code which works for both things??
Waiting for you help guys!!
Have you tried :
Linkify.addLinks(yourEmailString, Linkify.WEB_URLS);
yourTextView.setMovementMethod(LinkMovementMethod.getInstance());
It will make all links in the message clickable, not sure if this is what you are searching though :)?