Example usage for android.content.pm PackageManager queryIntentActivities

List of usage examples for android.content.pm PackageManager queryIntentActivities

Introduction

In this page you can find the example usage for android.content.pm PackageManager queryIntentActivities.

Prototype

public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);

Source Link

Document

Retrieve all activities that can be performed for the given intent.

Usage

From source file:com.dm.material.dashboard.candybar.tasks.IconRequestTask.java

@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {/*from  w w w . jav  a2 s  . c  o  m*/
            Thread.sleep(1);
            if (mContext.get().getResources().getBoolean(R.bool.enable_icon_request)
                    || mContext.get().getResources().getBoolean(R.bool.enable_premium_request)) {
                List<Request> requests = new ArrayList<>();
                HashMap<String, String> appFilter = RequestHelper.getAppFilter(mContext.get(),
                        RequestHelper.Key.ACTIVITY);
                if (appFilter.size() == 0) {
                    mError = Extras.Error.APPFILTER_NULL;
                    return false;
                }

                PackageManager packageManager = mContext.get().getPackageManager();

                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent,
                        PackageManager.GET_RESOLVED_FILTER);
                if (installedApps == null || installedApps.size() == 0) {
                    mError = Extras.Error.INSTALLED_APPS_NULL;
                    return false;
                }

                CandyBarMainActivity.sInstalledAppsCount = installedApps.size();

                try {
                    Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager));
                } catch (Exception ignored) {
                }

                for (ResolveInfo app : installedApps) {
                    String packageName = app.activityInfo.packageName;
                    String activity = packageName + "/" + app.activityInfo.name;

                    String value = appFilter.get(activity);

                    if (value == null) {
                        String name = LocaleHelper.getOtherAppLocaleName(mContext.get(), new Locale("en"),
                                packageName);
                        if (name == null) {
                            name = app.activityInfo.loadLabel(packageManager).toString();
                        }

                        boolean requested = Database.get(mContext.get()).isRequested(activity);
                        Request request = Request.Builder().name(name).packageName(app.activityInfo.packageName)
                                .activity(activity).requested(requested).build();

                        requests.add(request);
                    }
                }

                CandyBarMainActivity.sMissedApps = requests;
            }
            return true;
        } catch (Exception e) {
            CandyBarMainActivity.sMissedApps = null;
            mError = Extras.Error.DATABASE_ERROR;
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}

From source file:com.kccomy.orgar.ui.note.NoteFragment.java

private void initPopupWindow() {
    View popupWindowView = getActivity().getLayoutInflater().inflate(R.layout.popup_window_share, null);

    //??//  ww  w  .j  a v  a 2  s. co  m
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addCategory(Intent.CATEGORY_DEFAULT);
    shareIntent.setType("text/plain");

    PackageManager packageManager = getContext().getPackageManager();
    List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(shareIntent,
            PackageManager.GET_RESOLVED_FILTER);

    // RecyclerAdapter
    RecyclerView recyclerView = (RecyclerView) popupWindowView.findViewById(R.id.popup_widow_share_recycler);
    ShareAdapter shareAdapter = new ShareAdapter(packageManager);
    shareAdapter.setData(resolveInfos);
    shareAdapter.setAppIconClickListener(shareListener);

    recyclerView.setAdapter(shareAdapter);
    recyclerView
            .setLayoutManager(new GridLayoutManager(getContext(), 2, LinearLayoutManager.HORIZONTAL, false));

    // ?PopupWindow
    popupWindowView.setFocusable(true);
    popupWindowView.setFocusableInTouchMode(true);

    PopupWindow popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);

    popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));

    popupWindow.setAnimationStyle(R.style.anim_menu_bottombar);

    setWindowAlpha(0.5f);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            setWindowAlpha(1f);
        }
    });

    popupWindow.showAtLocation(getActivity().getLayoutInflater().inflate(R.layout.fragment_note, null),
            Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}

From source file:com.github.michalbednarski.intentslab.editor.ComponentPickerDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);/*w  w  w  .j av a  2s . c o m*/

    // Get edited intent
    IntentEditorActivity intentEditor = (IntentEditorActivity) getActivity();
    Intent intent = new Intent(intentEditor.getEditedIntent());
    intent.setComponent(null);

    // Get components
    PackageManager pm = intentEditor.getPackageManager();
    List<ResolveInfo> ri = null;

    switch (intentEditor.getComponentType()) {
    case IntentEditorConstants.ACTIVITY:
        ri = pm.queryIntentActivities(intent, PackageManager.GET_DISABLED_COMPONENTS);
        break;
    case IntentEditorConstants.BROADCAST:
        ri = pm.queryBroadcastReceivers(intent, PackageManager.GET_DISABLED_COMPONENTS);
        break;
    case IntentEditorConstants.SERVICE:
        ri = pm.queryIntentServices(intent, PackageManager.GET_DISABLED_COMPONENTS);
        break;
    }

    // Cancel if no components
    if (ri.isEmpty()) {
        Toast.makeText(getActivity(), R.string.no_matching_components_found, Toast.LENGTH_SHORT).show();
        dismiss();
        return;
    }

    // Split enabled and disabled choices
    ArrayList<ResolveInfo> choices = new ArrayList<ResolveInfo>();
    ArrayList<ResolveInfo> disabledChoices = new ArrayList<ResolveInfo>();
    for (ResolveInfo resolveInfo : ri) {
        (isComponentEnabled(pm, resolveInfo) ? choices : disabledChoices).add(resolveInfo);
    }

    mEnabledChoicesCount = choices.size();
    choices.addAll(disabledChoices);
    mChoices = choices.toArray(new ResolveInfo[choices.size()]);
}

