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:com.manotaurgames.castro.CastFragment.java

private String getCastAppId() {
    if (mCastAppIdRes != null) {
        return getString(mCastAppIdRes);
    }/*from   w  w  w.j a v a2 s  . c o  m*/
    Activity a = getActivity();
    try {
        ApplicationInfo ai = a.getPackageManager().getApplicationInfo(a.getPackageName(),
                PackageManager.GET_META_DATA);
        return (String) ai.metaData.get("GoogleCastId");
    } catch (NameNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.grobox.liberario.fragments.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_about, container, false);
    Activity activity = getActivity();

    String versionName;/*from   ww w  . j a va 2  s  .  c o  m*/
    try {
        versionName = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "?.?";
    }

    // add app name and version
    TextView aboutApp = (TextView) view.findViewById(R.id.aboutApp);
    aboutApp.setText(getResources().getString(R.string.app_name) + "  " + versionName);

    // create real paragraphs
    TextView t = (TextView) view.findViewById(R.id.aboutTextView);
    t.setText(Html.fromHtml(getString(R.string.about)
            + String.format(getString(R.string.about_bottom), getString(R.string.website),
                    getString(R.string.bugtracker), getString(R.string.website) + "#donate")));

    // make links in about text clickable
    t.setMovementMethod(LinkMovementMethod.getInstance());
    t.setLinkTextColor(ContextCompat.getColor(activity, R.color.accent));

    Button website = (Button) view.findViewById(R.id.websiteButton);
    website.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website)));
            startActivity(launchBrowser);
        }
    });

    return view;
}

From source file:io.palaima.debugdrawer.modules.BuildModule.java

@Override
public void onAttachActivity(Activity activity) {
    super.onAttachActivity(activity);
    try {//from  w  ww.j ava 2 s .  c  om
        info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:br.ajmarques.cordova.plugin.localnotification.Options.java

Options(Activity activity) {
    packageName = activity.getPackageName();
}

From source file:com.brq.wallet.activity.main.BalanceMasterFragment.java

@Override
public void onResume() {
    Activity activity = getActivity();
    // Set beta build
    PackageInfo pInfo;/*  w w  w.  java2s  .  c om*/
    try {
        pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        ((TextView) activity.findViewById(R.id.tvBuildText))
                .setText(getResources().getString(R.string.build_text, pInfo.versionName));
    } catch (NameNotFoundException e) {
        // Ignore
        //todo insert uncaught error handler
    }

    MbwManager mbwManager = MbwManager.getInstance(activity);
    tvTor = (TextView) activity.findViewById(R.id.tvTorState);
    if (mbwManager.getTorMode() == ServerEndpointType.Types.ONLY_TOR && mbwManager.getTorManager() != null) {
        tvTor.setVisibility(View.VISIBLE);
        showTorState(mbwManager.getTorManager().getInitState());
    } else {
        tvTor.setVisibility(View.GONE);
    }

    MbwManager.getInstance(this.getActivity()).getEventBus().register(this);
    super.onResume();
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

public static void openUriInCustomTabs(Activity activity, Uri uri, boolean excludeRview) {
    // Check user preferences
    if (!Preferences.isAccountUseCustomTabs(activity, Preferences.getAccount(activity))) {
        openUri(activity, uri, excludeRview);
        return;/*from w  ww  .j  ava2  s  . c  om*/
    }

    try {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setShowTitle(true);
        builder.setToolbarColor(ContextCompat.getColor(activity, R.color.primaryDark));
        CustomTabsIntent intent = builder.build();

        String packageName = CustomTabsHelper.getPackageNameToUse(activity);
        if (packageName == null) {
            openUri(activity, uri, excludeRview);
            return;
        }

        intent.intent.setPackage(packageName);
        if (excludeRview) {
            intent.intent.putExtra(Constants.EXTRA_SOURCE, activity.getPackageName());
        }
        intent.intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
        intent.launchUrl(activity, uri);

    } catch (ActivityNotFoundException ex) {
        // Fallback to default browser
        openUri(activity, uri, excludeRview);
    }
}

From source file:de.grobox.transportr.about.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_about, container, false);
    Activity activity = getActivity();

    String versionName;//from w  w w.ja  v a 2s . co m
    try {
        if (activity == null)
            throw new NameNotFoundException();
        versionName = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        versionName = "?.?";
    }

    // add app name and version
    TextView aboutApp = view.findViewById(R.id.aboutApp);
    aboutApp.setText(getResources().getString(R.string.app_name) + "  " + versionName);

    // create real paragraphs
    TextView t = view.findViewById(R.id.aboutTextView);
    t.setText(Html.fromHtml(getString(R.string.about)
            + String.format(getString(R.string.about_bottom), getString(R.string.website),
                    getString(R.string.bugtracker), getString(R.string.website) + "#donate")));

    // make links in about text clickable
    t.setMovementMethod(LinkMovementMethod.getInstance());
    t.setLinkTextColor(ContextCompat.getColor(getContext(), R.color.accent));

    Button website = view.findViewById(R.id.websiteButton);
    website.setOnClickListener(v -> {
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website)));
        startActivity(launchBrowser);
    });

    return view;
}

From source file:net.kourlas.voipms_sms.Billing.java

public void postDonation(final String token, final Activity sourceActivity) {
    new AsyncTask<Void, Void, Void>() {
        @Override/*from  w  ww . j  a va2s  .  c o m*/
        protected Void doInBackground(Void... params) {
            try {
                billingService.consumePurchase(3, sourceActivity.getPackageName(), token);
            } catch (Exception ignored) {
                // Do nothing.
            }
            return null;
        }
    }.execute();
}

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

@Override
public void onDetach() {
    // avoid to get notifications for changes in the shared preferences that we caused ourselves (because the active section has been stored)
    Activity activity = getActivity();
    activity.getSharedPreferences(activity.getPackageName() + "_preferences", 0)
            .unregisterOnSharedPreferenceChangeListener(this);
    super.onDetach();
}

From source file:com.lee.sdk.utils.Utils.java

/**
 * ????//from   ww w.j  a  v  a 2 s . co m
 * 
 * @param activity ?Activity???
 * @param nameId ????
 * @param iconId ??
 * @param appendFlags ????IntentFlag
 */
public static void addShortcut(Activity activity, int nameId, int iconId, int appendFlags) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    // ????
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(nameId));
    shortcut.putExtra("duplicate", false); // ????

    // ?Activity???
    ComponentName comp = new ComponentName(activity.getPackageName(), activity.getClass().getName());
    Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(comp);
    if (appendFlags != 0) {
        intent.addFlags(appendFlags);
    }
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    // ??
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, iconId);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    activity.sendBroadcast(shortcut);
}