List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java
private void _open(String url, String contentType, String packageId, String activity, CallbackContext callbackContext, Bundle viewerOptions) throws JSONException { clearTempFiles();// www .j a va 2 s.c om File file = getAccessibleFile(url); if (file != null && file.exists() && file.isFile()) { try { Intent intent = new Intent(Intent.ACTION_VIEW); Uri path = Uri.fromFile(file); // @see http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent intent.addCategory(Intent.CATEGORY_EMBED); intent.setDataAndType(path, contentType); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(this.getClass().getName(), viewerOptions); //activity needs fully qualified name here intent.setComponent(new ComponentName(packageId, packageId + "." + activity)); this.callbackContext = callbackContext; this.cordova.startActivityForResult(this, intent, REQUEST_CODE_OPEN); // send shown event JSONObject successObj = new JSONObject(); successObj.put(Result.STATUS, PluginResult.Status.OK.ordinal()); PluginResult result = new PluginResult(PluginResult.Status.OK, successObj); // need to keep callback for close event result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (android.content.ActivityNotFoundException e) { JSONObject errorObj = new JSONObject(); errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal()); errorObj.put(Result.MESSAGE, "Activity not found: " + e.getMessage()); callbackContext.error(errorObj); } } else { JSONObject errorObj = new JSONObject(); errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal()); errorObj.put(Result.MESSAGE, "File not found"); callbackContext.error(errorObj); } }
From source file:com.google.android.apps.dashclock.ExtensionManager.java
/** * Returns a listing of all available (installed) extensions, including those that aren't * world-readable.// w w w. j av a 2 s . c o m */ public List<ExtensionListing> getAvailableExtensions() { List<ExtensionListing> availableExtensions = new ArrayList<>(); PackageManager pm = mApplicationContext.getPackageManager(); List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(DashClockExtension.ACTION_EXTENSION), PackageManager.GET_META_DATA); for (ResolveInfo resolveInfo : resolveInfos) { ExtensionListing info = new ExtensionListing(); info.componentName( new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name)); info.title(resolveInfo.loadLabel(pm).toString()); Bundle metaData = resolveInfo.serviceInfo.metaData; if (metaData != null) { info.compatible(ExtensionHost.supportsProtocolVersion(metaData.getInt("protocolVersion"))); info.worldReadable(metaData.getBoolean("worldReadable", false)); info.description(metaData.getString("description")); String settingsActivity = metaData.getString("settingsActivity"); if (!TextUtils.isEmpty(settingsActivity)) { info.settingsActivity(ComponentName .unflattenFromString(resolveInfo.serviceInfo.packageName + "/" + settingsActivity)); } } info.icon(resolveInfo.getIconResource()); availableExtensions.add(info); } return availableExtensions; }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Check if ads should be hidden./*from ww w.ja v a 2 s .co m*/ * * @param context * {@link Context} * @return true if ads should be hidden */ public static boolean hideAds(final Context context) { PackageManager pm = context.getPackageManager(); Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK); ResolveInfo ri = pm.resolveService(donationCheck, 0); // Log.d(TAG, "ri: " + ri); int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE; if (ri != null) { Log.d(TAG, "found package: " + ri.serviceInfo.packageName); ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); // Log.d(TAG, "component name: " + cn); int i = pm.getComponentEnabledSetting(cn); // Log.d(TAG, "component status: " + i); // Log.d(TAG, "package status: " + ri.serviceInfo.enabled); if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) { match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName); } else { Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled); } } Log.i(TAG, "signature match: " + match); if (match != PackageManager.SIGNATURE_UNKNOWN_PACKAGE) { if (Math.random() < CHECK_DONATOR_LIC) { // verify donator license ComponentName cn = context.startService(donationCheck); Log.d(TAG, "Started service: " + cn); if (cn == null) { return false; } } return match == PackageManager.SIGNATURE_MATCH; } pm = null; // no donator app installed, check donation traditionally // do not drop legacy donators boolean ret = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_HIDEADS, false); Log.d(TAG, "legacy donation check: " + ret); return ret; }
From source file:me.kartikarora.transfersh.activities.TransferActivity.java
public void updateWidgets() { Intent intent = new Intent(TransferActivity.this, FilesAppWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); AppWidgetManager widgetManager = AppWidgetManager.getInstance(getApplicationContext()); int[] ids = widgetManager .getAppWidgetIds(new ComponentName(getApplicationContext(), FilesAppWidgetProvider.class)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); sendBroadcast(intent);/*w w w . j av a 2 s . c o m*/ }
From source file:com.wso2.mobile.mdm.services.Operation.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void revokePolicy() { String policy;/*from w w w . j av a2 s . c o m*/ JSONArray jArray = null; devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); try { policy = mainPref.getString("policy", ""); jArray = new JSONArray(policy); for (int i = 0; i < jArray.length(); i++) { if (jArray.getJSONObject(i) != null) { JSONObject policyObj = (JSONObject) jArray.getJSONObject(i); if (policyObj.getString("data") != null && policyObj.getString("data") != "") { if (policyObj.getString("code").trim().equals(CommonUtilities.OPERATION_WIFI)) { JSONObject jobj = new JSONObject(policyObj.getString("data")); if (!jobj.isNull("ssid")) { String rev_ssid = (String) jobj.get("ssid"); WiFiConfig config = new WiFiConfig(context); config.removeWiFiConfigurationBySSID(rev_ssid); } } else if (policyObj.getString("code").trim() .equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setCameraDisabled(cameraAdmin, false); } } else if (policyObj.getString("code").trim() .equals(CommonUtilities.OPERATION_ENCRYPT_STORAGE)) { JSONObject jobj = new JSONObject(policyObj.getString("data")); boolean encryptFunc = false; if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("encrypt")) { encryptFunc = true; } else if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("decrypt")) { encryptFunc = false; } else if (!jobj.isNull("function")) { encryptFunc = Boolean.parseBoolean(jobj.get("function").toString()); } if (encryptFunc) { if (devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE || devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setStorageEncryption(cameraAdmin, false); } } } } } else if (policyObj.getString("code").trim() .equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) { devicePolicyManager.setPasswordQuality(cameraAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); } } } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.vyasware.vaani.MainActivity.java
private void doOpen(String[] sentence) { System.out.println("open"); for (String word : sentence) { switch (word) { //? ??? case "?": case "facebook": //open facebook Intent fbintent = new Intent(); fbintent.setAction(Intent.ACTION_VIEW); fbintent.setData(android.net.Uri.parse("http://www.facebook.com")); startActivity(fbintent);/*from w ww .j a v a 2 s .c om*/ break; case "whatsapp": case "???": //todo run whatsapp break; case "camera": case "": case "": //open camera Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); try { PackageManager pm = getPackageManager(); final ResolveInfo mInfo = pm.resolveActivity(i, 0); Intent intent = new Intent(); intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name)); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(intent); } catch (Exception e) { Log.i("open", "Unable to launch camera: " + e); } break; case "browser": case "?": // open browser Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(android.net.Uri.parse("http://www.google.com")); startActivity(intent); break; case "youtube": case "???": //run youtube Intent ytintent = new Intent(); ytintent.setAction(Intent.ACTION_VIEW); ytintent.setData(android.net.Uri.parse("http://www.youtube.com")); startActivity(ytintent); break; } } }
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * Prepares the MediaPlayer objects for first use * and starts the service. The workflow of the entire * service starts here.//w w w .j av a 2 s. com * * @param intent Calling intent. * @param flags Service flags. * @param startId Service start ID. */ @SuppressLint("NewApi") @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); //Context. mContext = getApplicationContext(); mService = this; mHandler = new Handler(); mApp = (Common) getApplicationContext(); mApp.setService((AudioPlaybackService) this); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); //Initialize Google Analytics. //initGoogleAnalytics(); //Initialize the MediaPlayer objects. initMediaPlayers(); //Time to play nice with other music players (and audio apps) and request audio focus. mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioManagerHelper = new AudioManagerHelper(); // Request audio focus for playback mAudioManagerHelper.setHasAudioFocus(requestAudioFocus()); //Grab the crossfade duration for this session. mCrossfadeDuration = mApp.getCrossfadeDuration(); //Initialize audio effects (equalizer, virtualizer, bass boost) for this session. initAudioFX(); mMediaButtonReceiverComponent = new ComponentName(this.getPackageName(), HeadsetButtonsReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (mApp.getSharedPreferences().getBoolean(Common.SHOW_LOCKSCREEN_CONTROLS, true) == true) { initRemoteControlClient(); } mApp.getPlaybackKickstarter().setBuildCursorListener(buildCursorListener); //The service has been successfully started. setPrepareServiceListener(mApp.getPlaybackKickstarter()); getPrepareServiceListener().onServiceRunning(this); return START_STICKY; }
From source file:androidx.media.session.MediaButtonReceiver.java
/** * @hide//from ww w .j a va 2 s. c om */ @RestrictTo(LIBRARY) public static ComponentName getMediaButtonReceiverComponent(Context context) { Intent queryIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); queryIntent.setPackage(context.getPackageName()); PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfos = pm.queryBroadcastReceivers(queryIntent, 0); if (resolveInfos.size() == 1) { ResolveInfo resolveInfo = resolveInfos.get(0); return new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); } else if (resolveInfos.size() > 1) { Log.w(TAG, "More than one BroadcastReceiver that handles " + Intent.ACTION_MEDIA_BUTTON + " was found, returning null."); } return null; }
From source file:com.androidzeitgeist.dashwatch.dashclock.ExtensionManager.java
/** * Returns a listing of all available (installed) extensions. *//*from w w w. j a v a2 s .c o m*/ public List<ExtensionListing> getAvailableExtensions() { List<ExtensionListing> availableExtensions = new ArrayList<ExtensionListing>(); PackageManager pm = mApplicationContext.getPackageManager(); List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(DashClockExtension.ACTION_EXTENSION), PackageManager.GET_META_DATA); for (ResolveInfo resolveInfo : resolveInfos) { ExtensionListing listing = new ExtensionListing(); listing.componentName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name); listing.title = resolveInfo.loadLabel(pm).toString(); Bundle metaData = resolveInfo.serviceInfo.metaData; if (metaData != null) { listing.protocolVersion = metaData.getInt("protocolVersion"); listing.worldReadable = metaData.getBoolean("worldReadable", false); listing.description = metaData.getString("description"); String settingsActivity = metaData.getString("settingsActivity"); if (!TextUtils.isEmpty(settingsActivity)) { listing.settingsActivity = ComponentName .unflattenFromString(resolveInfo.serviceInfo.packageName + "/" + settingsActivity); } } listing.icon = resolveInfo.loadIcon(pm); availableExtensions.add(listing); } return availableExtensions; }
From source file:com.android.tv.settings.MainFragment.java
private void updateAccounts() { if (mAccountsGroup == null) { return;/*from ww w .j a va 2 s. co m*/ } final Set<String> touchedAccounts = new ArraySet<>(mAccountsGroup.getPreferenceCount()); final AccountManager am = AccountManager.get(getContext()); final AuthenticatorDescription[] authTypes = am.getAuthenticatorTypes(); final ArrayList<String> allowableAccountTypes = new ArrayList<>(authTypes.length); final Context themedContext = getPreferenceManager().getContext(); for (AuthenticatorDescription authDesc : authTypes) { final Context targetContext; try { targetContext = getContext().createPackageContext(authDesc.packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Authenticator description with bad package name", e); continue; } catch (SecurityException e) { Log.e(TAG, "Security exception loading package resources", e); continue; } // Main title text comes from the authenticator description (e.g. "Google"). String authTitle = null; try { authTitle = targetContext.getString(authDesc.labelId); if (TextUtils.isEmpty(authTitle)) { authTitle = null; // Handled later when we add the row. } } catch (Resources.NotFoundException e) { Log.e(TAG, "Authenticator description with bad label id", e); } // There exist some authenticators which aren't intended to be user-facing. // If the authenticator doesn't have a title or an icon, don't present it to // the user as an option. if (authTitle != null || authDesc.iconId != 0) { allowableAccountTypes.add(authDesc.type); } Account[] accounts = am.getAccountsByType(authDesc.type); if (accounts == null || accounts.length == 0) { continue; // No point in continuing; there aren't any accounts to show. } // Icon URI to be displayed for each account is based on the type of authenticator. Drawable authImage = null; try { authImage = targetContext.getDrawable(authDesc.iconId); } catch (Resources.NotFoundException e) { Log.e(TAG, "Authenticator has bad resources", e); } // Display an entry for each installed account we have. for (final Account account : accounts) { final String key = "account_pref:" + account.type + ":" + account.name; Preference preference = findPreference(key); if (preference == null) { preference = new Preference(themedContext); } preference.setTitle(authTitle != null ? authTitle : account.name); preference.setIcon(authImage); preference.setSummary(authTitle != null ? account.name : null); preference.setFragment(AccountSyncFragment.class.getName()); AccountSyncFragment.prepareArgs(preference.getExtras(), account); touchedAccounts.add(key); preference.setKey(key); mAccountsGroup.addPreference(preference); } } for (int i = 0; i < mAccountsGroup.getPreferenceCount();) { final Preference preference = mAccountsGroup.getPreference(i); final String key = preference.getKey(); if (touchedAccounts.contains(key) || TextUtils.equals(KEY_ADD_ACCOUNT, key)) { i++; } else { mAccountsGroup.removePreference(preference); } } // Never allow restricted profile to add accounts. final Preference addAccountPref = findPreference(KEY_ADD_ACCOUNT); if (addAccountPref != null) { addAccountPref.setOrder(Integer.MAX_VALUE); if (isRestricted()) { addAccountPref.setVisible(false); } else { Intent i = new Intent().setComponent(new ComponentName("com.android.tv.settings", "com.android.tv.settings.accounts.AddAccountWithTypeActivity")); i.putExtra(AddAccountWithTypeActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY, allowableAccountTypes.toArray(new String[allowableAccountTypes.size()])); // If there are available account types, show the "add account" button. addAccountPref.setVisible(!allowableAccountTypes.isEmpty()); addAccountPref.setIntent(i); } } }