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:edu.umich.flowfence.sandbox.SandboxService.java

private SandboxContext makePackageContext(String packageName) throws PackageManager.NameNotFoundException {
    // Load up context without code.
    Context pkgContext = createPackageContext(packageName, 0);
    ApplicationInfo ai = pkgContext.getApplicationInfo();
    // Crank up a ClassLoader - we can't use the default DexClassLoader in an isolated process.
    final ClassLoader loader = new PathClassLoader(ai.sourceDir, ai.nativeLibraryDir, getClassLoader());

    return new SandboxContext(pkgContext, packageName, loader, mTrustedAPI, mRootService);
}

From source file:de.petendi.ethereum.android.EthereumAndroid.java

public EthereumAndroid(Context context, EthereumAndroidCallback callback) {
    this.context = context;
    this.callback = callback;
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    EthereumAndroidService.responseHandler = new CallbackHandler();
    packageName = context.getApplicationInfo().packageName;
    Intent intent = new Intent("de.petendi.ethereum.android.action.BIND_API");
    intent.setPackage(EthereumAndroidFactory.PACKAGENAME);
    serviceConnection = new ServiceConnection() {
        @Override// w ww  . j a v a  2  s .c  om
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            binder = IEthereumService.Stub.asInterface(iBinder);
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            binder = null;
        }
    };
    context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.etmay.brescrollpager.ui.MyScroller.java

/**
 * Create a Scroller with the specified interpolator. If the interpolator is
 * null, the default (viscous) interpolator will be used. "Flywheel" behavior will
 * be in effect for apps targeting Honeycomb or newer.
 *//*from w  ww  . j av  a  2 s .  co  m*/
public MyScroller(Context context, Interpolator interpolator) {
    this(context, interpolator, context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB);
}

From source file:com.facebook.litho.LayoutState.java

