WebView findall doesen't work with android api 15 - android

I'm using the following code to find and highlight text in a webView:
int API = android.os.Build.VERSION.SDK_INT;
if(API < 16) {
wv.findAll(findBox.getText().toString());
} else {
wv.findAllAsync(findBox.getText().toString());
}
However, it fails on api 15 only. It finds the word but doesen't highlight it. Do you have a solution?

This is a known problem without a solution that I know of. This occurs on the following:
Platform Version API Level VERSION_CODE
Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1
This problem is discussed: Here and Here.

Related

Comparing resources in API 21 x API 23

My app is running well in API 23 and above, but there seems to be a bug in it when I run it in API 21. I've narrowed it down to this piece of code:
if (myButton.getBackground().getConstantState() == ResourcesCompat.getDrawable(getResources(), R.drawable.myDrawable, null).getConstantState())
{...}
In API 21 it always returns false (even when it shouldn't), so I guess one of those methods doesn't work in API 21.
Any ideas? Is there any other way (compatible with API 21 and above) to check if a button's background has a specific drawable assigned to it?
ps: my minsdk is 21, but Lint is not giving me any warnings.
You can try using ContextCompat:
ContextCompat.getDrawable(yourContext, R.drawable.myDrawable).getConstantState();

Android - setLayoutDirection in API 15 and API 16

Does anyone know if ViewCompat.setLayoutDirection works in API level below 17?
I search for a solution all over the internet but I can't find a solid one.
setLayoutDirection was added to in API Level 17 (read here) which is 4.2 so the older versions do not support that. So keep two layouts for higher and below and you need to work around for the below api level XML view.
If you're using the support library, you can do the following:
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL) {
// view -RTL layout
} else {
//view - set made layout for below apis
}
BidiFormatter might help you depending on your requirement.Check that as well.
Every one knows about android:layout_gravity="end" right? can be helpfull in this case

search text within a webView doesn't work

I'm using this code to search words within in a textView.
The buttons and the EditText are displayed but they don't work.
In the code there is a warning that says
The method findAll(String) from the type WebView is deprecated
for the line
wv.findAll(findBox.getText().toString());
The rest of the code is in this link.
Use
wv.findAll(findBox.getText().toString());
for API versions < 16 and Use
wv.findAllAsync(findBox.getText().toString());
for API versions > 16.
Use the following code to ensure that your code works on all versions:
int API = android.os.Build.VERSION.SDK_INT;
if(API < 16) {
wv.findAll(findBox.getText().toString());
} else {
wv.findAllAsync(findBox.getText().toString());
}

Android Webview : detecting when page has rendered

I am writing a highbred Android app that uses a lot of webviews. The problem is that the onPageFinished event for a webview is fired when a page is loaded but may not be rendered yet.
I believe there was a onNewPicture but has been removed since version 12.
Has anyone come across the same issue, my spinner basically disappears about 3-4 seconds before the page is actually rendered.
Rendering of a WebView can take a long time for long documents, and indeed onNewPicture has been deprecated since API 12 (Honeycomb 3.1) and returns a null picture since API level 18 (Jellybean 4.3).
I have tested for API level 17 (JB 4.2), and it still works fine. Probably works fine in API 18 too if you don't need the actual Picture details.
Please this issue on the issue tracker so we can get a non-deprecated replacement.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
PictureListener pictureListener = new PictureListener() {
#Override
#Deprecated
public void onNewPicture(WebView view, Picture picture) {
Log.i(TAG, "Picture changed!");
}
};
webView.setPictureListener(pictureListener);
}

API Level error

In an Activity I have a code that shows this error, but only if you press save.
Call requires API level 11 (current min is 8): android.widget.SearchView#setSearchableInfo
If I change the android:minSdkVersion to 7, it works, but when I save the code again, the same error is thrown. The minSdk must then be changed back to 8,...
What is wrong?
SearchView is available since API lvl 11.
Since your minimum sdk is 8 (lower than 11), Lint will give an error when using SearchView.
You can remove that error by using #TargetApi annotation before your method or class.
But you have to make sure you use a conditional statement before using SearchView to check if it is available, and provide an alternative for earlier versions.
Here's what your code should look like:
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
void yourMethod(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
// use SearchView
} else {
// use some other backward compatible custom view
}
}
The SearchView exists in Android from the version 11 ant more.
So, if you would like to use the SearchView in your code, you have to put the minSdkVersion in your manifest to be 11. In the case you put a number smaller than 11, you will get an error, which is normal beause you are giving access to your app to some android versions which will not support your app.
This can be seen (thanks to #JesseJ) here: http://developer.android.com/reference/android/widget/SearchView.html
Added in API level 11

Categories

Resources