Android:autoLink not working fully on my 4.4 device - android

I'm new to Android programming, and I had this weird problem, I wanted to make phone numbers in a list clickable, where they send you the the dialer, now this worked on my Android phone, but it seems to only work on numbers of 10-chars, but when I tested it on a virtual device with 4.1.2, it worked well on all numbers in the list, I later tried a 4.4.2 virtual device, and I had the same problem there.
From what I could find on Google, I think the problem starts from Jelly Bean, so, is there a solution to this?
I used this in the TextView element in the layout XML fileL
android:autoLink="phone"

Was facing the same issue, for all the numbers longer than 10digits, solution is to just format them correctly and instead of 00 add a + sign infront of them, like: if number 00447172737475 , autolink wont work, but for +447172737475 it will work , hope it helps

In my case I wanted any numbers work as phone autolink, and for me worked only this:
private void setAutoLinkForPhoneWorkaround(TextView textView, final String phoneText) {
textView.setText(phoneText);
textView.setPaintFlags(phoneText.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + phoneText));
startActivity(intent);
}
});
}

Related

Autolink property for TextView is not working in Android?

I am using below code for opening dial up when clicking on TextView. The problem is it is not working on samsung tablet 10 inch device. It is opening a dialogue box with options 'saving contact' and 'close' rather than opening dial up. I have tested using the same code on Lenovo 7 inch(using api level 19) and Motorolla droid turbo (using api level 22) it is working fine but samsung 10 inch tablet (using api level 21) it is showing dialogue with mentioned options.Am I missing something or this is api specific behavior? Below is the code.
<TextView
android:layout_marginLeft="10dp"
android:textColor="#color/white_color"
android:layout_marginTop="10dp"
android:id="#+id/tv_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:textColorLink="#color/white_color"
android:layout_below="#+id/tv_address"
android:text="PH: (800) 579-4875 (310) 534-1505" />
I am posting the answer. It may be helpful for others. The problem was not in the code or in xml. The problem was with the tablet hardware. My device does not have calling feature that means I don't have sim card slot in my tablet that's why I was not getting dial up screen.
You can setup click event handler to start dial. It must work for different firmware.
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + "phone number here"));
startActivity(intent);
}
});
Try this
TextView phone = (TextView) layout.findViewById(R.id.idPhone);
phone.setAutoLinkMask(Linkify.PHONE_NUMBERS);

InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS in Samsung

In my app, I have an EditText, with a button to change the keyboard input type. The code:
ToggleCambiarTeclado.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if (ToggleCambiarTeclado.isChecked()) {
tipoDeTecladoActual = InputType.TYPE_CLASS_NUMBER;
imagenTeclado.setImageDrawable(getResources().getDrawable(R.drawable.keyboard_numeric));
} else {
tipoDeTecladoActual = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
imagenTeclado.setImageDrawable(getResources().getDrawable(R.drawable.keyboard_querty));
}
editNumeroContador.setInputType(tipoDeTecladoActual);
}
});
It works perfectly in my phone...but my boss has a Samsung, and is not changing the keyboard type in his phone.
I have tried changing it to TYPE_TEXT_VARIATION_NORMAL, TYPE_TEXT_VARIATION_VISIBLE_PASSWORD and YPE_CLASS_TEXT, neither of them are working.
Anyone knows if this is a bug? Any known workaround?
Thank you.
EDIT:
Just realized my boss has TouchPal installed. If he changes the default keyboard to the standard it works perfectly...
Later Samsung devices have SwiftKey keyboards built in. SwiftKey intentionally decided at some point to ignore Android's InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS.
A workaround is to use InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, which is somewhat hacky, but an unfortunately common workaround.
XML variant: android:inputType="textVisiblePassword"
Samsung's behave weirdly with most things. I've had this issue before and I seem to recall that changing the input type to email worked like a charm. Give it a try.

how to clear a text edit field? android python appium

how to clear text edit field? android python appium?
I tried that way:
el = driver.find_element_by_id('text edit field id').clear()
el.click()
el.clear()
however, it actually deletes only one symbol.
I think may by call an el.click() twice and send keycode to delete highlighted text area but how to highlight the text?
Interestingly, such problem reproduces in Sony Xperia z3 compact, android 5.0.1.
In lg, nexus android 4.4,5.1 accordingly, the above code works well
i had faced same issue with my android application but i am doing automation in java , so for the solution i am performing tap Action twice near the location of the element so it will select all the text which already written in text field and after that click on that "cut" symbol so it will clear text field.
i have written a method for sendkeys in android device.
public void typeForAndroid(AppiumDriver appiumDriver,WebElement ele,String text)
{
if(ele.getText().isEmpty())
{
ele.sendKeys(text);
}
else
{
TouchAction action=new TouchAction(appiumDriver);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
appiumDriver.performTouchAction(action);
pause(2);
try{
appiumDriver.findElementById("android:id/cut").click();
}
catch(Exception e)
{
appiumDriver.sendKeyEvent(67);
}
pause(2);
ele.sendKeys(text);
}
}
this is working for me. I hope this might works for you.
in this i have used appiumdriver but you can also use androiddriver.
Thanks

