Example usage for android.content Context getApplicationInfo

List of usage examples for android.content Context getApplicationInfo

Introduction

In this page you can find the example usage for android.content Context getApplicationInfo.

Prototype

public abstract ApplicationInfo getApplicationInfo();

Source Link

Document

Return the full application info for this context's package.

Usage

From source file:Main.java

/**
 * @param ctx The Android application context.
 * @return Application name//  w  w w  .  j  av  a2s.c  om
 */
public static String getAppName(Context ctx) {
    PackageManager packageManager = ctx.getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {
        applicationInfo = packageManager.getApplicationInfo(ctx.getApplicationInfo().packageName, 0);
    } catch (final NameNotFoundException ignored) {
    }
    return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {// w  w w  .j ava2s.c  o  m
        applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0);
    } catch (final PackageManager.NameNotFoundException e) {
    }

    return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
}

From source file:de.handtwerk.android.IoHelper.java

public static File getExternalAppStoragePath(String pPath, Context pContext) {

    String path = "/Android/data/" + pContext.getApplicationInfo().packageName + "/files/" + pPath;
    return new File(Environment.getExternalStorageDirectory(), path);
}

From source file:Main.java

/**
 * Check if the database exist// w  w w  . j a v  a 2  s.  c  o  m
 *
 * @return true if it exists, false if it doesn't
 */
public static boolean checkDataBase(Context context) {
    SQLiteDatabase checkDB = null;
    int count = 0;
    try {
        if (android.os.Build.VERSION.SDK_INT >= 17) {
            DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
        } else {
            DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
        }
        checkDB = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);

        String selectRegistros = "SELECT COUNT(*) FROM Grupo_Gastos";

        Cursor mCursor = checkDB.query(true, "Grupo_Gastos", new String[] { "_id" }, null, null, null, null,
                null, null);
        count = mCursor.getCount();

        checkDB.close();
    } catch (SQLiteException e) {
        // database doesn't exist yet.
        return false;
    }
    return count > 0;
}

From source file:com.lokesh.FCMNotification.plugin.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*  www  .j  a va 2 s.  c om*/

private static String getAppName(Context context) {
    return (String) context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
}

From source file:nl.frankkie.bronylivewallpaper.CLog.java

public static boolean checkDebuggable(Context c) {
    return (0 != (c.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
}

From source file:Main.java

public static String createDirInHome(Context context, final String subDir)
        throws IOException, InterruptedException {
    File tmpFile = checkAndCreateDir(context.getApplicationInfo().dataDir + File.separator + subDir);
    return tmpFile.getAbsolutePath();
}

From source file:Main.java

/** Check if the app can be debugged or not */
public static boolean isDebugable(Context context) {
    if (isDebuggable == null) {
        if (context == null) {
            throw new NullPointerException("Context should not be null the first time.");
        }//from w w  w .  j ava 2 s. c o m
        isDebuggable = (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
    }
    return isDebuggable;
}

From source file:io.lqd.sdk.model.LQDevice.java

private static String getAppName(Context context) {
    int stringId = context.getApplicationInfo().labelRes;
    return context.getString(stringId);
}

From source file:Main.java

public static void notify(Context context, String msg, String title, Class<?> toClz, int notifyId) {
    PendingIntent pend = PendingIntent.getActivity(context, 0, new Intent(context, toClz), 0);
    Notification.Builder builder = new Notification.Builder(context);
    int icon = context.getApplicationInfo().icon;
    builder.setContentIntent(pend).setSmallIcon(icon).setWhen(System.currentTimeMillis()).setTicker(msg)
            .setContentTitle(title).setContentText(msg).setAutoCancel(true);

    NotificationManager man = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    man.notify(notifyId, builder.getNotification());
}