Example usage for android.content Intent resolveActivityInfo

List of usage examples for android.content Intent resolveActivityInfo

Introduction

In this page you can find the example usage for android.content Intent resolveActivityInfo.

Prototype

public ActivityInfo resolveActivityInfo(@NonNull PackageManager pm,
        @PackageManager.ComponentInfoFlags int flags) 

Source Link

Document

Resolve the Intent into an ActivityInfo describing the activity that should execute the intent.

Usage

From source file:org.sipdroid.sipua.ui.Receiver.java

static Intent createHomeDockIntent() {
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    if (docked == EXTRA_DOCK_STATE_CAR) {
        intent.addCategory(CATEGORY_CAR_DOCK);
    } else if (docked == EXTRA_DOCK_STATE_DESK) {
        intent.addCategory(CATEGORY_DESK_DOCK);
    } else {/*from ww  w. j a v a2  s .  com*/
        return null;
    }

    ActivityInfo ai = intent.resolveActivityInfo(mContext.getPackageManager(), PackageManager.GET_META_DATA);
    if (ai == null) {
        return null;
    }

    if (ai.metaData != null && ai.metaData.getBoolean(METADATA_DOCK_HOME)) {
        intent.setClassName(ai.packageName, ai.name);
        return intent;
    }

    return null;
}

From source file:me.xingrz.finder.ZipFinderActivity.java

private void openFileInZip() {
    if (getExternalCacheDir() == null) {
        Log.e(TAG, "no external cache dir to extract");
        return;// w  w w.ja  va 2  s.co  m
    }

    File target = new File(getExternalCacheDir(), extracting.getFileName());
    Intent intent = intentToView(Uri.fromFile(target), mimeOfFile(target));

    if (intent.resolveActivityInfo(getPackageManager(), 0) == null) {
        Log.e(TAG, "no activity to handle file " + extracting.getFileName());
        Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
        return;
    }

    if (extracting.isEncrypted()
            && (extracting.getPassword() == null || extracting.getPassword().length == 0)) {
        passwordPrompt.show();
        return;
    }

    try {
        zipFile.extractFile(extracting, getExternalCacheDir().getAbsolutePath());
    } catch (ZipException ignored) {
    }

    pendingIntent = intent;

    progressDialog.setProgress(0);
    progressDialog.show();

    handler.post(this);
}

From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java

@Override
public @NonNull View getView(int position, View convertView, final @NonNull ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.row_alt : R.layout.row,
                parent, false);/*from   w ww  .ja  v a2s.  com*/

    final AppEntry entry = getItem(position);
    assert entry != null;

    final SharedPreferences pref = U.getSharedPreferences(getContext());

    TextView textView = (TextView) convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());

    Intent intent = new Intent();
    intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
    ActivityInfo activityInfo = intent.resolveActivityInfo(getContext().getPackageManager(), 0);

    if (activityInfo != null)
        textView.setTypeface(null, isTopApp(activityInfo) ? Typeface.BOLD : Typeface.NORMAL);

    switch (pref.getString("theme", "light")) {
    case "light":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color));
        break;
    case "dark":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_dark));
        break;
    }

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(entry.getIcon(getContext()));

    LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        LocalBroadcastManager.getInstance(getContext())
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
        U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(),
                entry.getUserId(getContext()), null, false, false);
    });

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int backgroundTint = pref.getBoolean("transparent_start_menu", false)
                        ? U.getAccentColor(getContext())
                        : U.getBackgroundTint(getContext());

                //noinspection ResourceAsColor
                backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2);
                v.setBackgroundColor(backgroundTint);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.zigvine.zagriculture.UIActivity.java

@Override
public void startActivityForResult(Intent intent, int requestCode) {
    ActivityInfo info = intent.resolveActivityInfo(getPackageManager(), 0);
    if (info != null && info.packageName != null && info.packageName.equals(getPackageName())) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    }/*www .  ja v a  2s. c o m*/
    super.startActivityForResult(intent, requestCode);
}

From source file:org.glucosio.android.activity.MainActivity.java

public void openSupportDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getResources().getString(R.string.menu_support_title));
    builder.setItems(getResources().getStringArray(R.array.menu_support_options),
            new DialogInterface.OnClickListener() {
                @Override/* ww w . ja va  2  s  .co m*/
                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        // Email
                        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:hello@glucosio.org"));
                        boolean activityExists = emailIntent.resolveActivityInfo(getPackageManager(),
                                0) != null;

                        if (activityExists) {
                            startActivity(emailIntent);
                        } else {
                            showSnackBar(getResources().getString(R.string.menu_support_error1),
                                    Snackbar.LENGTH_LONG);
                        }
                    } else {
                        // Forum
                        String url = "http://community.glucosio.org/";
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        i.setPackage("com.android.chrome");
                        try {
                            startActivity(i);
                        } catch (ActivityNotFoundException e) {
                            // Chrome is probably not installed
                            // Try with the default browser
                            i.setPackage(null);
                            startActivity(i);
                        }
                    }
                }
            });
    builder.show();
}

