Java Code Examples for android.content.Intent#resolveActivityInfo()

The following examples show how to use android.content.Intent#resolveActivityInfo() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void addToIntent(Intent containerIntent, Context context) {
    Intent focusIntent = new Intent(context, FocusActivity.class);

    // This class may not be included in app's manifest, don't add it in that case.
    if (mActivityExistsCached == null) {
        mActivityExistsCached =
                focusIntent.resolveActivityInfo(context.getPackageManager(), 0) != null;
    }
    if (Boolean.FALSE.equals(mActivityExistsCached)) return;

    // This Intent will be launched from the background so we need NEW_TASK, however if an
    // existing task is suitable, that will be brought to the foreground despite the name of the
    // flag.
    focusIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    containerIntent.putExtra(EXTRA_FOCUS_INTENT,
            PendingIntent.getActivity(context, 0, focusIntent, 0));
}
 
Example 2
private void startActivity(Intent i, boolean bExpectResult,  int requestCode, CallbackContext callbackContext) {

        if (i.resolveActivityInfo(this.cordova.getActivity().getPackageManager(), 0) != null)
        {
            if (bExpectResult)
            {
                cordova.setActivityResultCallback(this);
               this.cordova.getActivity().startActivityForResult(i, requestCode);
            }
            else
            {
                this.cordova.getActivity().startActivity(i);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
            }
        }
        else
        {
            //  Return an error as there is no app to handle this intent
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
        }
    }
 
Example 3
protected void searchWebFor(String... keys) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String key : keys) {
        stringBuilder.append(key);
        stringBuilder.append(" ");
    }
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, stringBuilder.toString());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Start search intent if possible: https://stackoverflow.com/questions/36592450/unexpected-intent-with-action-web-search
    if (Intent.ACTION_WEB_SEARCH.equals(intent.getAction()) && intent.getExtras() != null) {
        String query = intent.getExtras().getString(SearchManager.QUERY, null);
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q="+query));
        boolean browserExists = intent.resolveActivityInfo(getPackageManager(), 0) != null;
        if (browserExists && query != null) {
            startActivity(browserIntent);
            return;
        }
    }

    Toast.makeText(this, R.string.error_no_app_for_intent, Toast.LENGTH_LONG).show();
}
 
Example 4
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar base clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    }

    if (id == R.id.action_show_folder) {
        Uri selectedUri = Uri.fromFile(storage.getStoragePath());
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(selectedUri, "resource/folder");
        if (intent.resolveActivityInfo(getPackageManager(), 0) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.no_folder_app, Toast.LENGTH_SHORT).show();
        }
    }

    return super.onOptionsItemSelected(item);
}
 
Example 5
Source Project: Taskbar   File: U.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N)
public static void applyOpenInNewWindow(Context context, Intent intent) {
    if(!isFreeformModeEnabled(context)) return;

    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

    ActivityInfo activityInfo = intent.resolveActivityInfo(context.getPackageManager(), 0);
    if(activityInfo != null) {
        switch(activityInfo.launchMode) {
            case ActivityInfo.LAUNCH_SINGLE_TASK:
            case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
                intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
                break;
        }
    }
}
 
Example 6
Source Project: SMP   File: Main.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void openSongFolder(View view) {
    final RowSong song = rows.getCurrSong();
    if (song == null) {
        // err msg ?
        return;
    }

    Uri selectedUri = Uri.fromFile(new File(song.getPath()).getParentFile());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(selectedUri, "resource/folder");

    if (intent.resolveActivityInfo(getPackageManager(), 0) != null) {
        startActivity(intent);
    }
    else {
        Toast.makeText(getApplicationContext(),
                "no file explorer app installed on your device", Toast.LENGTH_LONG).show();
    }
}
 
Example 7
Source Project: SMP   File: Main.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void openSongFolder(View view) {
    final RowSong song = rows.getCurrSong();
    if (song == null) {
        // err msg ?
        return;
    }

    Uri selectedUri = Uri.fromFile(new File(song.getPath()).getParentFile());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(selectedUri, "resource/folder");

    if (intent.resolveActivityInfo(getPackageManager(), 0) != null) {
        startActivity(intent);
    }
    else {
        Toast.makeText(getApplicationContext(),
                "no file explorer app installed on your device", Toast.LENGTH_LONG).show();
    }
}
 
Example 8
public final ActivityInfo resolveActivityInfo(Intent intent) {
    ActivityInfo aInfo = intent.resolveActivityInfo(
            mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES);
    if (aInfo == null) {
        // Throw an exception.
        Instrumentation.checkStartActivityResult(
                ActivityManager.START_CLASS_NOT_FOUND, intent);
    }
    return aInfo;
}
 
