Example usage for android.app Activity getPackageName

List of usage examples for android.app Activity getPackageName

Introduction

In this page you can find the example usage for android.app Activity getPackageName.

Prototype

@Override
    public String getPackageName() 

Source Link

Usage

From source file:org.dmfs.webcal.fragments.PagerFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    activity.getSharedPreferences(activity.getPackageName() + "_preferences", 0)
            .registerOnSharedPreferenceChangeListener(this);
}

From source file:com.stepinmobile.fantasticbutton.api.ButtonHandle.java

/**
 * Method check network availability and open Google Play.
 *
 */// w ww  .ja  v  a  2  s. c  om
public void rateOnMarket() {
    if (!isNetworkAvailable()) {
        Toast.makeText(aq.getContext(), R.string.no_internet, Toast.LENGTH_LONG).show();
    } else {
        Activity ac = (Activity) aq.getContext();
        Uri uri = Uri.parse("market://details?id=" + ac.getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        try {
            ac.startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            ac.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + ac.getPackageName())));
        }
    }
}

From source file:szjy.advtech.BuildInfo.java

/**
 * init//  w  ww.j  a  v a 2  s. c  o m
 * @param buildConfigClassName null or specified BuildConfig class name
 * @param callbackContext
 */
private void init(String buildConfigClassName, CallbackContext callbackContext) {
    // Cached check
    if (null != mBuildInfoCache) {
        callbackContext.success(mBuildInfoCache);
        return;
    }

    // Load PackageInfo
    Activity activity = cordova.getActivity();
    String packageName = activity.getPackageName();
    String basePackageName = packageName;
    CharSequence displayName = "";

    PackageManager pm = activity.getPackageManager();

    try {
        PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);

        if (null != pi.applicationInfo) {
            displayName = pi.applicationInfo.loadLabel(pm);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    // Load BuildConfig class
    Class c = null;

    if (null == buildConfigClassName) {
        buildConfigClassName = packageName + ".BuildConfig";
    }

    try {
        c = Class.forName(buildConfigClassName);
    } catch (ClassNotFoundException e) {
    }

    if (null == c) {
        basePackageName = activity.getClass().getPackage().getName();
        buildConfigClassName = basePackageName + ".BuildConfig";

        try {
            c = Class.forName(buildConfigClassName);
        } catch (ClassNotFoundException e) {
            callbackContext.error("BuildConfig ClassNotFoundException: " + e.getMessage());
            return;
        }
    }

    // Create result
    mBuildInfoCache = new JSONObject();
    try {
        boolean debug = getClassFieldBoolean(c, "DEBUG", false);

        mBuildInfoCache.put("packageName", packageName);
        mBuildInfoCache.put("basePackageName", basePackageName);
        mBuildInfoCache.put("displayName", displayName);
        mBuildInfoCache.put("name", displayName); // same as displayName
        mBuildInfoCache.put("version", getClassFieldString(c, "VERSION_NAME", ""));
        mBuildInfoCache.put("versionCode", getClassFieldInt(c, "VERSION_CODE", 0));
        mBuildInfoCache.put("debug", debug);
        mBuildInfoCache.put("buildType", getClassFieldString(c, "BUILD_TYPE", ""));
        mBuildInfoCache.put("flavor", getClassFieldString(c, "FLAVOR", ""));

        if (debug) {
            Log.d(TAG, "packageName    : \"" + mBuildInfoCache.getString("packageName") + "\"");
            Log.d(TAG, "basePackageName: \"" + mBuildInfoCache.getString("basePackageName") + "\"");
            Log.d(TAG, "displayName    : \"" + mBuildInfoCache.getString("displayName") + "\"");
            Log.d(TAG, "name           : \"" + mBuildInfoCache.getString("name") + "\"");
            Log.d(TAG, "version        : \"" + mBuildInfoCache.getString("version") + "\"");
            Log.d(TAG, "versionCode    : " + mBuildInfoCache.getInt("versionCode"));
            Log.d(TAG, "debug          : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false"));
            Log.d(TAG, "buildType      : \"" + mBuildInfoCache.getString("buildType") + "\"");
            Log.d(TAG, "flavor         : \"" + mBuildInfoCache.getString("flavor") + "\"");
        }
    } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.error("JSONException: " + e.getMessage());
        return;
    }

    callbackContext.success(mBuildInfoCache);
}

From source file:com.nick.scalpel.core.request.RequestPermissionWirer.java

private String[] extractUnGranted(Activity activity, String[] declaredPerms) {
    if (declaredPerms == null || declaredPerms.length == 0)
        return null;
    PackageManager packageManager = activity.getPackageManager();
    List<String> requestList = new ArrayList<>(declaredPerms.length);
    for (String info : declaredPerms) {
        int code = packageManager.checkPermission(info, activity.getPackageName());
        if (code == PackageManager.PERMISSION_GRANTED)
            continue;
        logV("Will request perm:" + info + ", current code:" + code);
        requestList.add(info);/*  w w w  .j  a va 2s.c  o  m*/
    }
    String[] out = new String[requestList.size()];
    for (int i = 0; i < requestList.size(); i++) {
        out[i] = requestList.get(i);
    }
    return out;
}

From source file:dev.nick.accessories.injection.processors.PermissionProcessor.java

