Example usage for android.app Activity getPackageManager

List of usage examples for android.app Activity getPackageManager

Introduction

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

Prototype

@Override
    public PackageManager getPackageManager() 

Source Link

Usage

From source file:com.waz.zclient.pages.main.conversation.AssetIntentsManager.java

public AssetIntentsManager(Activity activity, Callback callback, Bundle savedInstanceState) {
    setCallback(callback);//from w  w w . java 2 s.co m

    if (savedInstanceState != null) {
        pendingFileUri = savedInstanceState.getParcelable(SAVED_STATE_PENDING_URI);
    }
    pm = activity.getPackageManager();
}

From source file:io.nuclei.cyto.share.ShareIntent.java

/**
 * Start the sharing activity/*from w ww .j  a  v  a2s  .c om*/
 *
 * @param info The activity info
 * @param requestCode The request code to receive back from the started activity
 * @param permissionRequestCode The permission request code in case we need access to external storage
 */
public Intent startActivityForResult(Activity activity, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = activity.getPackageManager()
                .getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
        if (PackageTargetManager.FACEBOOK.equals(info.activityInfo.packageName))
            facebookId = applicationInfo.metaData.getString("com.facebook.sdk.ApplicationId");
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mTargetListeners == null ? null
            : mTargetListeners.get(info.activityInfo.packageName);
    if (manager == null) {
        if (mDefaultTargetManager == null)
            manager = new DefaultPackageTargetManager();
        else
            manager = mDefaultTargetManager;
    }
    manager.initialize(mText, mUri, mUrl, mEmail, mSubject, mFile);
    manager.mFacebookId = facebookId;
    Intent intent = manager.onCreateIntent(activity, authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(activity, intent, requestCode);
    return intent;
}

From source file:nuclei.ui.share.ShareIntent.java

/**
 * Start the sharing activity//w w w . j a v a2s .  c  om
 *
 * @param info The activity info
 * @param requestCode The request code to receive back from the started activity
 * @param permissionRequestCode The permission request code in case we need access to external storage
 */
public Intent startActivityForResult(Activity activity, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = activity.getPackageManager()
                .getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
        if (PackageTargetManager.FACEBOOK.equals(info.activityInfo.packageName))
            facebookId = applicationInfo.metaData.getString("com.facebook.sdk.ApplicationId");
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mTargetListeners == null ? null
            : mTargetListeners.get(info.activityInfo.packageName);
    if (manager == null) {
        if (mDefaultTargetManager == null)
            manager = new DefaultPackageTargetManager();
        else
            manager = mDefaultTargetManager;
    }
    manager.initialize(mText, mUri, mUrl, mSms, mEmail, mSubject, mFile);
    manager.mFacebookId = facebookId;
    Intent intent = manager.onCreateIntent(activity, authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(activity, intent, requestCode);
    return intent;
}

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   w  w w  .  j  av  a  2  s  .  c o m*/
@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.
 *///  w ww .j  ava  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:szjy.advtech.BuildInfo.java

/**
 * init//from w w w . ja  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:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Creates the speech recognizer and text-to-speech synthesizer instances
 * @see RecognitionListener.java//from   w  w  w . j  a  v  a 2s .c om
 * @param ctx context of the interaction
 * */
public void initSpeechInputOutput(Activity ctx) {

    this.ctx = ctx;
    PackageManager packManager = ctx.getPackageManager();

    setTTS();

    // Find out whether speech recognition is supported
    List<ResolveInfo> intActivities = packManager
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (intActivities.size() != 0 || "generic".equals(Build.BRAND.toLowerCase(Locale.US))) {
        myASR = SpeechRecognizer.createSpeechRecognizer(ctx);
        myASR.setRecognitionListener(this);
    } else
        myASR = null;
}

From source file:hku.fyp14017.blencode.ui.controller.LookController.java

public boolean checkIfPocketPaintIsInstalled(Intent intent, final Activity activity) {
    // Confirm if Pocket Paint is installed else start dialog --------------------------

    List<ResolveInfo> packageList = activity.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);

    if (packageList.size() <= 0) {
        AlertDialog.Builder builder = new CustomAlertDialogBuilder(activity);
        builder.setTitle(hku.fyp14017.blencode.R.string.pocket_paint_not_installed_title);
        builder.setMessage(hku.fyp14017.blencode.R.string.pocket_paint_not_installed).setCancelable(false)
                .setPositiveButton(hku.fyp14017.blencode.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override//from   w  w  w .  j  a  v  a2s .c o  m
                    public void onClick(DialogInterface dialog, int id) {
                        Intent downloadPocketPaintIntent = new Intent(Intent.ACTION_VIEW,
                                Uri.parse(Constants.POCKET_PAINT_DOWNLOAD_LINK));
                        activity.startActivity(downloadPocketPaintIntent);
                    }
                }).setNegativeButton(hku.fyp14017.blencode.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        return false;
    }
    return true;
}

From source file:org.catrobat.catroid.ui.controller.LookController.java

public boolean checkIfPocketPaintIsInstalled(Intent intent, final Activity activity) {
    // Confirm if Pocket Paint is installed else start dialog --------------------------

    List<ResolveInfo> packageList = activity.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);

    if (packageList.size() <= 0) {
        AlertDialog.Builder builder = new CustomAlertDialogBuilder(activity);
        builder.setTitle(R.string.pocket_paint_not_installed_title);
        builder.setMessage(R.string.pocket_paint_not_installed).setCancelable(false)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    @Override//from  www  .j  ava2  s  .c  o m
                    public void onClick(DialogInterface dialog, int id) {
                        Intent downloadPocketPaintIntent = new Intent(Intent.ACTION_VIEW,
                                Uri.parse(Constants.POCKET_PAINT_DOWNLOAD_LINK));
                        activity.startActivity(downloadPocketPaintIntent);
                    }
                }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        return false;
    }
    return true;
}

From source file:com.metinkale.prayerapp.utils.PermissionUtils.java

public void needNotificationPolicy(final Activity act) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;// w  ww .ja va  2  s.  c  o  m
    }
    NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE);
    pNotPolicy = nm.isNotificationPolicyAccessGranted();
    if (!pNotPolicy) {
        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        PackageManager packageManager = act.getPackageManager();
        if (intent.resolveActivity(packageManager) != null) {
            act.startActivity(intent);
        } else {
            ActivityCompat.requestPermissions(act,
                    new String[] { Manifest.permission.ACCESS_NOTIFICATION_POLICY }, 0);
        }
    }
}