From source file:org.bishoph.oxdemo.OXDemo.java

public void startVoiceRecognitionActivity() {
    Log.v("OXDemo", "startVoiceRecognitionActivity init...");
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    if (activities.size() > 0) {
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
        Log.v("OXDemo", "...done");
    } else {/*from w  w w  .j a  v a2s .co m*/
        // createTask(folder_id,
        // "Auto creation  "+getSimpleRandomString());
        Log.v("OXDemo", "No voice recognition!");
    }
}

From source file:com.partytv.server.PartyTvServer.java

private void checkAppKeySetup() {
    // Check to make sure that we have a valid app key
    if (APP_KEY.startsWith("CHANGE") || APP_SECRET.startsWith("CHANGE")) {
        showToast(/*  w  w w.j a  v  a2  s .c  o  m*/
                "You must apply for an app key and secret from developers.dropbox.com, and add them to the DBRoulette ap before trying it.");
        finish();
        return;
    }

    // Check if the app has set up its manifest properly.
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    String scheme = "db-" + APP_KEY;
    String uri = scheme + "://" + AuthActivity.AUTH_VERSION + "/test";
    testIntent.setData(Uri.parse(uri));
    PackageManager pm = getPackageManager();
    if (0 == pm.queryIntentActivities(testIntent, 0).size()) {
        showToast("URL scheme in your app's " + "manifest is not set up correctly. You should have a "
                + "com.dropbox.client2.android.AuthActivity with the " + "scheme: " + scheme);
        finish();
    }
}

From source file:com.jculb.wallet.ui.RequestCoinsFragment.java

private boolean checkForLocalApp() {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("defcoin:DJWsdcQhAbfSpRogDpqGCpk3w8ibXKVw1P")); //Just for testing; will never be fired.
    PackageManager manager = getActivity().getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
    return infos.size() > 0 ? true : false;
}

From source file:de.jdellay.wallet.ui.RequestCoinsFragment.java

private boolean checkForLocalApp() {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("cannacoin:DEwTHxztkSDUJEMywbPk5zVUGrupaNRqEy")); //Just for testing; will never be fired.
    PackageManager manager = getActivity().getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
    return infos.size() > 0 ? true : false;
}

From source file:com.hacktx.android.activities.MainActivity.java

private boolean isSlackInstalled() {
    final PackageManager packageManager = getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage("com.Slack");

    if (intent == null) {
        return false;
    }/*from  w  w  w .j  a v a2s  . c o  m*/

    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:de.langerhans.wallet.ui.RequestCoinsFragment.java

private boolean checkForLocalApp() {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("dogecoin:DEwTHxztkSDUJEMywbPk5zVUGrupaNRqEy")); //Just for testing; will never be fired.
    PackageManager manager = getActivity().getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
    return infos.size() > 0 ? true : false;
}

From source file:com.aylanetworks.aura.GcmIntentService.java

private void sendNotification(String msg, String sound) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    // Find the launcher class for our application
    PackageManager pm = getPackageManager();
    String packageName = getPackageName();
    Intent query = new Intent(Intent.ACTION_MAIN);
    Class launcherClass = null;//  ww w  .ja v a 2s  .  c  o m
    query.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> foundIntents = pm.queryIntentActivities(query, 0);
    for (ResolveInfo info : foundIntents) {
        if (TextUtils.equals(info.activityInfo.packageName, packageName)) {
            launcherClass = info.activityInfo.getClass();
        }
    }

    if (launcherClass == null) {
        Log.e(TAG, "Could not find application launcher class");
        return;
    }

    Intent appIntent = new Intent(this, launcherClass); // main activity of Ayla Control/aMCA
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, appIntent, 0);

    //Determine the sound to be played
    Uri soundUri = null;
    if (sound == null) {
        // NOP
        //PushNotification.playSound("bdth.mp3");
    } else if (sound.equals("none")) {
        // NOP
    } else if (sound.equals("default")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
    } else if (sound.equals("alarm")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // TYPE_NOTIFICATION or TYPE_ALARM
    } else {
        boolean playedSound;
        playedSound = PushNotification.playSound(sound);
        if (playedSound == false) {
            soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
        }
    }

    // @formatter:off
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            //.setSound(soundUri)
            .setSmallIcon(R.drawable.ic_push_icon).setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFFff0000, 500, 500) // flashing red light
            .setContentText(msg).setAutoCancel(true)
            //.setPriority(Notification.FLAG_HIGH_PRIORITY)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS);
    // @formatter:on

    if (soundUri != null) {
        mBuilder.setSound(soundUri);
    }
    mBuilder.setPriority(PRIORITY_MAX);
    mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}