I am trying to create a custom IME for Android, with custom emoticoons that are really just images showing on the keys.
Sending text from the keyboard to the focused text field is easy, by using the InputConnection in the KeyboardActionListener
InputConnection ic = getCurrentInputConnection();
ic.commitText(String.valueOf(code),1);
However sending images is quite challenging. I've seen the keyboard example suggested by many answer in SO (https://github.com/chiragjain/Emoticons-Keyboard) and a few other examples, and it always uses a method similar to this:
Spanned cs = Html.fromHtml("<img src ='"+ index +"'/>", imageGetter, null);
int cursorPosition = content.getSelectionStart();
content.getText().insert(cursorPosition, cs);
While this seems to work well if the focused text field is in part of the activity created by the programmer, it does not work with the OS text field (e.g. it adds an empty square instead of the image when trying to add the image to an EMail message I am writing).
I also tried other methods to send my custom image from the virtual keyboard when pressed. I tried using the clipboard to copy-paste the binary of the image and the link, but it did not work.
I tried sending an intent with the image after saving it to the media library. This works better, it lets the user choose the app to receive the image and when the app receives it, the image is properly displayed. However, it always creates a new message. For example, I am in the email app, open the custom keyboard and select an image. This launches the intent, which brings the chooser. I choose mail, and the image is added to a new message instead of the one I am currently editing.
I am now running out of ideas. Is it even possible to have custom emoticoones / images displayed on the virtual keyboard with a reliable way to send them to the OS applications?
Related
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.)
We are developing an android application for document scanner.
This application is having feature to edit the image like adding magic color, grey mode, Black white,etc. this application has the option to scan "N" number of pages and convert it into PDF at the end.
The flow of the application is First activity is taking photo of the image and the second activity for cropping the image and third activity for editing the image like applying magic color, grey mode and black/white conversion. And in the third activity we have add button,clicking on it will go back to first activty and the same process continues.Once all the images scanned, third activity is haivng done button, clicking on it will create pdf and close the application.
Now the problem is after scanning some 35 pages, it throws out of memory error because we are always keeping original and modified bitmaps as List in the code because its possible for the user to go back to previous images and edit it. At that time i need original version of the image also.
Could you please help me out on the below items.
1) where to keep the bitmaps in this scenario?
2) Is there any way to store the image in the external card and reading it everytime on need basis?
Thanks in advance.
Store the bitmap as cache.
out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
It is prefetable to use cache directory to store such a file rather than storing it persistently. getCacheDir() will return the path to the directory.
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 :)?
i am new with android and i try to create Epub reader.
i already read Epub Files in Android Webview and now i am taring create find functionality
i use this code for find any text in webview it works fine but wane i am go to next page
in my app stile my webview display find items .
code :
int i = webViewRead.findAll(text);
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webViewRead, true);
So, my problem is how to hide the result.
I already try to create new instants of my Webview( and Relode Webview Like webViewRead.reload(); ) but its not work for me.
is any anther way to do it.??
(my content witch i display in webview is xhtml pages).
And one More Thing with this method find text is highlighted with Green color
is their any way to display find text in Red color.
Why not use:
webViewRead.clearMatches();
?
Greg