private String[] extractUnGranted(Activity activity, String[] declaredPerms) {
    if (declaredPerms == null || declaredPerms.length == 0)
        return null;
    PackageManager packageManager = activity.getPackageManager();
    List<String> requestList = new ArrayList<>(declaredPerms.length);
    for (String info : declaredPerms) {
        int code = packageManager.checkPermission(info, activity.getPackageName());
        if (code == PackageManager.PERMISSION_GRANTED)
            continue;
        report("Will request perm:" + info + ", current code:" + code);
        requestList.add(info);//from   w ww. j  a  v  a 2s.c om
    }
    String[] out = new String[requestList.size()];
    for (int i = 0; i < requestList.size(); i++) {
        out[i] = requestList.get(i);
    }
    return out;
}

From source file:com.hanbing.library.android.runtimepermissions.PermissionsManager.java

/**
 * This method retrieves all the permissions declared in the application's manifest.
 * It returns a non null array of permisions that can be declared.
 *
 * @param activity the Activity necessary to check what permissions we have.
 * @return a non null array of permissions that are declared in the application manifest.
 *///from   ww w .  ja  v  a  2s .c om
@NonNull
private synchronized String[] getManifestPermissions(@NonNull final Activity activity) {
    PackageInfo packageInfo = null;
    List<String> list = new ArrayList<>(1);
    try {
        Log.d(TAG, activity.getPackageName());
        packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_PERMISSIONS);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "A problem occurred when retrieving permissions", e);
    }
    if (packageInfo != null) {
        String[] permissions = packageInfo.requestedPermissions;
        if (permissions != null) {
            for (String perm : permissions) {
                Log.d(TAG, "Manifest contained permission: " + perm);
                list.add(perm);
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:cn.moon.superwechat.runtimepermissions.PermissionsManager.java

/**
 * This method retrieves all the permissions declared in the application's manifest.
 * It returns a non null array of permisions that can be declared.
 *
 * @param activity the Activity necessary to check what permissions we have.
 * @return a non null array of permissions that are declared in the application manifest.
 *///ww w.  j  a  v a 2  s . c o  m
@NonNull
private synchronized String[] getManifestPermissions(@NonNull final Activity activity) {
    PackageInfo packageInfo = null;
    List<String> list = new ArrayList<String>(1);
    try {
        Log.d(TAG, activity.getPackageName());
        packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_PERMISSIONS);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "A problem occurred when retrieving permissions", e);
    }
    if (packageInfo != null) {
        String[] permissions = packageInfo.requestedPermissions;
        if (permissions != null) {
            for (String perm : permissions) {
                Log.d(TAG, "Manifest contained permission: " + perm);
                list.add(perm);
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:com.pomelodesign.cordova.metaio.MetaioPlugin.java

public String GetConfigFilePath(Activity action) {
    if (action == null) {
        return null;
    }/*from  www  .ja  v  a 2  s  . c o  m*/

    int id = action.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName());
    if (id == 0) {
        id = action.getResources().getIdentifier("cordova", "xml", action.getPackageName());
        return null;
    }
    if (id == 0) {
        return null;
    }

    XmlResourceParser xml = action.getResources().getXml(id);
    int eventType = -1;
    while (eventType != XmlResourceParser.END_DOCUMENT) {
        if (eventType == XmlResourceParser.START_TAG) {
            String strNode = xml.getName();

            if (strNode.equals("preference")) {
                String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.getDefault());
                if (name.equalsIgnoreCase("arelConfigPath")) {
                    String arelConfigPath = xml.getAttributeValue(null, "value");
                    return arelConfigPath;
                }
            }
        }
        try {
            eventType = xml.next();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    return null;
}

From source file:com.wanderfar.expander.Settings.SettingsActivity.java

private void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        setFloatingUIEnabledorDisabled();
    } else {/*  ww  w. j av  a 2s  . c  o  m*/
        final String packageName = context == null ? fragment.getActivity().getPackageName()
                : context.getPackageName();
        final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + packageName));
        if (fragment != null)
            fragment.startActivityForResult(intent, requestCode);
        else
            context.startActivityForResult(intent, requestCode);
    }

}

From source file:org.totschnig.myexpenses.dialog.ContribDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity ctx = getActivity();
    Resources res = getResources();
    Context wrappedCtx = DialogUtils.wrapContext2(ctx);
    String featureList = Utils.getContribFeatureLabelsAsFormattedList(ctx, feature);
    String featureDescription;/*  w  w  w.  ja  va 2 s .co  m*/
    if (feature.hasTrial)
        featureDescription = getString(R.string.dialog_contrib_premium_feature,
                "<i>" + getString(res.getIdentifier("contrib_feature_" + feature + "_label", "string",
                        ctx.getPackageName())) + "</i>")
                + (usagesLeft > 0
                        ? res.getQuantityString(R.plurals.dialog_contrib_usage_count, usagesLeft, usagesLeft)
                        : getString(R.string.dialog_contrib_no_usages_left));
    else
        featureDescription = getString(res.getIdentifier("contrib_feature_" + feature + "_description",
                "string", ctx.getPackageName()));
    CharSequence message = Html.fromHtml((String) TextUtils.concat(featureDescription, " ",
            getString(R.string.dialog_contrib_reminder_remove_limitation), " ",
            getString(R.string.dialog_contrib_reminder_gain_access), "<br>", featureList));
    return new AlertDialog.Builder(wrappedCtx).setTitle(R.string.dialog_title_contrib_feature)
            .setMessage(message).setNegativeButton(R.string.dialog_contrib_no, this)
            .setPositiveButton(R.string.dialog_contrib_yes, this).create();
}