Показаны сообщения с ярлыком snippets. Показать все сообщения
Показаны сообщения с ярлыком snippets. Показать все сообщения

суббота, 6 апреля 2013 г.

Android snippet: Linkify your Text Views

Linkify is a helper class that creates hyperlinks within Text View class trough RegEx pattern matching.

The Linkify class has presets that can detect and linkify web URLs, emails addresses and phone numbers. To apply a preset, use the static Linkify.addLinks method, passing in a View to Linkify and a bitmask of one of the following self-describing Linkify class constants: WEB_URLS, EMAIL_ADDRESSES, PHONE_NUMBERS and ALL.

TextView textView = (TextView) findViewById(R.id.myTextView);

Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES);


You can also linkify Views directly within a layout using the android:autoLink attribute. It supports one or more of the following values: none, web, email, phone, all.

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="@string/linkify_me"

android:autolink="phone | email"

/>


четверг, 22 сентября 2011 г.

Android snippet: Check if the device is connected to the internet

Just a quick function to make your live easier
How to check if the device that runs your application has an active internet connection
Here is the function:
public static boolean isOnline(Context context) {
     ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo netInfo = cm.getActiveNetworkInfo();
     if (netInfo != null && netInfo.isAvailable() && netInfo.isConnected()) {
         return true;
     }
     return false;
}
Also You must add the INTERNET and ACCESS_NETWORK_STATE permissions to Your application
<uses-permission android:name="android.permission.INTERNET"  />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />