List of usage examples for android.app Activity getPackageManager
@Override
public PackageManager getPackageManager()
From source file:com.deltadna.android.sdk.ads.core.AdServiceImpl.java
AdServiceImpl(Activity activity, AdServiceListener listener, String sdkVersion) { Preconditions.checkArg(activity != null, "activity cannot be null"); Preconditions.checkArg(listener != null, "listener cannot be null"); Log.d(BuildConfig.LOG_TAG, "Initialising AdService version " + VERSION); String version = ""; int versionCode = -1; try {// www.jav a 2s . com final PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0); version = info.versionName; versionCode = info.versionCode; } catch (PackageManager.NameNotFoundException e) { Log.w(BuildConfig.LOG_TAG, "Failed to read app versions", e); } exceptionHandler = new ExceptionHandler(activity.getApplicationContext(), version, versionCode, sdkVersion, BuildConfig.VERSION_NAME); Thread.setDefaultUncaughtExceptionHandler(exceptionHandler); this.activity = activity; this.listener = MainThread.redirect(listener, AdServiceListener.class); metrics = new AdMetrics( activity.getSharedPreferences(Preferences.METRICS.preferencesName(), Context.MODE_PRIVATE)); broadcasts = LocalBroadcastManager.getInstance(activity.getApplicationContext()); adAgentListeners = Collections .unmodifiableSet(new HashSet<>(Arrays.asList(new AgentListener(), new Broadcaster()))); // dynamically load the DebugReceiver try { @SuppressWarnings("unchecked") final Class<BroadcastReceiver> cls = (Class<BroadcastReceiver>) Class .forName("com.deltadna.android.sdk.ads.debug.DebugReceiver"); broadcasts.registerReceiver(cls.newInstance(), Actions.FILTER); Log.d(BuildConfig.LOG_TAG, "DebugReceiver registered"); } catch (ClassNotFoundException ignored) { Log.d(BuildConfig.LOG_TAG, "DebugReceiver not found in classpath"); } catch (IllegalAccessException e) { Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e); } catch (InstantiationException e) { Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e); } }
From source file:com.saulcintero.moveon.fragments.History.java
public static void sendAction(final Activity act, int[] idList, String[] nameList, String[] activityList, String[] shortDescriptionList, String[] longDescriptionList) { ArrayList<Integer> positions = new ArrayList<Integer>(); for (int p = 0; p < idList.length; p++) { String nameToSearch = osmFilesNameFromUploadPosition.get(p).substring(0, osmFilesNameFromUploadPosition.get(p).length() - 4); positions.add(ArrayUtils.indexOf(listOfFiles, nameToSearch)); }//from www.ja va2s . c o m for (int j = 0; j < idList.length; j++) { final String name = nameList[j]; final String activity = activityList[j]; final String shortDescription = shortDescriptionList[j]; final String longDescription = longDescriptionList[j]; final String url = osmUrlsToShare.get(positions.get(j)); Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); sendIntent.setType("text/plain"); List<ResolveInfo> activities = act.getPackageManager().queryIntentActivities(sendIntent, 0); AlertDialog.Builder builder = new AlertDialog.Builder(act); builder.setTitle(act.getText(R.string.send_to) + " " + name + " " + act.getText(R.string.share_with)); final ShareIntentListAdapter adapter = new ShareIntentListAdapter(act, R.layout.social_share, activities.toArray()); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ResolveInfo info = (ResolveInfo) adapter.getItem(which); if (info.activityInfo.packageName.contains("facebook")) { Intent i = new Intent("android.intent.action.PUBLISH_TO_FB_WALL"); i.putExtra("name", activity + " " + name); i.putExtra("msg", String.format("%s", shortDescription)); i.putExtra("link", String.format("%s", url)); act.sendBroadcast(i); } else { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); intent.setType("text/plain"); if ((info.activityInfo.packageName.contains("twitter")) || (info.activityInfo.packageName.contains("sms")) || (info.activityInfo.packageName.contains("mms"))) { intent.putExtra(Intent.EXTRA_TEXT, shortDescription + url); } else { intent.putExtra(Intent.EXTRA_TEXT, longDescription + url); } act.startActivity(intent); } } }); builder.create().show(); } }
From source file:de.baumann.browser.helper.helper_webView.java
public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout, final WebView webView, final EditText editText) { webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); swipeRefreshLayout.setRefreshing(false); editText.setText(webView.getTitle()); if (webView.getTitle() != null && !webView.getTitle().equals("about:blank")) { try { final Database_History db = new Database_History(from); db.addBookmark(webView.getTitle(), webView.getUrl()); db.close();/* w ww . j a va 2s . co m*/ } catch (Exception e) { e.printStackTrace(); } } } @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { final Uri uri = Uri.parse(url); return handleUri(uri); } @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final Uri uri = request.getUrl(); return handleUri(uri); } private boolean handleUri(final Uri uri) { Log.i(TAG, "Uri =" + uri); final String url = uri.toString(); // Based on some condition you need to determine if you are going to load the url // in your web view itself or in a browser. // You can use `host` or `scheme` or any part of the `uri` to decide. if (url.startsWith("http")) return false;//open web links as usual //try to find browse activity to handle uri Uri parsedUri = Uri.parse(url); PackageManager packageManager = from.getPackageManager(); Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri); if (browseIntent.resolveActivity(packageManager) != null) { from.startActivity(browseIntent); return true; } //if not activity found, try to parse intent:// if (url.startsWith("intent:")) { try { Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); if (intent.resolveActivity(from.getPackageManager()) != null) { from.startActivity(intent); return true; } //try to find fallback url String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { webView.loadUrl(fallbackUrl); return true; } //invite to install Intent marketIntent = new Intent(Intent.ACTION_VIEW) .setData(Uri.parse("market://details?id=" + intent.getPackage())); if (marketIntent.resolveActivity(packageManager) != null) { from.startActivity(marketIntent); return true; } } catch (URISyntaxException e) { //not an intent uri } } return true;//do nothing in other cases } }); }
From source file:com.afwsamples.testdpc.SetupManagementFragment.java
private void maybeLaunchProvisioning(String intentAction, int requestCode) { Activity activity = getActivity(); Intent intent = new Intent(intentAction); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, DeviceAdminReceiver.getComponentName(getActivity())); } else {/* w ww. j a v a 2 s . co m*/ intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, getActivity().getPackageName()); } if (!maybeSpecifyNExtras(intent)) { // Unable to handle user-input - can't continue. return; } PersistableBundle adminExtras = new PersistableBundle(); maybeSpecifySyncAuthExtras(intent, adminExtras); maybePassAffiliationIds(intent, adminExtras); specifySkipUserConsent(intent); specifyKeepAccountMigrated(intent); specifySkipEncryption(intent); specifyDefaultDisclaimers(intent); if (adminExtras.size() > 0) { intent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, adminExtras); } if (intent.resolveActivity(activity.getPackageManager()) != null) { startActivityForResult(intent, requestCode); } else { Toast.makeText(activity, R.string.provisioning_not_supported, Toast.LENGTH_SHORT).show(); } }
From source file:com.salmannazir.filemanager.businesslogic.EventHandler.java
private void showNewImageCreateDialog(final Activity mContext, final String directory) { boolean wrapInScrollView = true; new MaterialDialog.Builder(mContext).title("Create New Image File") .customView(R.layout.new_image_layout, wrapInScrollView).positiveText("Capture Image") .negativeText("Cancel").onPositive(new MaterialDialog.SingleButtonCallback() { @Override/* www . j ava 2 s.c o m*/ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { // TODO Toast.makeText(mContext, "+ve Clicked", Toast.LENGTH_SHORT).show(); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (cameraIntent.resolveActivity(mContext.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { EditText imageNameEditText = (EditText) dialog.findViewById(R.id.image_name); photoFile = createImageFile(imageNameEditText.getText().toString(), directory); } catch (IOException ex) { // Error occurred while creating the File Log.i("MainActivity", "IOException"); } // Continue only if the File was successfully created if (photoFile != null) { cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); mContext.startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST); } } } }).show(); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
public static void launchSMB(final HybridFileParcelable baseFile, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*/* w w w .j a va2s. com*/ List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(new SmbFile(baseFile.getPath()), baseFile.getSize()); activity.runOnUiThread(() -> { try { Uri uri = Uri.parse(Streamer.URL + Uri .fromFile(new File(Uri.parse(baseFile.getPath()).getPath())).getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java
/** * {@inheritDoc}/* ww w. ja va 2s . c o m*/ */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Activity activity = getActivity(); // Get references to required resources. locMan = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE); sp = activity.getSharedPreferences(PreferencesActivity.PREF_FILE, 0); bsd = BusStopDatabase.getInstance(activity.getApplicationContext()); sd = SettingsDatabase.getInstance(activity.getApplicationContext()); // Create the ArrayAdapter for the ListView. ad = new NearestStopsArrayAdapter(activity); // Initialise the services chooser Dialog. services = bsd.getBusServiceList(); if (savedInstanceState != null) { chosenServices = savedInstanceState.getStringArray(ARG_CHOSEN_SERVICES); } else { // Check to see if GPS is enabled then check to see if the GPS // prompt dialog has been disabled. if (!locMan.isProviderEnabled(LocationManager.GPS_PROVIDER) && !sp.getBoolean(PreferencesActivity.PREF_DISABLE_GPS_PROMPT, false)) { // Get the list of Activities which can handle the enabling of // location services. final List<ResolveInfo> packages = activity.getPackageManager() .queryIntentActivities(TurnOnGpsDialogFragment.TURN_ON_GPS_INTENT, 0); // If the list is not empty, this means Activities do exist. // Show Dialog asking users if they want to turn on GPS. if (packages != null && !packages.isEmpty()) { callbacks.onAskTurnOnGps(); } } } // Tell the underlying Activity that this Fragment contains an options // menu. setHasOptionsMenu(true); }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public static void launchSMB(final SmbFile smbFile, final long si, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*/*from ww w.j a va 2 s. c o m*/ List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(smbFile, si); activity.runOnUiThread(new Runnable() { public void run() { try { Uri uri = Uri.parse(Streamer.URL + Uri.fromFile(new File(Uri.parse(smbFile.getPath()).getPath())) .getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(new File(smbFile.getPath()))); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static boolean application_isCallable(Activity activity, Intent intent) { List<ResolveInfo> list = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:de.mrapp.android.bottomsheet.BottomSheet.java
/** * Adds the apps, which are able to handle a specific intent, as items to the bottom sheet. This * causes all previously added items to be removed. When an item is clicked, the corresponding * app is started.//from w w w. ja va 2s .co m * * @param activity * The activity, the bottom sheet belongs to, as an instance of the class {@link * Activity}. The activity may not be null * @param intent * The intent as an instance of the class {@link Intent}. The intent may not be null */ public final void setIntent(@NonNull final Activity activity, @NonNull final Intent intent) { ensureNotNull(activity, "The activity may not be null"); ensureNotNull(intent, "The intent may not be null"); removeAllItems(); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0); for (int i = 0; i < resolveInfos.size(); i++) { ResolveInfo resolveInfo = resolveInfos.get(i); addItem(i, resolveInfo.loadLabel(packageManager), resolveInfo.loadIcon(packageManager)); } setOnItemClickListener(createIntentClickListener(activity, (Intent) intent.clone(), resolveInfos)); }