List of usage examples for android.content ComponentName unflattenFromString
public static @Nullable ComponentName unflattenFromString(@NonNull String str)
From source file:Main.java
public static boolean checkNotificationReadPermission(Activity activity) { String notiStr = Settings.Secure.getString(activity.getContentResolver(), "enabled_notification_listeners"); if (notiStr != null && !TextUtils.isEmpty(notiStr)) { final String[] names = notiStr.split(":"); for (String name : names) { ComponentName cn = ComponentName.unflattenFromString(name); if (cn != null) { if (activity.getPackageName().equals(cn.getPackageName())) { return true; }/*ww w . j a va 2 s.co m*/ } } } return false; }
From source file:Main.java
public static boolean isAccessibilityServiceEnabled(Context context, Class<? extends AccessibilityService> accessibilityService) { ComponentName expectedComponentName = new ComponentName(context, accessibilityService); String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (enabledServicesSetting == null) return false; TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':'); colonSplitter.setString(enabledServicesSetting); while (colonSplitter.hasNext()) { String componentNameString = colonSplitter.next(); ComponentName enabledService = ComponentName.unflattenFromString(componentNameString); if (enabledService != null && enabledService.equals(expectedComponentName)) return true; }//from w w w .j ava2 s. c om return false; }
From source file:Main.java
/** * Compose PhoneAccount object from component name and account id. *///from w ww.j ava 2 s. co m public static PhoneAccountHandle getAccount(String componentString, String accountId) { if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { return null; } final ComponentName componentName = ComponentName.unflattenFromString(componentString); return new PhoneAccountHandle(componentName, accountId); }
From source file:Main.java
/** * Gets the service./*from w ww. j a va 2 s. c om*/ * * @param intent * the intent * * @return the service */ public static ComponentName getService(Intent intent) { String name = intent.getExtras().getString(SERVICE_KEY); if (name == null) return null; return ComponentName.unflattenFromString(name); }
From source file:com.google.android.apps.dashclock.ExtensionSettingActivityProxy.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_Translucent_NoTitleBar); mExtension = getIntent().getStringExtra(DashClockService.EXTRA_COMPONENT_NAME); String activity = getIntent().getStringExtra(EXTRA_SETTINGS_ACTIVITY); if (mExtension == null || activity == null) { finish();//from ww w . j a v a 2 s . c o m return; } try { Intent i = new Intent(); i.setComponent(ComponentName.unflattenFromString(activity)); startActivityForResult(i, RESULT_EXTENSION_SETTINGS); } catch (ActivityNotFoundException ex) { finish(); } }
From source file:com.phonegap.plugins.startapp.StartApp.java
/** * Starts an activity./*from w w w. ja va2s.co m*/ * * @param component * Activity ComponentName. * E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity */ void startActivity(String component) { Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.setComponent(ComponentName.unflattenFromString(component)); this.ctx.startActivity(intent); }
From source file:org.deviceconnect.message.intent.impl.io.IntentHttpMessageWriter.java
@Override public void write(final HttpMessage message) throws IOException, HttpException { mLogger.entering(getClass().getName(), "write"); DConnectMessage dmessage = HttpMessageFactory.getMessageFactory().newDConnectMessage(message); Intent intent = IntentMessageFactory.getMessageFactory().newPackagedMessage(dmessage); // put intent optional extras Header host = message.getFirstHeader(HttpHeaders.HOST); if (host != null) { intent.setComponent(ComponentName.unflattenFromString(host.getValue())); }/*from www .j a v a 2 s . com*/ intent.putExtra(DConnectMessage.EXTRA_RECEIVER, new ComponentName(mContext, IntentResponseReceiver.class)); // send broadcast mLogger.fine("send request broadcast: " + intent); mLogger.fine("send request extra: " + intent.getExtras()); mContext.sendBroadcast(intent); mLogger.exiting(getClass().getName(), "write"); }
From source file:com.byhook.cordova.chromelauncher.ChromeLauncher.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 context used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//* w w w . java 2 s .c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("open")) { String url = args.getString(0); Intent i = new Intent("android.intent.action.MAIN"); i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main")); i.addCategory("android.intent.category.LAUNCHER"); i.setData(Uri.parse(url)); ((Activity) cordova).startActivity(i); } else if (action.equals("checkInstall")) { if (isInstalled("com.android.chrome")) { callbackContext.sendPluginResult(new PluginResult(status, true)); return true; } else { status = PluginResult.Status.ERROR; callbackContext.sendPluginResult(new PluginResult(status, false)); return true; } } else if (action.equals("openStore")) { Uri marketUri = Uri.parse("market://details?id=com.android.chrome"); Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); ((Activity) cordova).startActivity(marketIntent); } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:org.mariotaku.twidere.util.ExternalThemeManager.java
public void reloadEmojiPreferences() { final String emojiComponentName = preferences.getString(KEY_EMOJI_SUPPORT, null); if (emojiComponentName != null) { final ComponentName componentName = ComponentName.unflattenFromString(emojiComponentName); if (componentName != null) { emojiPackageName = componentName.getPackageName(); } else {/*from ww w .j av a 2 s. c o m*/ emojiPackageName = null; } } else { emojiPackageName = null; } initEmojiSupport(); }
From source file:com.cordova.plugins.startapp.StartApp.java
/** * Starts an activity./* w ww.ja va2 s.co m*/ * * @param component * Activity ComponentName. * E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity */ void startActivity(String component) { try { Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.setComponent(ComponentName.unflattenFromString(component)); ((DroidGap) this.cordova.getActivity()).startActivity(intent); } catch (ActivityNotFoundException ex) { /** * If not installed, open market */ String[] packageNameSplt = component.split("/"); String packageName = packageNameSplt[0]; Intent marketIntent = new Intent(Intent.ACTION_VIEW); marketIntent.setData(Uri.parse("market://details?id=" + packageName)); ((DroidGap) this.cordova.getActivity()).startActivity(marketIntent); } }