Espresso - typeText not working

I'm trying to type some text inside an EditText:
public void testSearch() {
onView(withId(R.id.titleInput)).perform(typeText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
I see the EditText is getting focus, but nothing happens. No text is typed.
I tried this on a phone and an emulator - same result.
Looks like I figured out the issue. It had to do with hardware vs software keyboard.
For Emulators:
Go to Settings -> Language & Input -> switch the Default Input to Sample Soft Keyboard.
For Phones:
Install a software keyboard from the Play store and switch to it. It appears that the native keyboards of some phones do not work.
It works now.
Had the same issue using Espresso 2. As a workaround I'm using replaceText instead of typeText.
public void testSearch() {
onView(withId(R.id.titleInput)).perform(click(), replaceText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
If the EditText does not has the focus yet, you should click on it first. If this solves your problem, then there is no bug.
onView(withId(R.id.titleInput)).perform(click()).perform(typeText("Engineer"));
You can bypass the problem by calling setText on the EditText.
final EditText titleInput = (EditText) activity.findViewById(R.id.titleInput);
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
titleInput.setText("Engineer");
}
});
Same issue resolved with the following:
editText.perform(scrollTo(), click(), clearText(), typeText(myInput), closeSoftKeyboard())
Interestingly, I only ever had a problem when my machine was working hard.
You can include it with in the code like this,
onView(withId(R.id.titleInput))
.perform(click(), replaceText("Engineer"), closeSoftKeyboard());
I fixed this issue by setting layout_height="wrap_content" on the View I wanted to click(). Maybe it can help someone here.
If you're using Genymotion, you may need to switch the default keyboard in Genymotion Configuration (it's an app on the emulator).
Go to Apps -> Genymotion Configuration -> Keyboard -> Virtual keyboard (click "Yes" when you're prompted to reboot)
NOTE: These changes do not persist after you close the emulator. You will need to set this every time you start the emulator.
for me I was annotated my test method with #UiThreadTest. I removed that and it solved.
Adding closeSoftKeyboard() after typeText() worked for me.
CODE:
onView(withId(R.id.editTextUserInput))
.perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
This is how it is documented in the Android docs.

Selecting text on TextView (android 2.2)

How to implement selecting text capability on Android 2.2? I searched Google but can't find a solution.
This is the only way I've found (from google) to support it for android 1.6+, it works but it's not ideal, I think in stock android you can't hold down a webview to highlight until v2.3, but I may be mistaken..
By the way this is for a webview, it might also work on textview, but I haven't tried it
(Note: this is currently what my shipped app is using, so it works with all the phones I've had it tested on, but the only reason I found this question was because I was searching and hoping that someone had come up with a better way by now)
I've just got a menu item called "Select text" which calls the function "selectnCopy()"
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//..
switch (item.getItemId()) {
case R.id.menu_select:
selectnCopy();
return true;
//..
}
}
Which looks like this:
public void selectnCopy() {
Toast.makeText(WebClass.this,getString(R.string.select_help),Toast.LENGTH_SHORT).show();
try {
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(wv);
} catch (Exception e) {
throw new AssertionError(e);
}
}
Notice I've put the select_help string there as a toast, that's just because it's not immediately clear to the user how it's supposed to work
<string name="select_help">Touch and drag to copy text.</string>
The Link #Stefan Hållén provided only worked after API Level 11.
And Android 2.2 is API Lv.8, that's the reason why you cannot get a resource identifier.
Have you set the text to be selectable? like this:
android:textIsSelectable="false" //OR true
See the Documentation for further reference.
After a long and time consuming search, I can't find a component that can select text in textview for android API level <=11. I have written this component that may be of help to you :
new Selectable TextView in android 3 (API <=11) component
An interesting workaround:
You could try displaying your text in a webview.
You just have to write the HTML tags and all of that into your string to display, and it should be selectable using the WebKit browser.
This should be fairly lightweight and transparent to the user, and I think it would solve your problem.
Let me know if you need a code example, it should be fairly simple. Just check out the WebView docs on http://developer.android.com/resources/tutorials/views/hello-webview.html
Best of luck!

Categories

Resources