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:com.pdftron.pdf.utils.Utils.java

public static String decryptIt(Context context, String value) {
    String cryptoPass = context.getString(context.getApplicationInfo().labelRes);
    try {/*from w  ww .j av  a  2  s .  c  o m*/
        DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey key = keyFactory.generateSecret(keySpec);

        byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
        // cipher is not thread safe
        Cipher cipher = Cipher.getInstance("DES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));

        String decrypedValue = new String(decrypedValueBytes);
        Log.d("MiscUtils", "Decrypted: " + value + " -> " + decrypedValue);
        return decrypedValue;

    } catch (Exception e) {
        Log.e(e.getClass().getName(), e.getMessage());
    }
    return value;
}

From source file:io.github.carlorodriguez.alarmon.AppSettings.java

public static boolean isDebugMode(Context c) {
    final String[] values = c.getResources().getStringArray(R.array.debug_values);
    final String DEBUG_DEFAULT = values[0];
    final String DEBUG_ON = values[1];
    final String DEBUG_OFF = values[2];

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    final String value = prefs.getString(DEBUG_MODE, DEBUG_DEFAULT);
    if (value.equals(DEBUG_ON)) {
        return true;
    } else if (value.equals(DEBUG_OFF)) {
        return false;
    } else if (value.equals(DEBUG_DEFAULT)) {
        return (c.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0;
    } else {/*from   ww  w .j a  v a  2s  .  com*/
        throw new IllegalStateException("Unknown debug mode setting: " + value);
    }
}

From source file:io.teak.sdk.Teak.java

/**
 * Initialize Teak and tell it to listen to the lifecycle events of {@link Activity}.
 * <p/>/*from  w  w w.j  a  va  2s. c  o  m*/
 * <p>Call this function from the {@link Activity#onCreate} function of your <code>Activity</code>
 * <b>before</b> the call to <code>super.onCreate()</code></p>
 *
 * @param activity The main <code>Activity</code> of your app.
 */
public static void onCreate(Activity activity) {
    Log.d(LOG_TAG, "Android SDK Version: " + Teak.SDKVersion);

    if (activity == null) {
        Log.e(LOG_TAG, "null Activity passed to onCreate, Teak is disabled.");
        Teak.setState(State.Disabled);
        return;
    }

    {
        String airSdkVersion = Helpers.getStringResourceByName("io_teak_air_sdk_version",
                activity.getApplicationContext());
        if (airSdkVersion != null) {
            Log.d(LOG_TAG, "Adobe AIR SDK Version: " + airSdkVersion);
        }
    }

    // Set up debug logging ASAP
    try {
        final Context context = activity.getApplicationContext();
        final ApplicationInfo applicationInfo = context.getApplicationInfo();
        Teak.debugConfiguration = new DebugConfiguration(context);
        Teak.isDebug = Teak.forceDebug || Teak.debugConfiguration.forceDebug || (applicationInfo != null
                && (0 != (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE)));
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error creating DebugConfiguration. " + Log.getStackTraceString(e));
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Log.e(LOG_TAG, "Teak requires API level 14 to operate. Teak is disabled.");
        Teak.setState(State.Disabled);
    } else {
        try {
            Application application = activity.getApplication();
            synchronized (Teak.stateMutex) {
                if (Teak.state == State.Allocated) {
                    application.registerActivityLifecycleCallbacks(Teak.lifecycleCallbacks);
                }
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to register Activity lifecycle callbacks. Teak is disabled. "
                    + Log.getStackTraceString(e));
            Teak.setState(State.Disabled);
        }
    }
}

From source file:com.google.android.gm.ay.java

private static String aG(final Context context) {
    Label_0027: {/*from w  ww.  jav a2  s  .c  o m*/
        if (ay.aQK != null) {
            break Label_0027;
        }
        try {
            ay.aQK = String.valueOf(
                    context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode);
            return ay.aQK;
        } catch (PackageManager$NameNotFoundException ex) {
            E.f(ay.mW, "Error finding package %s", context.getApplicationInfo().packageName);
            return ay.aQK;
        }
    }
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +/*www.  j  a  va2 s .  co m*/
 * @throws JSONException 
 */
@SuppressLint("InlinedApi")
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setTicker(json.getString("title"))
            .setContentTitle(json.getString("message")).setContentIntent(contentIntent);

    String message = json.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());
}

From source file:com.xperia64.timidityae.Globals.java

@SuppressLint({ "NewApi", "SdCardPath" })
public static String getLibDir(Context c) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        String s = c.getApplicationInfo().nativeLibraryDir;
        if (!s.endsWith(File.separator)) {
            s += "/";
        }//from   www .j  a v a2 s .c  o m
        return s;
    } else {
        return "/data/data/com.xperia64.timidityae/lib/";
    }
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateNotification(Context context, Intent intent, Handler handler) {
    Bundle extras = intent.getExtras();/*from  w ww .  j  a  v  a  2s .  c  o m*/
    if (extras == null) {
        return;
    }

    extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context));

    String title = (String) extras.get("title");
    String link = (String) extras.get("l");

    // empty message with no data
    Intent notifyIntent;
    if (link != null) {
        // we want main app class to be launched
        notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        notifyIntent = new Intent(context, PushHandlerActivity.class);
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // pass all bundle
        notifyIntent.putExtra("pushBundle", extras);
    }

    // first string will appear on the status bar once when message is added
    CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
    if (null == appName) {
        appName = "";
    }

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationFactory notificationFactory;

    //is this banner notification?
    String bannerUrl = (String) extras.get("b");

    //also check that notification layout has been placed in layout folder
    int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout",
            context.getPackageName());

    if (layoutId != 0 && bannerUrl != null) {
        notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    } else {
        notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    }
    notificationFactory.generateNotification();
    notificationFactory.addSoundAndVibrate();
    notificationFactory.addCancel();

    Notification notification = notificationFactory.getNotification();

    notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (mSimpleNotification) {
        manager.notify(PushManager.MESSAGE_ID, notification);
    } else {
        manager.notify(PushManager.MESSAGE_ID++, notification);
    }

    generateBroadcast(context, extras);
}

