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:it.telecomitalia.my.base_struct_apps.VersionUpdate.java

public VersionUpdate(Activity activity) {
    super();/*from w  ww  .  j a va 2  s .  c o m*/
    /* http://developer.android.com/tools/publishing/versioning.html
     * si comincia dal capire che versione sto utilizzando. Nella documentazione sopra
     * elencata, leggersi tutto e fare attenzione alla differenza tra Version Name e
     * Version Code. Con questo metodo mi leggo il versionName e lo salvo per
     * ulteriori elaborazioni. In caso qualcosa non funzionasse ritorno null */
    try {
        PackageManager manager = activity.getPackageManager();
        PackageInfo info = manager.getPackageInfo(activity.getPackageName(), 0);
        runningVersion = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        runningVersion = null;
    }
}

From source file:org.onepf.oms.appstore.SamsungAppsBillingService.java

@Override
public void launchPurchaseFlow(Activity activity, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    String itemGroupId = getItemGroupId(sku);
    String itemId = getItemId(sku);

    Bundle bundle = new Bundle();
    bundle.putString(KEY_NAME_THIRD_PARTY_NAME, activity.getPackageName());
    bundle.putString(KEY_NAME_ITEM_GROUP_ID, itemGroupId);
    bundle.putString(KEY_NAME_ITEM_ID, itemId);
    if (isDebugLog())
        Log.d(TAG, "launchPurchase: itemGroupId = " + itemGroupId + ", itemId = " + itemId);
    ComponentName cmpName = new ComponentName(SamsungApps.IAP_PACKAGE_NAME, PAYMENT_ACTIVITY_NAME);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(cmpName);//from  w  ww .  ja v a2s .co m
    intent.putExtras(bundle);
    mRequestCode = requestCode;
    mPurchaseListener = listener;
    purchasingItemType = itemType;
    mItemGroupId = itemGroupId;
    mExtraData = extraData;
    if (isDebugLog())
        Log.d(TAG, "Request code: " + requestCode);
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.handlerexploit.news.fragments.WeatherFragment.java

private void render(WeatherInfo weatherInfo) {
    Activity activity = getActivity();
    if (activity != null && weatherInfo != null) {
        View root = getView();// www . j  av a 2 s .  c  o  m

        TextView city = (TextView) root.findViewById(R.id.city);
        city.setText(weatherInfo.getCity());

        CurrentWeather currentWeather = weatherInfo.getCurrentWeather();

        RemoteImageView icon = (RemoteImageView) root.findViewById(R.id.icon);
        int resId = activity.getResources().getIdentifier(currentWeather.getIcon(), "drawable",
                activity.getPackageName());
        if (resId != 0) {
            ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(resId);
            icon.setImageResource(resId);
        } else {
            ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(R.drawable.unknown);
            icon.setImageResource(R.drawable.unknown);
        }

        TextView temp = (TextView) root.findViewById(R.id.temp);
        temp.setText(currentWeather.getTempF() + " \u00B0F | " + currentWeather.getTempC() + " \u00B0C");
        ((TextView) activity.findViewById(R.id.weather_small_text))
                .setText(currentWeather.getTempF() + "\u00B0");

        TextView condition = (TextView) root.findViewById(R.id.condition);
        String conditionText = currentWeather.getCondition();
        if (conditionText != null && !conditionText.equals("")) {
            condition.setText(conditionText);
        } else {
            condition.setText("N/A");
        }

        TextView windCondition = (TextView) root.findViewById(R.id.windCondition);
        windCondition.setText(currentWeather.getWindCondition());

        TextView humidity = (TextView) root.findViewById(R.id.humidity);
        humidity.setText(currentWeather.getHumidity());

        LinearLayout forcastConditions = (LinearLayout) root.findViewById(R.id.forcastConditions);
        forcastConditions.removeAllViews();

        LayoutInflater inflater = LayoutInflater.from(activity);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        params.weight = 1f;

        ArrayList<Condition> forcastArray = weatherInfo.getForcastConditions();
        for (int i = 0; i < forcastArray.size(); i++) {
            Condition forcastCondition = forcastArray.get(i);
            View forcastRoot = inflater.inflate(R.layout.fragment_weather_condition_item, null);

            TextView forcastDay = (TextView) forcastRoot.findViewById(R.id.day);
            forcastDay.setText(forcastCondition.getDay());

            RemoteImageView forcastIcon = (RemoteImageView) forcastRoot.findViewById(R.id.icon);
            int forcastResId = activity.getResources().getIdentifier(forcastCondition.getIcon(), "drawable",
                    activity.getPackageName());
            if (forcastResId != 0) {
                forcastIcon.setImageResource(forcastResId);
            } else {
                forcastIcon.setImageResource(R.drawable.unknown);
            }

            TextView forcastHigh = (TextView) forcastRoot.findViewById(R.id.high);
            forcastHigh.setText(forcastCondition.getHigh() + "\u00B0");

            TextView forcastLow = (TextView) forcastRoot.findViewById(R.id.low);
            forcastLow.setText(forcastCondition.getLow() + "\u00B0");

            forcastConditions.addView(forcastRoot, params);
        }
    }
}

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

private String[] getRequiredPermissions() {
    Activity activity = getActivity();
    try {/*from   ww  w.  ja v a  2  s  .  c  o  m*/
        PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_PERMISSIONS);
        String[] ps = info.requestedPermissions;
        if (ps != null && ps.length > 0) {
            return ps;
        } else {
            return new String[0];
        }
    } catch (Exception e) {
        return new String[0];
    }
}

