switch to alsa.omap3 module
[android_pandora.git] / apps / oi-filemanager / FileManager / src / org / openintents / util / VersionUtils.java
CommitLineData
27a4fda1 1/* \r
2 * Copyright (C) 2007-2009 OpenIntents.org\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 * http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16\r
17package org.openintents.util;\r
18\r
19import android.content.Context;\r
20import android.content.pm.PackageInfo;\r
21import android.content.pm.PackageManager;\r
22import android.content.pm.PackageManager.NameNotFoundException;\r
23import android.os.Build;\r
24import android.util.Log;\r
25\r
26/**\r
27 * \r
28 * @version 2011-01-22\r
29 * @author Peli\r
30 *\r
31 */\r
32public class VersionUtils {\r
33 \r
34 private static final String TAG = "VersionUtils";\r
35\r
36 /**\r
37 * Get current version code.\r
38 * \r
39 * @return\r
40 */\r
41 public static int getVersionCode(Context context) {\r
42 int version = 0;\r
43 try {\r
44 PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);\r
45 version = pi.versionCode;\r
46 } catch (PackageManager.NameNotFoundException e) {\r
47 Log.e(TAG, "Package name not found", e);\r
48 };\r
49 return version;\r
50 }\r
51 \r
52 /**\r
53 * Get current version number.\r
54 * \r
55 * @return\r
56 */\r
57 public static String getVersionNumber(Context context) {\r
58 String version = "?";\r
59 try {\r
60 PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);\r
61 version = pi.versionName;\r
62 } catch (PackageManager.NameNotFoundException e) {\r
63 Log.e(TAG, "Package name not found", e);\r
64 };\r
65 return version;\r
66 }\r
67 \r
68 /**\r
69 * Get application name.\r
70 * \r
71 * Since API level 4 this routine could be replaced by\r
72 * appname = getString(getApplicationInfo().labelRes);\r
73 * \r
74 * @return\r
75 */\r
76 public static String getApplicationName(Context context) {\r
77 String name = "?";\r
78 try {\r
79 PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);\r
80 name = context.getString(pi.applicationInfo.labelRes);\r
81 } catch (PackageManager.NameNotFoundException e) {\r
82 Log.e(TAG, "Package name not found", e);\r
83 };\r
84 return name;\r
85 }\r
86\r
87 /**\r
88 * Get application icon.\r
89 * \r
90 * Since API level 4 this routine could be replaced by\r
91 * icon = getApplicationInfo().icon;\r
92 * \r
93 * @return\r
94 */\r
95 public static int getApplicationIcon(Context context) {\r
96 int icon = 0;\r
97 try {\r
98 PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);\r
99 icon = pi.applicationInfo.icon;\r
100 } catch (PackageManager.NameNotFoundException e) {\r
101 Log.e(TAG, "Package name not found", e);\r
102 };\r
103 return icon;\r
104 }\r
105\r
106 /**\r
107 * Indicates whether a specific package with minimum version code is available.\r
108 */\r
109 public static boolean isPackageAvailable(final Context context, final String packageName,\r
110 final int minVersionCode) {\r
111 boolean result = false;\r
112 try {\r
113 PackageInfo pi = context.getPackageManager().getPackageInfo(\r
114 packageName, 0);\r
115 if (pi.versionCode >= minVersionCode) {\r
116 result = true;\r
117 }\r
118 } catch (PackageManager.NameNotFoundException e) {\r
119 \r
120 }\r
121 return result;\r
122 }\r
123}\r