List of usage examples for android.app Activity getPackageName
@Override
public String getPackageName()
From source file:io.nuclei.cyto.share.ShareIntent.java
/** * Start the sharing activity/*from w ww .j a v a2 s . c o m*/ * * @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 va 2s .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.frostwire.android.gui.util.DangerousPermissionsChecker.java
/** * This method will invoke an activity that shows the WRITE_SETTINGS capabilities * of our app./*from w ww .j a v a 2 s .c om*/ * * More unnecessary distractions and time wasting for developers * courtesy of Google. * * https://commonsware.com/blog/2015/08/17/random-musings-android-6p0-sdk.html * * > Several interesting new Settings screens are now accessible * > via Settings action strings. One that will get a lot of * > attention is ACTION_MANAGE_WRITE_SETTINGS, where users can indicate * > whether apps can write to system settings or not. * > If your app requests the WRITE_SETTINGS permission, you may appear * > on this list, and you can call canWrite() on Settings.System to * > see if you were granted permission. * * Google geniuses, Make up your minds please. */ private void requestWriteSettingsPermissionsAPILevel23(Activity activity) { // Settings.ACTION_MANAGE_WRITE_SETTINGS - won't build if the // intellij sdk is set to API 16 Platform, so I'll just hardcode // the value. // Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS"); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivityForResult(intent, DangerousPermissionsChecker.WRITE_SETTINGS_PERMISSIONS_REQUEST_CODE); }
From source file:com.vinexs.eeb.receiver.BaseReceiverGCM.java
public void requestDeviceRegisterId(Activity activity, final String gcmSenderId) { ArrayList<String> permissionList = new ArrayList<>(); permissionList.add(Manifest.permission.INTERNET); permissionList.add(Manifest.permission.WAKE_LOCK); permissionList.add(Manifest.permission.GET_ACCOUNTS); permissionList.add(Manifest.permission.VIBRATE); permissionList.add("com.google.android.c2dm.permission.RECEIVE"); permissionList.add(activity.getPackageName() + ".permission.C2D_MESSAGE"); if (Utility.hasPermission(activity, permissionList)) { gcm = GoogleCloudMessaging.getInstance(activity.getApplicationContext()); String register_id;//from ww w . jav a 2s .c o m try { register_id = gcm.register(gcmSenderId); if (!register_id.equals("")) { Log.d("GoogleCloudMessaging", "Register ID: " + register_id); handleReceivedRegisterId(register_id); } } catch (Exception e) { e.printStackTrace(); } } SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(activity); if (setting.getInt("notifyId", 0) == 0) { setting.edit().putInt("notifyId", new Random().nextInt(65535)).apply(); } }
From source file:com.bushstar.htmlcoin_android_wallet.ui.ExchangeRatesFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.contentUri = ExchangeRatesProvider.contentUri(activity.getPackageName()); this.loaderManager = getLoaderManager(); }
From source file:com.felkertech.n.ActivityUtils.java
public static void writeDriveData(final Activity context, GoogleApiClient gapi) { //Ask here for permission to storage PermissionUtils.requestPermissionIfDisabled(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, context.getString(R.string.permission_storage_rationale)); if (PermissionUtils.isDisabled(context, android.Manifest.permission_group.STORAGE)) { new MaterialDialog.Builder(context).title(R.string.permission_not_allowed_error) .content(R.string.permission_not_allowed_text).positiveText(R.string.permission_action_settings) .negativeText(R.string.ok).callback(new MaterialDialog.ButtonCallback() { @Override// w w w. j av a 2 s .co m public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", context.getPackageName(), null); intent.setData(uri); } }).build(); } else actuallyWriteData(context, gapi); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public Intent getChangeDefaultSmsAppIntent(final Activity activity) { final Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, activity.getPackageName()); return intent; }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.dialogs.AboutDialogFragment.java
/** * {@inheritDoc}//from w w w . jav a2 s .co m */ @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Activity activity = getActivity(); // Get the inflater then inflate the view from XML. final LayoutInflater inflater = LayoutInflater.from(activity); final View layout = inflater.inflate(R.layout.about, null); final TextView temp = (TextView) layout.findViewById(R.id.aboutVersion); // Set the version text. try { temp.setText(getString(R.string.aboutdialog_version, activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName, activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode)); } catch (NameNotFoundException e) { // This should never occur. temp.setText("Unknown"); } final TextView txtDBVersion = (TextView) layout.findViewById(R.id.aboutDBVersion); final TextView txtTopoVersion = (TextView) layout.findViewById(R.id.aboutTopoVersion); // Get the database mod time. long dbtime; final Calendar date = Calendar.getInstance(); final BusStopDatabase bsd = BusStopDatabase.getInstance(activity.getApplicationContext()); try { dbtime = bsd.getLastDBModTime(); } catch (SQLException e) { dbtime = 0; } date.setTimeInMillis(dbtime); // Set the DB version text. txtDBVersion.setText(getString(R.string.aboutdialog_dbversion, dbtime, dateFormat.format(date.getTime()))); // Set the topology ID text. txtTopoVersion.setText(getString(R.string.aboutdialog_topology, bsd.getTopoId())); final Button btnLicenses = (Button) layout.findViewById(R.id.btnLicenses); btnLicenses.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { callbacks.onShowLicences(); } }); // Get the AlertDialog.Builder with the correct theme set. final AlertDialog.Builder builder; if (isHoneycombOrGreater) { builder = getHoneycombDialog(activity); } else { builder = new AlertDialog.Builder(activity); } // Build the Dialog. builder.setView(layout).setNegativeButton(R.string.close, null); return builder.create(); }
From source file:com.affectiva.affdexme.MetricSelectionFragment.java
/** * A method to populate the metricSelectors array using information from either a saved instance bundle (if the activity is being re-created) * or sharedPreferences (if the activity is being created for the first time) */// w w w . j a v a 2s.c o m void restoreSettings(Bundle bundle) { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); Activity hostActivity = getActivity(); LayoutInflater inflater = hostActivity.getLayoutInflater(); Resources res = getResources(); String packageName = hostActivity.getPackageName(); //populate metricSelectors list with objects for (MetricsManager.Metrics metric : MetricsManager.getAllMetrics()) { metricSelectors.put(metric, new MetricSelector(hostActivity, inflater, res, packageName, metric)); } if (bundle != null) { //if we were passed a bundle, use its data to configure the MetricSelectors for (MetricsManager.Metrics metric : MetricsManager.getAllMetrics()) { if (bundle.getBoolean(metric.toString(), false)) { selectItem(metricSelectors.get(metric), true, false); } } } else { //otherwise, we pull the data from application preferences for (int i = 0; i < NUM_METRICS_DISPLAYED; i++) { MetricsManager.Metrics chosenMetric = PreferencesUtils.getMetricFromPrefs(sharedPreferences, i); selectItem(metricSelectors.get(chosenMetric), true, false); } } }
From source file:org.totschnig.myexpenses.dialog.VersionDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle bundle = getArguments();/*w ww . ja v a 2s .c om*/ Activity ctx = (Activity) getActivity(); LayoutInflater li = LayoutInflater.from(ctx); int from = bundle.getInt("from"); Resources res = getResources(); int[] versionCodes = res.getIntArray(R.array.version_codes); String[] versionNames = res.getStringArray(R.array.version_names); final ArrayList<VersionInfo> versions = new ArrayList<VersionInfo>(); for (int i = 0; i < versionCodes.length; i++) { int code = versionCodes[i]; if (from >= code) break; int resId = res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName()); if (resId == 0) { Log.e(MyApplication.TAG, "missing change log entry for version " + code); } else { String changes[] = res .getStringArray(res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName())); versions.add(new VersionInfo(code, versionNames[i], changes)); } } View view = li.inflate(R.layout.versiondialog, null); final ListView lv = (ListView) view.findViewById(R.id.list); ArrayAdapter<VersionInfo> adapter = new ArrayAdapter<VersionInfo>(ctx, R.layout.version_row, R.id.versionInfoName, versions) { @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout row = (LinearLayout) super.getView(position, convertView, parent); VersionInfo version = versions.get(position); ((TextView) row.findViewById(R.id.versionInfoName)).setText(version.name); ((TextView) row.findViewById(R.id.versionInfoChanges)) .setText("- " + TextUtils.join("\n- ", version.changes)); return row; } }; lv.setAdapter(adapter); if (MyApplication.getInstance().showImportantUpgradeInfo) { view.findViewById(R.id.ImportantUpgradeInfoHeading).setVisibility(View.VISIBLE); view.findViewById(R.id.ImportantUpgradeInfoBody).setVisibility(View.VISIBLE); } AlertDialog.Builder builder = new AlertDialog.Builder(ctx) .setTitle(getString(R.string.help_heading_whats_new)).setIcon(R.drawable.icon).setView(view) .setNegativeButton(android.R.string.ok, this); if (!MyApplication.getInstance().isContribEnabled) builder.setPositiveButton(R.string.menu_contrib, this); return builder.create(); }