Example usage for android.content.pm PackageManager getLaunchIntentForPackage

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

Introduction

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

Prototype

public abstract @Nullable Intent getLaunchIntentForPackage(@NonNull String packageName);

Source Link

Document

Returns a "good" intent to launch a front-door activity in a package.

Usage

From source file:com.hukum.app_framework.application.gcm.controller.AppGcmListenerService.java

/**
 * Called when message is received.// www .  j av  a  2s  .  co  m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    if (data != null) {
        if (data.containsKey("CMD"))
            return;

        Log.d(TAG, "From: " + from);
        if (from.startsWith("/topics/")) {
            // message received from some topic.
        } else {
            // normal downstream message.
            String he = data.getString("he");
            String messageId = data.getString("messageId");
            int event = Integer.parseInt(he);
            String playStoreUrl;
            String webUrl;
            String openAppScreen;
            String message;
            Intent intent = null;
            message = data.getString("message");
            String notificationType = data.getString("nt");

            if (!TextUtils.isEmpty(notificationType) && !TextUtils.isEmpty(messageId)) {
                ApplicationObject.getInstance().getInternalTracker().sendNotificationTracking(notificationType,
                        messageId);
            }

            switch (event) {
            case GCMConstants.APP_OPEN_EVENT:
                PackageManager packageManager = getPackageManager();
                intent = packageManager.getLaunchIntentForPackage(getPackageName());
                ComponentName componentName = intent.getComponent();
                Intent mainIntent = IntentCompat.makeRestartActivityTask(componentName);
                sendNotification(mainIntent, message);
                break;
            case GCMConstants.APP_CONSUMABLE_EVENT:
                openAppScreen = data.getString("op");
                String parameter = data.getString("pm");
                handleParams(message, parameter, messageId);
                // push notification handling..

                break;
            case GCMConstants.PLAY_STORE_CONSUMABLE_EVENT:
                playStoreUrl = data.getString("androidURL");
                if (TextUtils.isEmpty(playStoreUrl)) {
                    playStoreUrl = getPackageName();
                }
                try {
                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + playStoreUrl));
                } catch (ActivityNotFoundException e) {
                    intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + playStoreUrl));
                }
                sendNotification(intent, message);
                break;
            case GCMConstants.WEB_CONSUMABLE_EVENT:
                webUrl = data.getString("androidURL");
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
                sendNotification(intent, message);
                break;
            }

        }
    }
}

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.  java2s.c  o m

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

From source file:ti.notificare.IntentReceiver.java

@Override
public void onActionReceived(Uri target) {
    NotificareTitaniumAndroidModule module = NotificareTitaniumAndroidModule.getModule();
    if (module != null) {
        Log.i(TAG, "Module is running, firing custom action event");
        KrollDict event = new KrollDict();
        event.put("target", target.toString());
        module.fireEvent("action", event);
    } else {//from   ww w . j  a v a 2 s.co m
        // Start the main activity
        Log.i(TAG, "Module not running, launch app with custom action intent");
        PackageManager pm = Notificare.shared().getApplicationContext().getPackageManager();
        String packageName = Notificare.shared().getApplicationContext().getPackageName();
        Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
        if (launchIntent != null) {
            launchIntent.setAction(Notificare.INTENT_ACTION_CUSTOM_ACTION).setData(target)
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            Notificare.shared().getApplicationContext().startActivity(launchIntent);
        }
    }
}

From source file:it.ms.theing.loquitur.functions.IntentInterface.java

/**
 * Create a new intent by the application name
 * @param argument// w w w.  j  a  va2 s. co  m
 * Application name
 */
@JavascriptInterface
public void launchFromName(String argument) {
    try {
        PackageManager packman = context.getPackageManager();
        intent = packman.getLaunchIntentForPackage(argument);
    } catch (Exception e) {
        Utils.safe(e);
    }

}

From source file:com.fbbackup.TagImageDetailActivity.java

private void setListener() {
    btn_share.setOnClickListener(new Button.OnClickListener() {

        @Override// ww  w . j  av  a 2 s.c o  m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // Gets a handle to the clipboard service.
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipBoardText);

            PackageManager pm = getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android");
            startActivity(intent);

        }

    });

    btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            DownloadSinglePicTask download = new DownloadSinglePicTask();

            download.setContext(TagImageDetailActivity.this);

            download.setAlbunPhotoUrl(clipBoardText);

            Log.w("downloadpic", "ImageDetail albumName:" + albumName);

            download.setPath(extStorageDirectory + "/DCIM/FBBackup/" + name + "/TagMe" + "/");

            download.execute("test");
        }

    });
}