From source file:com.ingeneo.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +// ww w. java 2s .  c o m
 * 
 * @throws JSONException
 */
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    JSONObject obj = json.getJSONObject("ibeacon");
    String message = obj.getString("message");
    String title = obj.getString("title");
    if (title == null || title == "") {
        title = context.getApplicationInfo().name;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis()).setTicker(message)
            .setContentTitle(title).setContentText(message).setSmallIcon(context.getApplicationInfo().icon)
            .setContentIntent(contentIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    // Sets a title for the Inbox style big view
    inboxStyle.setBigContentTitle("Beacons");

    // Moves events into the big view
    for (int i = 0; i < itemsNotification.size(); i++) {
        JSONObject beacon = beaconsData.get(itemsNotification.get(i));
        inboxStyle.addLine(beacon.getString("message"));
    }
    // Moves the big view style object into the notification object.
    mBuilder.setStyle(inboxStyle);

    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, "Ver mas", contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());

}

From source file:com.codename1.impl.android.LocalNotificationPublisher.java

private Notification createAndroidNotification(Context context, LocalNotification localNotif,
        PendingIntent content) {/*w  w w. j a v  a  2  s  .  co m*/
    Context ctx = context;
    int smallIcon = ctx.getResources().getIdentifier("ic_stat_notify", "drawable",
            ctx.getApplicationInfo().packageName);
    int icon = ctx.getResources().getIdentifier("icon", "drawable", ctx.getApplicationInfo().packageName);

    if (smallIcon == 0) {
        smallIcon = icon;
    } else {
        icon = smallIcon;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
    builder.setContentTitle(localNotif.getAlertTitle());
    builder.setContentText(localNotif.getAlertBody());
    builder.setAutoCancel(true);
    if (localNotif.getBadgeNumber() >= 0) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
            builder.setNumber(localNotif.getBadgeNumber());
        }
    }
    String image = localNotif.getAlertImage();
    if (image != null && image.length() > 0) {
        if (image.startsWith("/")) {
            image = image.substring(1);
        }
        InputStream in;
        try {
            in = context.getAssets().open(image);
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
            Bitmap im = BitmapFactory.decodeStream(in, null, opts);
            builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(im));
        } catch (IOException ex) {
            Logger.getLogger(LocalNotificationPublisher.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    builder.setSmallIcon(smallIcon);
    builder.setContentIntent(content);
    AndroidImplementation.setNotificationChannel(
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE), builder, context);
    String sound = localNotif.getAlertSound();
    if (sound != null && sound.length() > 0) {
        sound = sound.toLowerCase();
        builder.setSound(android.net.Uri.parse("android.resource://" + ctx.getApplicationInfo().packageName
                + "/raw" + sound.substring(0, sound.indexOf("."))));
    }
    Notification n = builder.build();
    n.icon = icon;
    if (sound == null || sound.length() == 0) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }
    return n;
}

From source file:org.stenerud.kscrash.KSCrash.java

/** Install the crash reporter.
 *
 * @param context The application context.
 *//*from  w w w  .  j a va2  s  .c o m*/
public void install(Context context) throws IOException {
    String appName = context.getApplicationInfo().processName;
    File installDir = new File(context.getCacheDir().getAbsolutePath(), "KSCrash");
    install(appName, installDir.getCanonicalPath());

    // TODO: Put this elsewhere
    oldUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            KSCrash.this.reportJavaException(e);
            KSCrash.oldUncaughtExceptionHandler.uncaughtException(t, e);
        }
    });
}