Example 9
public final ActivityInfo resolveActivityInfo(Intent intent) {
    ActivityInfo aInfo = intent.resolveActivityInfo(
            mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES);
    if (aInfo == null) {
        // Throw an exception.
        Instrumentation.checkStartActivityResult(
                IActivityManager.START_CLASS_NOT_FOUND, intent);
    }
    return aInfo;
}
 
Example 10
public static void launchWifiSettings(Context context) {
    // context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
    Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (intent.resolveActivityInfo(context.getPackageManager(), 0) != null) {
        context.startActivity(intent);
    }
}
 
Example 11
public static void launchHotspotSettings(Context context) {
    // context.startActivity(new Intent(WifiManager.AC));

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.TetherSettings");
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (intent.resolveActivityInfo(context.getPackageManager(), 0) != null) {
        context.startActivity(intent);
    }
}
 
Example 12
@Override
public void onClick(View v) {
    TextView textView = findViewById(v.getId());
    String result = textView.getText().toString().trim();

    Uri uri = Uri.parse(result);

    StringBuffer sb = new StringBuffer();
    sb.append("uri==").append(uri).append("\n");
    sb.append("scheme==").append(uri.getScheme()).append("\n");
    sb.append("host==").append(uri.getHost()).append("\n");
    sb.append("path==").append(uri.getPath()).append("\n");
    sb.append("pathSegment==").append(Arrays.toString(uri.getPathSegments().toArray())).append("\n");
    sb.append("query==").append(uri.getQuery()).append("\n");

    if (uri.isHierarchical()) {
        Optional.ofNullable(uri.getQueryParameterNames())
                .ifPresent(strings -> sb.append("QueryParameterNames==").append(strings.toString()).append("\n"));
    }


    Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();

    if (v.getId() == R.id.custom_scheme_and_host) {
        Intent intent = new Intent();
        intent.setAction("my_action");
        intent.setData(Uri.parse(result));
        ActivityInfo activityInfo = intent.resolveActivityInfo(getPackageManager(), PackageManager.MATCH_DEFAULT_ONLY);
        Optional.ofNullable(activityInfo)
                .ifPresent( activityInfo1 -> {
                    startActivity(intent);});
    }

}
 
Example 13
Source Project: Jockey   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
public static Intent getSystemEqIntent(Context c) {
    Intent systemEq = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    systemEq.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, c.getPackageName());

    ActivityInfo info = systemEq.resolveActivityInfo(c.getPackageManager(), 0);
    if (info != null && !info.name.startsWith("com.android.musicfx")) {
        return systemEq;
    } else {
        return null;
    }
}
 
Example 14
/** Starts an Activity using the given intent. */
@Override
public void startActivity(Intent intent, @Nullable Bundle activityOptions) {
  // make sure the intent can resolve an activity
  ActivityInfo ai = intent.resolveActivityInfo(getApplicationContext().getPackageManager(), 0);
  if (ai == null) {
    throw new RuntimeException("Unable to resolve activity for: " + intent);
  }
  // Close empty activities and bootstrap activity if it's running. This might happen if the
  // previous test crashes before it cleans up the state.
  getApplicationContext().sendBroadcast(new Intent(FINISH_BOOTSTRAP_ACTIVITY));
  getApplicationContext().sendBroadcast(new Intent(FINISH_EMPTY_ACTIVITIES));

  activityResultWaiter = new ActivityResultWaiter(getApplicationContext());

  // Note: Instrumentation.startActivitySync(Intent) cannot be used here because BootstrapActivity
  // may start in different process. Also, we use PendingIntent because the target activity may
  // set "exported" attribute to false so that it prohibits starting the activity outside of their
  // package. With PendingIntent we delegate the authority to BootstrapActivity.
  getApplicationContext()
      .startActivity(
          getIntentForActivity(BootstrapActivity.class)
              .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
              .putExtra(
                  TARGET_ACTIVITY_INTENT_KEY,
                  PendingIntent.getActivity(
                      getApplicationContext(),
                      /*requestCode=*/ 0,
                      intent,
                      /*flags=*/ PendingIntent.FLAG_UPDATE_CURRENT))
              .putExtra(TARGET_ACTIVITY_OPTIONS_BUNDLE_KEY, activityOptions));
}
 
Example 15
Source Project: AndroidAll   File: IntentHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean intentAvailable(Context context, Intent intent) {
    ActivityInfo activityInfo = intent.resolveActivityInfo(context.getPackageManager(), intent.getFlags());
    return activityInfo != null && activityInfo.exported;
}
 