From source file:ti.notificare.IntentReceiver.java

@Override
public void onNotificationOpened(String alert, final String notificationId, final String inboxItemId,
        Bundle extras) {//from ww  w  .  ja  v  a  2 s.co m
    NotificareAction action = extras.getParcelable(Notificare.INTENT_EXTRA_ACTION);
    NotificareNotification notification = extras.getParcelable(Notificare.INTENT_EXTRA_NOTIFICATION);
    if (action != null && notification != null && action.getType().equals(NotificareAction.ACTION_TYPE_CALLBACK)
            && !action.getCamera() && !action.getKeyboard()) {
        try {
            Class<?> actionClass = Class.forName(action.getType());
            Constructor<?> ctor = actionClass.getConstructor(Activity.class, NotificareNotification.class,
                    NotificareAction.class);
            NotificationAction actionHandler = (NotificationAction) ctor.newInstance(null, notification,
                    action);
            actionHandler.handleAction(new NotificareCallback<NotificarePendingResult>() {
                @Override
                public void onSuccess(NotificarePendingResult result) {
                    Log.i(TAG, "action handled successfully");
                    Notificare.shared().getEventLogger().logOpenNotificationInfluenced(notificationId);
                    Notificare.shared().getEventLogger().logOpenNotification(notificationId);
                    if (inboxItemId != null) {
                        Notificare.shared().getInboxManager().markItem(inboxItemId);
                    }
                }

                @Override
                public void onError(NotificareError error) {
                    Log.e(TAG, "error handling action", error);
                }
            });
        } catch (Exception e) {
            Log.e(TAG, "error instantiating Action Handler", e);
        }
    } else {
        KrollDict event = new KrollDict();
        try {
            event.put("itemId", inboxItemId);
            event.put("notification",
                    NotificareTitaniumAndroidModule.jsonToObject(notification.toJSONObject()));
            event.put("alert", alert);
            event.put("extras", notification.getExtra());

            NotificareTitaniumAndroidModule module = NotificareTitaniumAndroidModule.getModule();
            if (module != null) {
                Log.i(TAG, "Module is running, firing notification open event");
                module.fireEvent("notification", event);
            } else {
                // Start the main activity
                Log.i(TAG, "Module not running, launch app with notification open intent");
                PackageManager pm = Notificare.shared().getApplicationContext().getPackageManager();
                String packageName = Notificare.shared().getApplicationContext().getPackageName();
                Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
                if (launchIntent != null) {
                    launchIntent.setAction(Notificare.INTENT_ACTION_NOTIFICATION_OPENED).putExtras(extras)
                            .putExtra(Notificare.INTENT_EXTRA_DISPLAY_MESSAGE,
                                    Notificare.shared().getDisplayMessage())
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    Notificare.shared().getApplicationContext().startActivity(launchIntent);
                }
            }
        } catch (JSONException e) {
            Log.e(TAG, "JSON parse error");
        }
    }

    if (Notificare.shared().getAutoCancel()) {
        Notificare.shared().cancelNotification(notificationId);
    }

}

From source file:com.fbbackup.ImageDetailActivity.java

private void setListener() {
    btn_share.setOnClickListener(new Button.OnClickListener() {

        @Override//from w  w  w  . j av a 2 s .  c om
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // Gets a handle to the clipboard service.
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipBoardText);

            PackageManager pm = getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android");

            File file = new File(extStorageDirectory + "/DCIM/FBBackup/test.jpg");

            Uri outputFileUri = Uri.fromFile(file);

            String[] path = { extStorageDirectory + "/DCIM/FBBackup/test.jpg" };
            //            MediaScannerConnection.scanFile(this, path, null,  
            //                  new MediaScannerConnection.OnScanCompletedListener() {
            //                  public void onScanCompleted(String path, Uri uri) {
            //                      Log.i("ExternalStorage", "Scanned " + path + ":");
            //                      Log.i("ExternalStorage", "-> uri=" + uri);
            //                  }
            //            });

            MediaScannerConnection.scanFile(getApplicationContext(), path, null, null);

            Log.w("RyanWang", outputFileUri.getPath());

            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, outputFileUri);
            intent.setType("image/jpeg");

            startActivity(intent);

        }

    });

    btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            DownloadSinglePicTask download = new DownloadSinglePicTask();

            download.setContext(ImageDetailActivity.this);

            download.setAlbunPhotoUrl(clipBoardText);

            Log.w("downloadpic", "ImageDetail albumName:" + albumName);

            download.setPath(
                    extStorageDirectory + "/DCIM/FBBackup/" + name + "/" + Utils.getDirName(albumName) + "/");

            download.execute("test");
        }

    });
}

