List of usage examples for android.text TextUtils equals
public static boolean equals(CharSequence a, CharSequence b)
From source file:Main.java
public static Account findGoogleAccount(Context context, String name) { AccountManager am = AccountManager.get(context); for (final Account a : am.getAccountsByType(GOOGLE_TYPE)) { if (TextUtils.equals(a.name, name)) return a; }/*from ww w .ja va2 s . co m*/ return null; }
From source file:Main.java
public static boolean isQqInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.tencent.mobileqq")) { return true; }/*from w ww. j av a 2 s .c om*/ } } return false; }
From source file:Main.java
public static boolean isBackGround() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses(); for (RunningAppProcessInfo info : processInfos) { if (TextUtils.equals(info.processName, mContext.getPackageName()) && info.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { return true; }/* ww w.j a v a 2 s. c o m*/ } return false; }
From source file:Main.java
public static boolean isWeiboInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.sina.weibo")) { return true; }// w w w .j a va2 s. c o m } } return false; }
From source file:Main.java
public static boolean isWechatInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.tencent.mm")) { return true; }//from w w w. j a v a 2 s. c om } } return false; }
From source file:Main.java
public static String getRunningActivityName(Context context, String packageName) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> processInfos = activityManager.getRunningTasks(10); for (ActivityManager.RunningTaskInfo taskInfo : processInfos) { if (taskInfo.topActivity != null) { if (TextUtils.equals(packageName, taskInfo.topActivity.getPackageName())) { return taskInfo.topActivity.getClassName(); }/*from w w w . ja va 2 s. c om*/ } } return null; }
From source file:Main.java
public static File createTmpFile(Context context) throws IOException { File dir = null;/* w w w . j a v a2 s.c om*/ if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) { dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); if (!dir.exists()) { dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM + "/Camera"); if (!dir.exists()) { dir = getCacheDirectory(context, true); } } } else { dir = getCacheDirectory(context, true); } return File.createTempFile(JPEG_FILE_PREFIX, JPEG_FILE_SUFFIX, dir); }
From source file:Main.java
public static String getFormatDateFromAmazon(String amazonDate) { String month = null;/*from ww w. j ava 2 s . co m*/ String date = null; String year = null; if (TextUtils.isEmpty(amazonDate)) return ""; String[] format_1 = amazonDate.split(","); String[] month_date = format_1[0].split(" "); month = month_date[0]; date = month_date[1]; if (format_1[1].startsWith(" ")) { format_1[1] = format_1[1].substring(1, format_1[1].length()); } String[] year_plus = format_1[1].split(" "); year = year_plus[0]; if (TextUtils.equals(month, "Jan")) month = "1"; else if (TextUtils.equals(month, "Feb")) month = "2"; else if (TextUtils.equals(month, "Mar")) month = "3"; else if (TextUtils.equals(month, "Apr")) month = "4"; else if (TextUtils.equals(month, "May")) month = "5"; else if (TextUtils.equals(month, "Jun")) month = "6"; else if (TextUtils.equals(month, "Jul")) month = "7"; else if (TextUtils.equals(month, "Aug")) month = "8"; else if (TextUtils.equals(month, "Sep")) month = "9"; else if (TextUtils.equals(month, "Oct")) month = "10"; else if (TextUtils.equals(month, "Nov")) month = "11"; else if (TextUtils.equals(month, "Dev")) month = "12"; return month + "/" + date + "/" + year; }
From source file:Main.java
public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager .getRunningServices(Integer.MAX_VALUE); if (serviceList == null || serviceList.isEmpty()) return false; for (int i = 0; i < serviceList.size(); i++) { if (serviceList.get(i).service.getClassName().equals(className) && TextUtils.equals(serviceList.get(i).service.getPackageName(), context.getPackageName())) { isRunning = true;//from w w w . j a v a2 s . c om break; } } return isRunning; }
From source file:Main.java
public static void hasPermission() { if (mContext == null) throw new NullPointerException("you must initialize in appliction to use: CCCoreUtil.init"); PackageManager pm = mContext.getPackageManager(); PackageInfo pInfo = null;/* ww w . j a v a 2 s.c o m*/ try { pInfo = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_PERMISSIONS); String[] permissions = pInfo.requestedPermissions; for (String permission : permissions) { if (TextUtils.equals(mContext.getPackageName() + ".permission." + "WANG_CC_CONG", permission)) return; } } catch (Exception e) { // TODO: handle exception System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); } System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKAGENAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); }