Sunday, December 23, 2012

Hide Soft Keyboard Android

InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);



Some other methods:

http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard

Tuesday, November 27, 2012

View Switcher layout_height="wrap_content" dosen't work

http://stackoverflow.com/questions/5466537/how-to-get-viewswitcher-to-wrap-only-the-currently-displayed-view-height

 

Solution:

 

android:measureAllChildren="false"

Monday, October 22, 2012

Check weather application sent to background or not

[java]

public static boolean isApplicationSentToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}

return false;
}

[/java]

Sunday, October 21, 2012

How to prevent a scrollview from scrolling to a webview after data is loaded?

You should create new class extend ScrollView, then Override requestChildFocus:

 
public class MyScrollView extends ScrollView {

@Override
public void requestChildFocus(View child, View focused) {
    if (focused instanceof WebView )
       return;
    super.requestChildFocus(child, focused);
}
}

Then in your xml layout, using:
<MyScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background" >

The ScrollView will not auto scroll to the WebView anymore.

 

Solution taken from :

http://stackoverflow.com/questions/9842494/how-to-prevent-a-scrollview-from-scrolling-to-a-webview-after-data-is-loaded

 

webview showing white bar on right side

Use the following to hide but not remove the functionality of the scrollbar. The layout margin adjustment is a nasty work-around.

//webview being your WebView object reference.

webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

 

Solution from:

http://stackoverflow.com/questions/2279978/webview-showing-white-bar-on-right-side

Wednesday, August 15, 2012

Friday, June 15, 2012

Twitter Android Integration

Good tutorial to integrate twitter with android..

http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application

 

 

 


Tuesday, June 12, 2012

How to build mupdf android library

MuPDF Android Library Build

Today I was able to successfully build MuPDF library on Windows 7 platform using Cygwin. I'll explain each and every step here.

1. Android SDK should be installed.

2. Android NDK should be installed

Just download android NDK here http://developer.android.com/sdk/ndk/index.html and extract it to a directory with no spaces in the name.

3. You need to install Cygwin latest version. download the setup.exe from http://cygwin.com/install.html and follow instructions here. do not skip a single step. Instructions :  http://vmerror.com/?p=133

4. Download MuPDF source zip file and third-party zip file here http://code.google.com/p/mupdf/downloads/list

5. Extract your mupdf source folder somewhere in your hard disk (path must not contain any spaces)

6. Create a folder named 'thirdparty' in the mupdf source folder you have extracted. It should be in the same level of 'android', 'apps', 'fitz', 'win32' etc. and extract downloaded thirdparty zip file directly under created folder.

7. You need to have Visual studio installed. if not you can download trial version here : http://www.microsoft.com/en-us/download/details.aspx?id=12752

Download and install it properly.

8. Go to mupdf source folder, open win32 folder and double click generated.vcproj

then it will open with visual studio.

9. In visual studio just run the c++ application. no need to have any visual studio or c++ knowledge. just press green arrow button (run button)

10. If everything goes ok, it should create a folder inside mupdf source. the folder name is 'generated' and it should contain some header files (.h files)

11. Open Cygwin console,(just double click cygwin installation short-cut) and type following command and enter.

 

cd /cygdrive/<path to mupdf sorce folder/android

ex. cd /cygdrive/c/mupdf-1.0-source/android

then

/cygdrive/<path to ndk installation>/ndk-build

ex. /cygdrive/c/ndk/ndk-build

 

Cheerz... thats all. now you have built your mupdf library and what you can do is, create an Android application using mupdf android source (inside android folder) run it and see...

you can create a library project and include it anywhere you need.

 

Install Cygwin to develop android NDK application

When you develop android native applications you need to have Unix tools. Cygwin emulates Unix environment on Windows. here I'm explaining how to install Cygwin step by step.

  • Download setup.exe from here : http://cygwin.com/install.html and execute it

  • Choose install from internet

  • When you specify installation location be sure to choose a directory path that contains no spaces in it

  • Choose a mirror site close to you

  • After you choose the mirror and click Next, Cygwin will download and present to you the list of available packages:

  • I suggest that we install the entire Devel branch. Click (once) on the word “Default” next to the root Devel node and wait few seconds while the setup hangs. When it is back, you will see that “Default” changes to “Install” for the Devel node. Then press next.

  • This might take long, may be half an hour or may be 1 - 3 hours depends on your internet connection. let it to be installed and create a short-cut on the desktop.


 

For detailed steps with screen shots please see step 2 in post below:

http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

 

 

 

 

Monday, May 7, 2012

Solution: Android INSTALL_FAILED_INSUFFICIENT_STORAGE error Android Imulator

You need to increase the Android emulator's memory capacity, there are 2 ways for that:

1- Right click the root of your Android Project, go to "Run As" then go to "Run Configurations..." locate the "Android Application" node in the tree at the left, then select your project and go to the "Target" tab on the right side of the window look down for the "Additional Emulator Command Line Options" field (sometimes you'll need to make the window larger) and finally paste "-partition-size 1024" there. Click Apply and then Run to use your emulator.

2- Go to Eclipse's Preferences, then Select “Launch” Add “-partition-size 1024” on the “Default emulator option” field, then click “Apply” and use your emulator as usual.

 

Source : http://stackoverflow.com/questions/4709137/solution-android-install-failed-insufficient-storage-error

Tuesday, May 1, 2012

Pending Intent Extras Problem

http://stackoverflow.com/questions/4689029/send-extra-data-via-pendingintent-problem

Friday, April 20, 2012

ProGuard Issue when you try to sign apk

http://stackoverflow.com/questions/2680827/conversion-to-dalvik-format-failed-with-error-1-on-external-jar

 

Windows 7 Solution:

Confirmed the problem is caused by ProGuard command line in the file
[Android SDK Installation Directory]toolsproguardbinproguard.bat

Edit the following line will solve the problem:
call %java_exe% -jar "%PROGUARD_HOME%"libproguard.jar %*

to
call %java_exe% -jar "%PROGUARD_HOME%"libproguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9

Thursday, March 1, 2012

onConfigurationChanged is not being called

Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSiz e". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

(From http://developer.android.com/guide/topics/resources/runtime-changes.html)