From source file:jahirfiquitiva.iconshowcase.fragments.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    String[] appsNames = getResources().getStringArray(R.array.apps_titles);
    String[] appsDescriptions = getResources().getStringArray(R.array.apps_descriptions);
    String[] appsIcons = getResources().getStringArray(R.array.apps_icons);
    String[] appsPackages = getResources().getStringArray(R.array.apps_packages);

    int names = appsNames.length, descs = appsDescriptions.length, icons = appsIcons.length,
            packs = appsPackages.length;

    if (names > 0 && names == descs && names == icons && names == packs) {
        hasAppsList = true;//from  w  w  w .  j av  a2  s.  c  o m
    }

    context = getActivity();

    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        if (parent != null) {
            parent.removeView(layout);
        }
    }
    try {
        layout = (ViewGroup) inflater.inflate(R.layout.main_section, container, false);
    } catch (InflateException e) {
        //Do nothing
    }

    fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);

    themeMode = getResources().getBoolean(R.bool.theme_mode);
    RecyclerView mRecyclerView = (RecyclerView) layout.findViewById(R.id.home_rv);

    if (!themeMode) {
        setupAndAnimateIcons(true, true, 600);

        GridLayout iconsRow = (GridLayout) getActivity().findViewById(R.id.iconsRow);

        iconsRow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ShowcaseActivity.SHUFFLE = true;
                setupAndAnimateIcons(true, true, 0);
            }
        });

    }

    if (hasAppsList) {
        for (int i = 0; i < appsNames.length; i++) {
            try {
                if (appsPackages[i].indexOf("http") != -1) { //checks if package is a site
                    homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                            .description(appsDescriptions[i])
                            .icon(ContextCompat.getDrawable(context,
                                    Utils.getIconResId(context, getResources(), context.getPackageName(),
                                            appsIcons[i], null)))
                            .onClickLink(appsPackages[i], false, false, null).build());
                    continue;
                }
                Intent intent;
                boolean isInstalled = Utils.isAppInstalled(context, appsPackages[i]);
                if (isInstalled) {
                    PackageManager pm = context.getPackageManager();
                    intent = pm.getLaunchIntentForPackage(appsPackages[i]);
                    if (intent != null) {
                        try {
                            homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                    .description(appsDescriptions[i])
                                    .icon(ContextCompat.getDrawable(context,
                                            Utils.getIconResId(context, getResources(),
                                                    context.getPackageName(), appsIcons[i], null)))
                                    .onClickLink(appsPackages[i], true, true, intent).build());
                        } catch (Resources.NotFoundException e) {
                            if (ShowcaseActivity.DEBUGGING)
                                Utils.showLog(context, "There's no icon that matches name: " + appsIcons[i]);
                            homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                    .description(appsDescriptions[i])
                                    .icon(ContextCompat.getDrawable(context,
                                            Utils.getIconResId(context, getResources(),
                                                    context.getPackageName(), "ic_na_launcher", null)))
                                    .onClickLink(appsPackages[i], true, true, intent).build());
                        }
                    }
                } else {
                    try {
                        homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                .description(appsDescriptions[i])
                                .icon(ContextCompat.getDrawable(context,
                                        Utils.getIconResId(context, getResources(), context.getPackageName(),
                                                appsIcons[i], null)))
                                .onClickLink(appsPackages[i], true, false, null).build());
                    } catch (Resources.NotFoundException e) {
                        if (ShowcaseActivity.DEBUGGING)
                            Utils.showLog(context, "There's no icon that matches name: " + appsIcons[i]);
                        homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                .description(appsDescriptions[i])
                                .icon(ContextCompat.getDrawable(context,
                                        Utils.getIconResId(context, getResources(), context.getPackageName(),
                                                "ic_na_launcher", null)))
                                .onClickLink(appsPackages[i], true, false, null).build());
                    }
                }
            } catch (IndexOutOfBoundsException e) {
                hasAppsList = false;
                if (ShowcaseActivity.DEBUGGING)
                    Utils.showLog(context, "Apps Cards arrays are inconsistent. Fix them.");
            }
        }
    }

    setupFAB();

    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null,
            getResources().getDimensionPixelSize(R.dimen.dividers_height), false, true));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setHasFixedSize(true);

    HomeListAdapter mAdapter = new HomeListAdapter(homeCards, context, hasAppsList);
    mRecyclerView.setAdapter(mAdapter);

    return layout;
}

