List of usage examples for android.app Activity getPackageManager
@Override
public PackageManager getPackageManager()
From source file:com.easy.facebook.android.facebook.FBLoginManager.java
private boolean validateAppSignatureForIntent(Activity activity, Intent intent) { ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, 0); if (resolveInfo == null) { return false; }/*from w w w .ja v a2 s . c o m*/ String packageName = resolveInfo.activityInfo.packageName; PackageInfo packageInfo; try { packageInfo = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (NameNotFoundException e) { return false; } for (Signature signature : packageInfo.signatures) { if (signature.toCharsString().equals(FB_APP_SIGNATURE)) { return true; } } return false; }
From source file:mysteryinc.eagleeye.LiveLocatorFragment.java
/** * Start the camera by dispatching a camera intent. Returns a string location to the photo. *//* ww w. jav a 2s. c om*/ private String takePicture() { // Check if there is a camera. if (deviceMissingCamera()) { MainActivity.toast("This device does not have a camera."); return ""; } // Camera exists? Then proceed... Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent Activity activity = getActivity(); File photoFile = null; if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go. // If you don't do this, you may get a crash in some devices. try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); MainActivity.toast("There was a problem saving the photo..."); } // Continue only if the File was successfully created if (photoFile != null) { Uri fileUri = Uri.fromFile(photoFile); // activity.setCapturedImageURI(fileUri); // activity.setCurrentPhotoPath(fileUri.getPath()); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // activity.getCapturedImageURI()); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } return photoFile.getAbsolutePath(); }
From source file:org.kontalk.ui.DonationFragment.java
private void donateBitcoin() { final String address = getString(R.string.bitcoin_address); Uri uri = Uri.parse("bitcoin:" + address); Intent intent = SystemUtils.externalIntent(Intent.ACTION_VIEW, Uri.parse(uri.toString())); Activity ctx = getActivity(); final PackageManager pm = ctx.getPackageManager(); if (pm.resolveActivity(intent, 0) != null) startActivity(intent);/*from w ww .j a v a 2s. c o m*/ else new MaterialDialog.Builder(getActivity()).title(R.string.title_bitcoin_dialog) .content(getString(R.string.text_bitcoin_dialog, address)).positiveText(android.R.string.ok) .neutralText(R.string.copy_clipboard).onNeutral(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ClipboardManager cpm = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); cpm.setText(address); Toast.makeText(getActivity(), R.string.bitcoin_clipboard_copied, Toast.LENGTH_LONG) .show(); } }).show(); }
From source file:br.com.hotforms.FacebookHash.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return True if the action was valid, false otherwise. */// w w w . j a va 2 s .com @Override public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(TAG, "Executing action: " + action); final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); if ("getHash".equals(action)) { try { String packageName = activity.getClass().getPackage().getName(); PackageManager packageManager = activity.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT); String result = String.format("{ FacebookHash : \"%s\", PackageName : \"%s\"}", hash.trim(), packageName); callbackContext.success(result); } } catch (NameNotFoundException e) { callbackContext.error(e.getMessage()); } catch (NoSuchAlgorithmException e) { callbackContext.error(e.getMessage()); } return true; } return false; }
From source file:com.felkertech.n.ActivityUtils.java
/** * Opens the correct intent to start editing the channel. * * @param activity The activity you're calling this from. * @param channelUrl The channel's media url.m */// ww w. j av a2 s . c o m public static void editChannel(final Activity activity, final String channelUrl) { ChannelDatabase cdn = ChannelDatabase.getInstance(activity); final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl); if (channelUrl == null || jsonChannel == null) { try { Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show(); } catch (RuntimeException e) { Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid)); } return; } if (jsonChannel.getPluginSource() != null) { // Search through all plugins for one of a given source PackageManager pm = activity.getPackageManager(); try { pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES); // Open up this particular activity Intent intent = new Intent(); intent.setComponent(jsonChannel.getPluginSource()); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT); Log.d(TAG, "Editing channel " + jsonChannel.toString()); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString()); activity.startActivity(intent); } catch (PackageManager.NameNotFoundException e) { new MaterialDialog.Builder(activity) .title(activity.getString(R.string.plugin_not_installed_title, jsonChannel.getPluginSource().getPackageName())) .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app) .negativeText(R.string.open_in_another_plugin) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + jsonChannel.getPluginSource().getPackageName())); activity.startActivity(i); } @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); openPluginPicker(false, channelUrl, activity); } }).show(); Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed, jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show(); openPluginPicker(false, channelUrl, activity); } } else { if (DEBUG) { Log.d(TAG, "No specified source"); } openPluginPicker(false, channelUrl, activity); } }
From source file:org.apache.cordova.smsreceiver.SmsReceivingPlugin.java
@Override public boolean execute(String action, JSONArray arg1, final CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_HAS_RECEIVE_PERMISSION)) { Activity ctx = this.cordova.getActivity(); if (Build.VERSION.SDK_INT >= 23) { if (PermissionHelper.hasPermission(this, Manifest.permission.RECEIVE_SMS)) { if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true)); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false)); }//from w ww.ja va 2 s . com return true; } else { PermissionHelper.requestPermission(this, 0, Manifest.permission.RECEIVE_SMS); JSONObject returnObj = new JSONObject(); addProperty(returnObj, "permissionGranted", true); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, returnObj)); return true; } } else { if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true)); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false)); } return true; } } else if (action.equals(ACTION_START_RECEIVE_SMS)) { // if already receiving (this case can happen if the startReception is called // several times if (this.isReceiving) { // close the already opened callback ... PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(false); this.callback_receive.sendPluginResult(pluginResult); // ... before registering a new one to the sms receiver } this.isReceiving = true; if (this.smsReceiver == null) { this.smsReceiver = new SmsReceiver(); IntentFilter fp = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); fp.setPriority(1000); // fp.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); this.cordova.getActivity().registerReceiver(this.smsReceiver, fp); } this.smsReceiver.startReceiving(callbackContext); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); this.callback_receive = callbackContext; return true; } else if (action.equals(ACTION_STOP_RECEIVE_SMS)) { if (this.smsReceiver != null) { smsReceiver.stopReceiving(); } this.isReceiving = false; // 1. Stop the receiving context PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(false); this.callback_receive.sendPluginResult(pluginResult); // 2. Send result for the current context pluginResult = new PluginResult(PluginResult.Status.OK); callbackContext.sendPluginResult(pluginResult); return true; } return false; }
From source file:org.androidsoft.app.permission.ui.ApplicationFragment.java
void updateApplication(Activity activity, String packageName) { if (PermissionService.exists(activity, packageName)) { try {// w w w . java 2 s . c o m mActivity = activity; mPackageName = packageName; PackageManager pm = activity.getPackageManager(); PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); mName.setText(pi.applicationInfo.loadLabel(pm).toString()); mIcon.setImageDrawable(pi.applicationInfo.loadIcon(pm)); mTvPackageName.setText(packageName); mTvVersion.setText(pi.versionName); List<PermissionGroup> listGroups = PermissionService.getPermissions(pi.requestedPermissions, pm); PermissionExpandableListAdapter adapter = new PermissionExpandableListAdapter(getActivity(), listGroups); mPermissions.setAdapter(adapter); for (int i = 0; i < listGroups.size(); i++) { mPermissions.expandGroup(i); } if (listGroups.isEmpty()) { mNoPermissionLayout.setVisibility(View.VISIBLE); mIvTrusted.setVisibility(View.GONE); } else { mNoPermissionLayout.setVisibility(View.GONE); mIvTrusted.setVisibility(View.VISIBLE); if (PermissionService.isTrusted(mActivity, mPackageName)) { mIvTrusted.setImageResource(R.drawable.trusted_on); } else { mIvTrusted.setImageResource(R.drawable.trusted_off); } } mTvMessageNoApplication.setVisibility(View.GONE); mApplicationLayout.setVisibility(View.VISIBLE); } catch (NameNotFoundException ex) { Log.e(Constants.TAG, "Package name not found : " + packageName); } } else { mTvMessageNoApplication.setVisibility(View.VISIBLE); mApplicationLayout.setVisibility(View.GONE); } }
From source file:com.pspdfkit.cordova.PSPDFCordovaPlugin.java
@SuppressWarnings("ConstantConditions") @NonNull/*from ww w. j ava2 s. com*/ private PSPDFActivityConfiguration parseOptionsToConfiguration(@NonNull final JSONObject options) throws JSONException { final Activity activity = cordova.getActivity(); int theme; try { ActivityInfo info = activity.getPackageManager() .getActivityInfo(new ComponentName(activity, PSPDFActivity.class), 0); theme = info.theme; } catch (PackageManager.NameNotFoundException e) { theme = R.style.Theme_AppCompat_NoActionBar; } final ContextThemeWrapper themedContext = new ContextThemeWrapper(activity, theme); final PSPDFActivityConfiguration.Builder builder = new PSPDFActivityConfiguration.Builder(themedContext, licenseKey); final Iterator<String> optionIterator = options.keys(); while (optionIterator.hasNext()) { final String option = optionIterator.next(); final Object value = options.get(option); try { if ("backgroundColor".equals(option)) { builder.backgroundColor(Color.parseColor((String) value)); } else if ("disableOutline".equals(option) && ((Boolean) value)) { builder.disableOutline(); } else if ("disableSearch".equals(option) && ((Boolean) value)) { builder.disableSearch(); } else if ("hidePageLabels".equals(option) && ((Boolean) value)) { builder.hidePageLabels(); } else if ("hidePageNumberOverlay".equals(option) && ((Boolean) value)) { builder.hidePageNumberOverlay(); } else if ("hideThumbnailBar".equals(option) && ((Boolean) value)) { builder.hideThumbnailBar(); } else if ("hideThumbnailGrid".equals(option) && ((Boolean) value)) { builder.hideThumbnailGrid(); } else if ("diskCacheSize".equals(option)) { builder.diskCacheSize((Integer) value); } else if ("memoryCacheSize".equals(option)) { builder.memoryCacheSize((Integer) value); } else if ("pageFitMode".equals(option)) { builder.fitMode(PageFitMode.valueOf((String) value)); } else if ("scrollDirection".equals(option)) { builder.scrollDirection(PageScrollDirection.valueOf((String) value)); } else if ("scrollMode".equals(option)) { builder.scrollMode(PageScrollMode.valueOf((String) value)); } else if ("invertColors".equals(option)) { builder.invertColors((Boolean) value); } else if ("toGrayscale".equals(option)) { builder.toGrayscale((Boolean) value); } else if ("loggingEnabled".equals(option)) { builder.loggingEnabled((Boolean) value); } else if ("title".equals(option)) { builder.title(fromJsonString(options.getString("title"))); } else if ("startZoomScale".equals(option)) { builder.startZoomScale((float) options.getDouble("startZoomScale")); } else if ("maxZoomScale".equals(option)) { builder.maxZoomScale((float) options.getDouble("maxZoomScale")); } else if ("zoomOutBounce".equals(option)) { builder.zoomOutBounce(options.getBoolean("zoomOutBounce")); } else if ("page".equals(option)) { builder.page(options.getInt("page")); } else if ("useImmersiveMode".equals(option)) { builder.useImmersiveMode(options.getBoolean("useImmersiveMode")); } else if ("searchType".equals(option)) { final String searchType = options.getString("searchType"); if ("SEARCH_INLINE".equals(searchType)) builder.setSearchType(PSPDFActivityConfiguration.SEARCH_INLINE); else if ("SEARCH_MODULAR".equals(searchType)) builder.setSearchType(PSPDFActivityConfiguration.SEARCH_MODULAR); else throw new IllegalArgumentException(String.format("Invalid search type: %s", value)); } else if ("autosaveEnabled".equals(option)) { builder.autosaveEnabled(options.getBoolean("autosaveEnabled")); } else if ("annotationEditing".equals(option)) { final AnnotationEditingConfiguration.Builder annotationBuilder = new AnnotationEditingConfiguration.Builder( themedContext); final JSONObject annotationEditing = options.getJSONObject("annotationEditing"); final Iterator<String> annotationOptionIterator = annotationEditing.keys(); while (annotationOptionIterator.hasNext()) { final String annotationEditingOption = annotationOptionIterator.next(); final Object annotationEditingValue = annotationEditing.get(annotationEditingOption); if ("enabled".equals(annotationEditingOption)) { if ((Boolean) annotationEditingValue) annotationBuilder.enableAnnotationEditing(); else annotationBuilder.disableAnnotationEditing(); } else if ("creatorName".equals(annotationEditingOption)) { annotationBuilder.defaultAnnotationCreator( fromJsonString(annotationEditing.getString("creatorName"))); } else { throw new IllegalArgumentException(String .format("Invalid annotation editing option '%s'", annotationEditingOption)); } } builder.annotationEditingConfiguration(annotationBuilder.build()); } else { throw new IllegalArgumentException(String.format("Invalid plugin option '%s'", option)); } } catch (Exception ex) { throw new PSPDFCordovaPluginException(String.format("Error while parsing option '%s'", option), ex); } } return builder.build(); }
From source file:net.sf.sprockets.app.NavigationDrawerToggle.java
/** * Manage the Activity's ActionBar and listen for navigation drawer events on the DrawerLayout. *//*from w w w. j ava 2 s .c o m*/ public NavigationDrawerToggle(Activity activity, DrawerLayout layout) { super(activity, layout, R.drawable.ic_drawer, R.string.open_navigation_drawer, R.string.close_navigation_drawer); mActivity = activity; mLayout = layout; mApp = activity.getPackageManager().getApplicationLabel(activity.getApplicationInfo()); mActionBar = activity.getActionBar(); mActionBar.setDisplayHomeAsUpEnabled(true); layout.setDrawerShadow(R.drawable.drawer_shadow, START); layout.setDrawerListener(this); }
From source file:com.schedjoules.eventdiscovery.framework.actions.ShareActionExecutable.java
@Override public void execute(@NonNull Activity activity) { new InsightsTask(activity).execute(new ActionInteraction(mLink, mEvent)); String eventText = eventText(activity); Intent sendIntent = ShareCompat.IntentBuilder.from(activity).setText(eventText).setType("text/plain") .setChooserTitle(R.string.schedjoules_action_share_chooser_title).createChooserIntent(); if (sendIntent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(sendIntent); } else {/*from ww w .jav a 2 s . co m*/ Toast.makeText(activity, R.string.schedjoules_action_cannot_handle_message, Toast.LENGTH_LONG).show(); } }