Tag Archive for 'android'

Android Service SecurityException when starting

Start service always this way:

context.startService(new Intent(MusicService.ACTION_PAUSE, null, context, MusicService.class));

Android unmarshalling from Parcel

When unmarshalling from a byte array into a Parcel object, be sure to reset (setDataPosition(0)) it before reading out any object.

Example:

Parcel p = Parcel.obtain();
p.unmarshall(buff, 0, length);
p.setDataPosition(0);
return p.readBundle();

Android zoomable-pannable ImageView

PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView.
Features

  • Out of the box zooming, using multi-touch and double-tap.
  • Scrolling, with smooth scrolling fling.
  • Works perfectly when using used in a scrolling parent (such as ViewPager).
  • Allows the application to be notified when the displayed Matrix has changed. Useful for when you need to update your UI based on the current zoom/scroll position.
  • Allows the application to be notified when the user taps on the Photo.
  • PhotoView GitHub site

    Disabling Certificate Validation in an HTTPS Connection

    By default, accessing an HTTPS URL using the URL class results in an exception if the server’s certificate chain cannot be validated has not previously been installed in the truststore. If you want to disable the validation of certificates for testing purposes, you need to override the default trust manager with one that trusts all certificates.

    Great tutorial and sample code here!

    Android Fragments

    A very great and simple tutorial about fragments, check it out here.

    Disable Android 2.3 View overscrolling on prior versions

    Update Developers reported, that this does not work/misbehaves on several devices, so should be avoided.

    Android Gingerbread enables by default overscrolling in default orange style, which could be disturbing in many layouts.
    To disable it you can use the setOverScrollMode method with the OVER_SCROLL_NEVER parameter, however it is not available on prior Android versions.
    Here is a safe solution for all Android versions:

    public static void disableOverscroll(View view) {
    Class viewCls = view.getClass();
    try {
    Method m = viewCls.getMethod("setOverScrollMode",
    new Class[] { int.class });
    int OVER_SCROLL_NEVER = (Integer) viewCls.getField(
    "OVER_SCROLL_NEVER").get(view);
    m.invoke(view, OVER_SCROLL_NEVER);
    } catch (Exception e) {
    // swallow
    }
    }

    By alex on Stackoverflow.com

    Display only mail apps when calling ACTION_SEND intent

    Maybe you have already noticed, that if you invoke the mail sender intent on Android, it may display a lot of installed apps, which can handle text/plain MIME-types, that may confuse the user.
    To display only mail-capable apps, use message/rfc822 as the parameter of setType method.

    Via Stackoverflow.com

    Android Toast-like HUD for iOS

    If you wish to easily report status of background processes to the user, on Android you may use Toast class, however iOS lacks of this great feature. But there is a great library, that provides even more features than Android version: MBProgressHUD.

    Android 3.x Action Bar customization

    The ActionBar UI component has been introduced in Android 3.0 and above, and it seems to become the standard way to use tabs and context/action menus in Android applications.
    You may also customize the ActionBar associated to your application in different ways through this great tutorial, however you might run into errors when you wish to override Tab item styles, to resolve this issue,
    check this blog for a very straightforward solution. (due to private API issues)

    Android push messaging – C2DM

    From Android 2.2 and above, push messaging is supported like on Apple iPhone through the C2DM service. The official developer site and blog features a good client example, but this article features a complete guide with server side PHP examples as well.