Skip to main content

Posts

Showing posts from 2013

Get Android application version information programatically in android

Reading Android application version name and version code defined in the Manifest file programatically in android              /**      * Method to Fetch Application Name as Defined in Manifest File      * @returns String      */     public String getVersionName(){         String versionName = "";         try {                 versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;         } catch (Exception e) {             e.printStackTrace();         }         return versionName;     }         /**     ...

Supporting text size for all supporting devices for your Android Application

Add different dimens.xml files to support different font sizes for all supporting devices in your application.. First create different folders as below, Under res folder create folders as , res/values/dimens.xml(default) res/values-ldpi/dimens.xml (for ldpi devices) res/values-mdpi/dimens.xml res/values-hdpi/dimens.xml res/values-xhdpi/dimens.xml   res/values-xxhdpi/dimens.xml For Tablets , res/values-sw600dp/dimens.xml (600*1024) res/values-sw720dp-land/dimens.xml (800*1280) Now Update dimens.xml for defining font sizes dimens.xml file should have text size defined for all labels as below, eg. Default value of footer text size will be 18 sp,  <dimen name="text_size_footer">18sp</dimen> eg. For tablet -> res/values-sw600dp value of footer textsize will be 25 sp,  <dimen name="text_size_footer">25sp</dimen> Finally read it in a your layout, <TextView     android:id="@+id/lblFooter" ...

Bring Android application to forground

Intent launchApp = new Intent(context, Applications_MainActivity.class);                             launchApp.setAction(Intent.ACTION_MAIN);                             launchApp.addCategory(Intent.CATEGORY_LAUNCHER);                             launchApp.setFlags(IConstants.NOTIFICATION_FLAG);//Use this Special Flag                             context.getApplicationContext().startActivity(launchApp); Update below value in your Constants File,   public static final int NOTIFICATION_FLAG = 0x10200000;

IS MY SERVICE RUNNING? - DISPLAY ALL RUNNING SERVICES IN ANDROID

Compare your service name with class name of running services to find out your service is running or not. ActivityManager activityManager= (ActivityManager)getSystemService(ACTIVITY_SERVICE);         for (RunningServiceInfo service : activityManager.getRunningServices(Integer.MAX_VALUE)) {             Log.i("Service", "Process " + service.process + " with component " + service.service.getClassName());         }             

Code : Reading files from Assets folder

Reading File from Assets Folder AssetManager assetManager = getApplicationContext().getAssets();         InputStream is = assetManager .open("filename.txt");         BufferedReader reader = new BufferedReader(new InputStreamReader(is));         StringBuilder sb = new StringBuilder();         String line = null;         while ((line = reader.readLine()) != null) {           sb.append(line + "\n");         }         is.close();       String dataString = sb.toString();