2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU AFFERO General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 You may obtain a copy of the License at
10 http://www.gnu.org/licenses/agpl-3.0.txt
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com.samsung.srpol.utils;
23 import com.samsung.srpol.R;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.content.SharedPreferences;
28 import android.content.pm.PackageManager.NameNotFoundException;
29 import android.graphics.drawable.Drawable;
30 import android.net.Uri;
31 import android.os.Build;
32 import android.provider.Settings;
36 private static final String SCHEME = "package";
38 private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
40 private static final String APP_PKG_NAME_22 = "pkg";
42 private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
44 private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
46 private static final String MY_PREFERENCES = "my_preferences";
48 private static Drawable mSystemIcon;
49 private static Drawable mSystemIconDisable;
52 * @return the mSystemIcon
54 public static Drawable getmSystemIcon(Context context) {
55 if (mSystemIcon == null) {
56 return mSystemIcon = context.getResources().getDrawable(
57 R.drawable.ic_system_red_dark);
64 * @return the mSystemIcon
66 public static Drawable getmSystemIconDisable(Context context) {
67 if (mSystemIconDisable == null) {
68 return mSystemIconDisable = context.getResources().getDrawable(
69 R.drawable.ic_system_red_disable);
71 return mSystemIconDisable;
76 * Show Platform's Settings app Window with details about given packageName
82 * Package name of requested app details
84 public static void showInstalledAppDetails(Context context,
86 Intent intent = new Intent();
87 final int apiLevel = Build.VERSION.SDK_INT;
88 if (apiLevel >= 9) { // above 2.3
89 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
90 Uri uri = Uri.fromParts(SCHEME, packageName, null);
94 final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
96 intent.setAction(Intent.ACTION_VIEW);
97 intent.setClassName(APP_DETAILS_PACKAGE_NAME,
98 APP_DETAILS_CLASS_NAME);
99 intent.putExtra(appPkgName, packageName);
101 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
102 context.startActivity(intent);
105 public static void unistallApp(Context context, String packageName) {
106 Intent intent = new Intent();
107 final int apiLevel = Build.VERSION.SDK_INT;
108 if (apiLevel >= 14) { // above 4.0
109 intent.setAction(Intent.ACTION_DELETE);
110 Uri uri = Uri.fromParts(SCHEME, packageName, null);
112 } else { // below 4.0
114 final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
116 intent.setAction(Intent.ACTION_VIEW);
117 intent.setClassName(APP_DETAILS_PACKAGE_NAME,
118 APP_DETAILS_CLASS_NAME);
119 intent.putExtra(appPkgName, packageName);
121 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
122 context.startActivity(intent);
125 public static String getAppVersionCode(Context context) {
128 versionName = context.getPackageManager().getPackageInfo(
129 context.getPackageName(), 0).versionName;
130 } catch (NameNotFoundException e) {
131 versionName = "not found";
137 public static boolean isFirstRun(Context context) {
138 final SharedPreferences reader = context.getSharedPreferences(
139 MY_PREFERENCES, Context.MODE_PRIVATE);
140 final boolean first = reader.getBoolean("is_first", true);
142 final SharedPreferences.Editor editor = reader.edit();
143 editor.putBoolean("is_first", false);
149 public static void startBrowser(Context context, String url) {
150 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
151 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
152 context.startActivity(intent);