Android examples for App:App Information
get App Platform
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; public class Main { public static int getAppPlatform(Context context) { String versionName = getAppVersionName(context); int platform = -1; if (versionName != null) { int end = versionName.indexOf('.'); if (end > -1) { platform = Integer.parseInt(versionName.substring(0, end)); }// www.j a v a2 s .c o m } return platform; } /** * Get android versionName in AndroidManifest.xml * * @param context * @return */ public static String getAppVersionName(Context context) { String appVersion; try { PackageInfo info = context.getPackageManager().getPackageInfo( context.getPackageName(), 0); appVersion = info.versionName; } catch (NameNotFoundException e) { appVersion = null; } return appVersion; } }