From source file:org.medcada.android.activity.MainActivity.java

public void openSupportDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getResources().getString(R.string.menu_support_title));
    builder.setItems(getResources().getStringArray(R.array.menu_support_options),
            new DialogInterface.OnClickListener() {
                @Override/*from w  w  w . ja va2 s  .  c o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        // Email
                        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:support@assistbud.com"));
                        boolean activityExists = emailIntent.resolveActivityInfo(getPackageManager(),
                                0) != null;

                        if (activityExists) {
                            startActivity(emailIntent);
                        } else {
                            showSnackBar(getResources().getString(R.string.menu_support_error1),
                                    Snackbar.LENGTH_LONG);
                        }
                    } else {
                        // Forum
                        String url = "http://community.glucosio.org/";
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        i.setPackage("com.android.chrome");
                        try {
                            startActivity(i);
                        } catch (ActivityNotFoundException e) {
                            // Chrome is probably not installed
                            // Try with the default browser
                            i.setPackage(null);
                            startActivity(i);
                        }
                    }
                }
            });
    builder.show();
}

From source file:de.ub0r.android.smsdroid.MessageListActivity.java

/**
 * {@inheritDoc}/* ww  w  .  j a v a2 s .  c  om*/
 */
@Override
protected final void onResume() {
    super.onResume();
    boolean noAds = DonationHelper.hideAds(this);
    if (!noAds) {
        Ads.loadAd(this, R.id.ad, ADMOB_PUBID, AD_KEYWORDS);
    }

    final ListView lv = this.getListView();
    lv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
    lv.setAdapter(new MessageAdapter(this, this.uri));
    this.markedUnread = false;

    final Button btn = (Button) this.findViewById(R.id.send_);
    if (this.showTextField) {
        final Intent i = this.buildIntent(this.enableAutosend, false);
        final PackageManager pm = this.getPackageManager();
        ActivityInfo ai = null;
        if (PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(PreferencesActivity.PREFS_SHOWTARGETAPP, true)) {
            ai = i.resolveActivityInfo(pm, 0);
        }
        if (ai == null) {
            btn.setText(null);
            this.etText.setMinLines(1);
        } else {
            if (chooserPackage == null) {
                final ActivityInfo cai = this.buildIntent(this.enableAutosend, true).resolveActivityInfo(pm, 0);
                if (cai != null) {
                    chooserPackage = cai.packageName;
                }
            }
            if (ai.packageName.equals(chooserPackage)) {
                btn.setText(R.string.chooser_);
            } else {
                Log.d(TAG, "ai.pn: " + ai.packageName);
                btn.setText(ai.loadLabel(pm));
            }
            this.etText.setMinLines(3);
        }
    } else {
        btn.setText(null);
    }
}

From source file:me.myatminsoe.myansms.MessageListActivity.java

/**
 * {@inheritDoc}/*from   www . j a  va2s . c  o m*/
 */
@Override
protected final void onResume() {
    super.onResume();

    final ListView lv = getListView();
    lv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
    lv.setAdapter(new MessageAdapter(this, uri));
    markedUnread = false;

    final AppCompatImageButton btn = (AppCompatImageButton) findViewById(R.id.send_);
    if (showTextField) {
        Intent i;
        ActivityInfo ai = null;
        final PackageManager pm = getPackageManager();
        try {
            i = buildIntent(false, false);
            if (pm != null && PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(PreferencesActivity.PREFS_SHOWTARGETAPP, true)) {
                ai = i.resolveActivityInfo(pm, 0);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, "unable to build Intent", e);
        }
        etText.setMaxLines(MAX_EDITTEXT_LINES);

        if (ai == null) {
            etText.setMinLines(1);
        } else {
            if (chooserPackage == null) {
                try {
                    final ActivityInfo cai = buildIntent(false, true).resolveActivityInfo(pm, 0);
                    if (cai != null) {
                        chooserPackage = cai.packageName;
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "unable to build Intent", e);
                }
            }
            if (ai.packageName.equals(chooserPackage)) {
            } else {

            }
            etText.setMinLines(3);
        }
    } else {
        btn.setImageResource(R.drawable.icn_send_disabled);
    }
}