private static boolean isLayoutDirectionRTL(Context context) {
    ApplicationInfo applicationInfo = context.getApplicationInfo();

    if ((SDK_INT >= JELLY_BEAN_MR1) && (applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0) {

        int layoutDirection = getLayoutDirection(context);
        return layoutDirection == View.LAYOUT_DIRECTION_RTL;
    }/*from w  w w .j  a v a2s  .c  om*/

    return false;
}

From source file:com.brainasylum.andruid.UniqueIdentifierManager.java

private void serializeUdid(Context context, String udid) {
    // if the external storage is writable (according to the current
    // application manifest settings) write to file
    if (canWriteExternalStorage(context)) {
        File dir = new File(Environment.getExternalStorageDirectory() + "/" + FILE_DIR);
        if (!dir.exists()) {
            dir.mkdir();//  w  ww .j a va 2 s  .com
        }
        //
        File file = new File(dir, FILE_NAME);
        //
        String applicationName = context.getApplicationInfo().packageName;
        //
        try {
            //
            JSONObject root;
            if (file.exists()) {
                FileInputStream fis = new FileInputStream(file);
                byte[] buffer = new byte[(int) file.length()];
                fis.read(buffer);
                fis.close();
                root = new JSONObject(new String(buffer));
            } else {
                root = new JSONObject();
            }
            JSONObject values;
            if (root.has(applicationName)) {
                values = root.getJSONObject(applicationName);
            } else {
                values = new JSONObject();
                root.put(applicationName, values);
            }
            //
            values.put(_identifier.getKey(), udid);
            //
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(root.toString().getBytes());
            fos.close();
        } catch (JSONException e) {
            Log.e(TAG, "JSON error with file " + file.getAbsolutePath(), e);
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(TAG, "I/O error with file " + file.getAbsolutePath(), e);
            e.printStackTrace();
        }
    }
    // ... then store the value in the preference file, too...
    SharedPreferences prefs = context.getSharedPreferences(_identifier.getTag(), Context.MODE_PRIVATE);
    prefs.edit().putString(_identifier.getKey(), udid.toString()).commit();
}

From source file:com.brainasylum.andruid.UniqueIdentifierManager.java

private String getSdCardUdid(Context context) {
    if (canReadExternalStorage(context)) {
        File file = new File(Environment.getExternalStorageDirectory() + "/" + FILE_DIR, FILE_NAME);
        if (file.exists()) {
            try {
                //
                FileInputStream fis = new FileInputStream(file);
                byte[] buffer = new byte[(int) file.length()];
                fis.read(buffer);//from ww w. jav a2  s  . c  om
                fis.close();
                JSONObject root = new JSONObject(new String(buffer));
                //
                String applicationName = context.getApplicationInfo().packageName;
                //
                if (root.has(applicationName)) {
                    JSONObject values = root.getJSONObject(applicationName);
                    if (values.has(_identifier.getKey())) {
                        return values.getString(_identifier.getKey());
                    } else {
                        return null;
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "I/O error with file " + file.getAbsolutePath(), e);
                e.printStackTrace();
            } catch (JSONException e) {
                Log.e(TAG, "JSON error with file " + file.getAbsolutePath(), e);
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:com.nuvolect.securesuite.webserver.connector.CmdUpload.java

private CmdUpload(Context context) {
    /**//from w ww  .j  a  v a 2 s . co m
     * An object keyed by filename holds an objects of file chunks.
     * fileUploads
     *     filename1
     *         chunk_0_5
     *         chunk_3_5
     *     filename2
     *         chunk_2_5
     *         chunk_4_5
     */
    fileUploads = new JsonObject();
    chunkDirPath = context.getFilesDir() + CConst.CHUNK;
    dataDir = context.getApplicationInfo().dataDir;
    clearChunkFiles();
}

From source file:bolts.AppLinkNavigation.java

/**
 * Creates a bundle containing the final, constructed App Link data to be used in navigation.
 *//*from ww w  . jav  a  2s.com*/
private Bundle buildAppLinkDataForNavigation(Context context) {
    Bundle data = new Bundle();
    Bundle refererAppLinkData = new Bundle();
    if (context != null) {
        String refererAppPackage = context.getPackageName();
        if (refererAppPackage != null) {
            refererAppLinkData.putString(KEY_NAME_REFERER_APP_LINK_PACKAGE, refererAppPackage);
        }
        ApplicationInfo appInfo = context.getApplicationInfo();
        if (appInfo != null) {
            String refererAppName = context.getString(appInfo.labelRes);
            if (refererAppName != null) {
                refererAppLinkData.putString(KEY_NAME_REFERER_APP_LINK_APP_NAME, refererAppName);
            }
        }
    }
    data.putAll(getAppLinkData());
    data.putString(AppLinks.KEY_NAME_TARGET, getAppLink().getSourceUrl().toString());
    data.putString(KEY_NAME_VERSION, VERSION);
    data.putString(KEY_NAME_USER_AGENT, "Bolts Android " + Bolts.VERSION);
    data.putBundle(KEY_NAME_REFERER_APP_LINK, refererAppLinkData);
    data.putBundle(AppLinks.KEY_NAME_EXTRAS, getExtras());
    return data;
}

From source file:org.jboss.aerogear.cordova.push.NotificationMessageHandler.java

public void createNotification(Context context, Bundle extras) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(context);

    Intent notificationIntent = new Intent(context, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

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

    final String title = extras.getString("title");
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setContentTitle(title != null ? title : appName)
            .setTicker(appName).setAutoCancel(true).setContentIntent(contentIntent);

    String message = extras.getString("alert");
    if (message != null) {
        builder.setContentText(message);
    } else {//from  w ww.  ja v a2  s.  c  o m
        builder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
        builder.setNumber(Integer.parseInt(msgcnt));
    }

    manager.notify(appName, NOTIFICATION_ID, builder.build());
}

From source file:org.jboss.aerogear.cordova.geo.ProximityReceiver.java

public void createNotification(Context context, String id, String status) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(context);

    Intent notificationIntent = new Intent(context, ProxyActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("id", id);
    notificationIntent.putExtra("status", status);

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setContentTitle(appName).setTicker(appName).setAutoCancel(true)
            .setContentIntent(contentIntent);

    if (GeofencingPlugin.getNotifyMessage() != null) {
        builder.setContentText(String.format(GeofencingPlugin.getNotifyMessage(), id, status));
    } else {// www.j  a  v  a 2 s.  c om
        builder.setContentText("You have " + status + " your point of interest");
    }

    notificationManager.notify(appName, NOTIFICATION_ID, builder.build());
}