From source file:com.facebook.AppEventsLogger.java

/**
 * Source Application setters and getters
 *//*  w ww  .j ava 2  s.  c  om*/
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an intent before.
    // Introduce an extra field in the intent to force clear the sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}

From source file:com.facebook.appevents.AppEventsLogger.java

/**
 * Source Application setters and getters
 *///from  w  ww  .  j av a2 s  .c  o  m
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an
    // intent before. Introduce an extra field in the intent to force clear the
    // sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}

From source file:crittercism.CrittercismModuleModule.java

@Kroll.method
public void start(KrollDict dict) {
    String app_id = (String) dict.get("appID");
    Boolean should_collect_logcat = (Boolean) dict.get("setLogcatReportingEnabled");
    String custom_app_version = (String) dict.get("customAppVersion");

    Activity activity = TiApplication.getAppCurrentActivity();

    if (app_id != null) {
        // We have an app id, now we can do this

        try {//from w  ww  .  j a  v  a  2 s  .  com

            CrittercismConfig config = new CrittercismConfig();

            // Set the version name
            if (custom_app_version != null) {
                config.setCustomVersionName(custom_app_version);
                config.setVersionCodeToBeIncludedInVersionString(false);
            } else {
                config.setCustomVersionName(
                        activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName);
                config.setVersionCodeToBeIncludedInVersionString(true);
            }

            // Send logcat info
            if (should_collect_logcat != null && should_collect_logcat) {
                config.setLogcatReportingEnabled(should_collect_logcat);
            }

            // Initialize.
            Crittercism.initialize(activity.getApplicationContext(), app_id, config);

            handleLastCrash();
        } catch (Exception e) {
            // Well... we couldn't start...
            // Log.e(LCAT, "Can't inialize because of: "+e);
        }
        ;
    } else {
        // There's no app id... we can't start it
        // Log.e(LCAT, "Crittercism cannot be initialized without an app id!");
    }
}

From source file:com.crearo.gpslogger.ui.fragments.display.GpsSimpleViewFragment.java

private void startInstalledAppDetailsActivity(final Activity context) {
    if (context == null) {
        return;/*w ww  . j  av a  2s  . c  o  m*/
    }
    final Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);
}

From source file:net.globide.coloring_book.MainPanelFragment.java

/**
 * Implements onCreateView().// www  .j  av a  2  s.  c  o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    // Inflate the view for the search fragment.
    View view = inflater.inflate(R.layout.panel_main, container, false);

    // Get the host activity as an object.
    Activity activity = getActivity();

    // If the host activity exists...
    if (activity != null) {

        // Get the selected category data.
        Bundle extras = this.getArguments();
        mCid = extras.getInt("id");
        mCategory = extras.getString("category");

        /*
         * ImageView.
         */

        // Set the current palette cover.
        final ImageButton ibMainColor = (ImageButton) view.findViewById(R.id.ibMainColor);
        // Generate the resource name based on the current category id.
        int imageResourceId = getResources().getIdentifier("cover_" + mCid, "drawable",
                activity.getPackageName());
        // Create a new drawable object to so we can draw our credits image.
        Drawable image = this.getResources().getDrawable(imageResourceId);

        ibMainColor.setImageDrawable(image);

        ibMainColor.setBackgroundColor(Color.TRANSPARENT);

        ibMainColor.setTag("ibMainColor");
        ibMainColor.setOnClickListener(this);

        /*
         * TextView.
         */

        // Set the category name as the title of this coloring book.
        final TextView tvMainTitle = (TextView) view.findViewById(R.id.tvPanelMain);
        tvMainTitle.setText(mCategory);

        /*
         * This screen needs to be dynamically positioned to fit each screen
         * size fluidly.
         */
        RelativeLayout mRlPanelMain = (RelativeLayout) view.findViewById(R.id.rlPanelMain);

        // Determine the floor section size
        Drawable imageFloor = this.getResources().getDrawable(R.drawable.floor);
        // Store the height locally
        int floorHeight = imageFloor.getIntrinsicHeight();

        // Resize the layout views to be centered in their proper positions
        // based on the sizes calculated.
        ViewGroup.LayoutParams paramsTop = mRlPanelMain.getLayoutParams();
        int resultHeight = floorHeight;
        paramsTop.height = resultHeight;
        mRlPanelMain.setLayoutParams(paramsTop);
    }

    return view;
}

From source file:com.github.yuqilin.qmediaplayerapp.util.Permissions.java

private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
    int titleId = 0, textId = 0;
    String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
    switch (mode) {
    case PERMISSION_SYSTEM_RINGTONE:
        titleId = R.string.allow_settings_access_ringtone_title;
        textId = R.string.allow_settings_access_ringtone_description;
        break;/*from  w ww  .j  av  a 2s  .c o m*/
    case PERMISSION_SYSTEM_BRIGHTNESS:
        titleId = R.string.allow_settings_access_brightness_title;
        textId = R.string.allow_settings_access_brightness_description;
        break;
    case PERMISSION_SYSTEM_DRAW_OVRLAYS:
        titleId = R.string.allow_draw_overlays_title;
        textId = R.string.allow_sdraw_overlays_description;
        action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
        break;
    }
    final String finalAction = action;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId))
            .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(activity.getString(R.string.permission_ask_again),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            Intent i = new Intent(finalAction);
                            i.setData(Uri.parse("package:" + activity.getPackageName()));
                            try {
                                activity.startActivity(i);
                            } catch (Exception ex) {
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_settings_access", true);
                            Util.commitPreferences(editor);
                        }
                    });
    return dialogBuilder.show();
}