Example 16
String getPreferencesDescription(boolean addBullet, boolean addPassStatus, Context context)
{
    String descr = "";

    if (!this._enabled) {
        if (!addBullet)
            descr = context.getString(R.string.event_preference_sensor_application_summary);
    } else {
        if (Event.isEventPreferenceAllowed(PREF_EVENT_APPLICATION_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) {
            if (addBullet) {
                descr = descr + "<b>";
                descr = descr + getPassStatusString(context.getString(R.string.event_type_applications), addPassStatus, DatabaseHandler.ETYPE_APPLICATION, context);
                descr = descr + "</b> ";
            }

            String selectedApplications = context.getString(R.string.applications_multiselect_summary_text_not_selected);
            int extenderVersion = PPPExtenderBroadcastReceiver.isExtenderInstalled(context.getApplicationContext());
            if (extenderVersion == 0) {
                selectedApplications = context.getResources().getString(R.string.profile_preferences_device_not_allowed) +
                        ": " + context.getString(R.string.preference_not_allowed_reason_not_extender_installed);
            } else if (extenderVersion < PPApplication.VERSION_CODE_EXTENDER_3_0) {
                selectedApplications = context.getResources().getString(R.string.profile_preferences_device_not_allowed) +
                        ": " + context.getString(R.string.preference_not_allowed_reason_extender_not_upgraded);
            } else if (!PPPExtenderBroadcastReceiver.isAccessibilityServiceEnabled(context.getApplicationContext())) {
                selectedApplications = context.getResources().getString(R.string.profile_preferences_device_not_allowed) +
                        ": " + context.getString(R.string.preference_not_allowed_reason_not_enabled_accessibility_settings_for_extender);
            } else if (!this._applications.isEmpty() && !this._applications.equals("-")) {
                String[] splits = this._applications.split("\\|");
                if (splits.length == 1) {
                    String packageName = Application.getPackageName(splits[0]);
                    String activityName = Application.getActivityName(splits[0]);
                    PackageManager packageManager = context.getPackageManager();
                    if (activityName.isEmpty()) {
                        ApplicationInfo app;
                        try {
                            app = packageManager.getApplicationInfo(packageName, 0);
                            if (app != null)
                                selectedApplications = packageManager.getApplicationLabel(app).toString();
                        } catch (Exception e) {
                            selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
                        }
                    } else {
                        Intent intent = new Intent();
                        intent.setClassName(packageName, activityName);
                        ActivityInfo info = intent.resolveActivityInfo(packageManager, 0);
                        if (info != null)
                            selectedApplications = info.loadLabel(packageManager).toString();
                    }
                } else
                    selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
            }
            descr = descr + /*"(S) "+*/context.getString(R.string.event_preferences_applications_applications) + ": <b>" + selectedApplications + "</b>";

            //descr = descr + context.getString(R.string.event_preferences_notifications_applications) + ": " +selectedApplications + "; ";
            //descr = descr + context.getString(R.string.pref_event_duration) + ": " +tmp._duration;
        }
    }

    return descr;
}
 
Example 17
String getPreferencesDescription(boolean addBullet, boolean addPassStatus, Context context)
{
    String descr = "";

    if (!this._enabled) {
        if (!addBullet)
            descr = context.getString(R.string.event_preference_sensor_alarm_clock_summary);
    } else {
        if (Event.isEventPreferenceAllowed(PREF_EVENT_ALARM_CLOCK_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) {
            if (addBullet) {
                descr = descr + "<b>";
                descr = descr + getPassStatusString(context.getString(R.string.event_type_alarm_clock), addPassStatus, DatabaseHandler.ETYPE_ALARM_CLOCK, context);
                descr = descr + "</b> ";
            }

            if (this._permanentRun)
                descr = descr + "<b>" + context.getString(R.string.pref_event_permanentRun) + "</b>";
            else
                descr = descr + context.getString(R.string.pref_event_duration) + ": <b>" + GlobalGUIRoutines.getDurationString(this._duration) + "</b>";

            String selectedApplications = context.getString(R.string.applications_multiselect_summary_text_not_selected);
            if (!this._applications.isEmpty() && !this._applications.equals("-")) {
                String[] splits = this._applications.split("\\|");
                if (splits.length == 1) {
                    String packageName = Application.getPackageName(splits[0]);
                    String activityName = Application.getActivityName(splits[0]);
                    PackageManager packageManager = context.getPackageManager();
                    if (activityName.isEmpty()) {
                        ApplicationInfo app;
                        try {
                            app = packageManager.getApplicationInfo(packageName, 0);
                            if (app != null)
                                selectedApplications = packageManager.getApplicationLabel(app).toString();
                        } catch (Exception e) {
                            selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
                        }
                    } else {
                        Intent intent = new Intent();
                        intent.setClassName(packageName, activityName);
                        ActivityInfo info = intent.resolveActivityInfo(packageManager, 0);
                        if (info != null)
                            selectedApplications = info.loadLabel(packageManager).toString();
                    }
                } else
                    selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
            }

            descr = descr + " • ";
            descr = descr + /*"(S) "+*/context.getString(R.string.event_preferences_alarm_clock_applications) + ": <b>" + selectedApplications + "</b>";
        }
    }

    return descr;
}
 
Example 18
String getPreferencesDescription(boolean addBullet, boolean addPassStatus, Context context)
{
    String descr = "";

    if (!this._enabled) {
        if (!addBullet)
            descr = context.getString(R.string.event_preference_sensor_notification_summary);
    } else {
        if (Event.isEventPreferenceAllowed(PREF_EVENT_NOTIFICATION_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) {
            if (addBullet) {
                descr = descr + "<b>";
                descr = descr + getPassStatusString(context.getString(R.string.event_type_notifications), addPassStatus, DatabaseHandler.ETYPE_NOTIFICATION, context);
                descr = descr + "</b> ";
            }

            if (!PPNotificationListenerService.isNotificationListenerServiceEnabled(context)) {
                descr = descr + "* " + context.getString(R.string.event_preferences_notificationsAccessSettings_disabled_summary) + "! *";
            } else {
                //descr = descr + context.getString(R.string.event_preferences_notificationsAccessSettings_enabled_summary) + "<br>";

                if (this._inCall) {
                    descr = descr + "<b>" + context.getString(R.string.event_preferences_notifications_inCall) + "</b>";
                }
                if (this._missedCall) {
                    if (this._inCall)
                        descr = descr + " • ";
                    descr = descr + "<b>" +context.getString(R.string.event_preferences_notifications_missedCall) + "</b>";
                }
                String selectedApplications = context.getString(R.string.applications_multiselect_summary_text_not_selected);
                if (!this._applications.isEmpty() && !this._applications.equals("-")) {
                    String[] splits = this._applications.split("\\|");
                    if (splits.length == 1) {
                        String packageName = Application.getPackageName(splits[0]);
                        String activityName = Application.getActivityName(splits[0]);
                        PackageManager packageManager = context.getPackageManager();
                        if (activityName.isEmpty()) {
                            ApplicationInfo app;
                            try {
                                app = packageManager.getApplicationInfo(packageName, 0);
                                if (app != null)
                                    selectedApplications = packageManager.getApplicationLabel(app).toString();
                            } catch (Exception e) {
                                selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
                            }
                        } else {
                            Intent intent = new Intent();
                            intent.setClassName(packageName, activityName);
                            ActivityInfo info = intent.resolveActivityInfo(packageManager, 0);
                            if (info != null)
                                selectedApplications = info.loadLabel(packageManager).toString();
                        }
                    } else
                        selectedApplications = context.getString(R.string.applications_multiselect_summary_text_selected) + ": " + splits.length;
                }
                if (this._inCall || this._missedCall)
                    descr = descr + " • ";
                descr = descr + /*"(S) "+*/context.getString(R.string.event_preferences_notifications_applications) + ": <b>" + selectedApplications + "</b>";

                if (this._checkContacts) {
                    descr = descr + " • ";
                    descr = descr + "<b>" + context.getString(R.string.event_preferences_notifications_checkContacts) + "</b>: ";

                    descr = descr + context.getString(R.string.event_preferences_notifications_contact_groups) + ": ";
                    descr = descr + "<b>" + ContactGroupsMultiSelectDialogPreferenceX.getSummary(_contactGroups, context) + "</b> • ";

                    descr = descr + context.getString(R.string.event_preferences_notifications_contacts) + ": ";
                    descr = descr + "<b>" + ContactsMultiSelectDialogPreferenceX.getSummary(_contacts, true, context) + "</b> • ";

                    descr = descr + context.getString(R.string.event_preferences_contactListType) + ": ";
                    String[] contactListTypes = context.getResources().getStringArray(R.array.eventNotificationContactListTypeArray);
                    descr = descr + "<b>" + contactListTypes[this._contactListType] + "</b>";
                }
                if (this._checkText) {
                    descr = descr + " • ";
                    descr = descr + "<b>" + context.getString(R.string.event_preferences_notifications_checkText) + "</b>: ";

                    descr = descr + context.getString(R.string.event_preferences_notifications_text) + ": ";
                    descr = descr + "<b>" + _text + "</b>";
                }
                descr = descr + " • ";
                descr = descr + context.getString(R.string.pref_event_duration) + ": <b>" + GlobalGUIRoutines.getDurationString(this._duration) + "</b>";
            }
        }
    }

    return descr;
}