From source file:com.apptentive.android.sdk.ApptentiveViewActivity.java

private void startLauncherActivityIfRoot() {
    if (isTaskRoot()) {
        PackageManager packageManager = getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(getPackageName());
        ComponentName componentName = intent.getComponent();
        /** Backwards compatible method that will clear all activities in the stack. */
        Intent mainIntent = IntentCompat.makeRestartActivityTask(componentName);
        startActivity(mainIntent);/*from w w  w. j a va 2  s .c  o m*/
    }
}

From source file:com.tomclaw.appteka.main.view.AppsView.java

private void showActionDialog(final AppItem appItem) {
    ListAdapter menuAdapter = new MenuAdapter(getContext(), R.array.app_actions_titles,
            R.array.app_actions_icons);/*w  w  w .  j  a  v  a  2s  .c  o m*/
    new AlertDialog.Builder(getContext()).setAdapter(menuAdapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case 0: {
                FlurryAgent.logEvent("App menu: run");
                PackageManager packageManager = getContext().getPackageManager();
                Intent launchIntent = packageManager.getLaunchIntentForPackage(appItem.getPackageName());
                if (launchIntent == null) {
                    Snackbar.make(recyclerView, R.string.non_launchable_package, Snackbar.LENGTH_LONG).show();
                } else {
                    startActivity(launchIntent);
                }
                break;
            }
            case 1: {
                FlurryAgent.logEvent("App menu: share");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_SHARE));
                break;
            }
            case 2: {
                FlurryAgent.logEvent("App menu: extract");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_EXTRACT));
                break;
            }
            case 3: {
                FlurryAgent.logEvent("App menu: upload");
                Intent intent = new Intent(getContext(), UploadActivity.class);
                intent.putExtra(UploadActivity.UPLOAD_ITEM, appItem);
                startActivity(intent);
                break;
            }
            case 4: {
                FlurryAgent.logEvent("App menu: bluetooth");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_BLUETOOTH));
                break;
            }
            case 5: {
                FlurryAgent.logEvent("App menu: Google Play");
                String packageName = appItem.getPackageName();
                openGooglePlay(getContext(), packageName);
                break;
            }
            case 6: {
                FlurryAgent.logEvent("App menu: permissions");
                try {
                    PackageInfo packageInfo = appItem.getPackageInfo();
                    List<String> permissions = Arrays.asList(packageInfo.requestedPermissions);
                    Intent intent = new Intent(getContext(), PermissionsActivity.class).putStringArrayListExtra(
                            PermissionsActivity.EXTRA_PERMISSIONS, new ArrayList<>(permissions));
                    startActivity(intent);
                } catch (Throwable ex) {
                    Snackbar.make(recyclerView, R.string.unable_to_get_permissions, Snackbar.LENGTH_LONG)
                            .show();
                }
                break;
            }
            case 7: {
                FlurryAgent.logEvent("App menu: details");
                setRefreshOnResume();
                final Intent intent = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        .addCategory(Intent.CATEGORY_DEFAULT)
                        .setData(Uri.parse("package:" + appItem.getPackageName()))
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            }
            case 8: {
                FlurryAgent.logEvent("App menu: remove");
                setRefreshOnResume();
                Uri packageUri = Uri.parse("package:" + appItem.getPackageName());
                Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
                startActivity(uninstallIntent);
                break;
            }
            }
        }
    }).show();
}