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.velli.passwordmanager.FragmentPasswordDetails.java

public static void openApp(Context context, String packageName) {
    PackageManager manager = context.getPackageManager();
    Intent i = manager.getLaunchIntentForPackage(packageName);
    if (i != null) {
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        context.startActivity(i);/*  w  w w  .j a  v a 2 s  .c o  m*/
    }

}

From source file:br.com.arlsoft.pushclient.PushClientModule.java

public static Intent getLauncherIntent(Bundle extras) {
    TiApplication appContext = TiApplication.getInstance();
    PackageManager pm = appContext.getPackageManager();
    Intent launch = pm.getLaunchIntentForPackage(appContext.getPackageName());

    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (extras != null && !extras.isEmpty()) {
        launch.putExtra(PROPERTY_EXTRAS, extras);
    }/*from ww w. j a v  a  2  s.c om*/

    return launch;
}

From source file:org.deviceconnect.android.deviceplugin.kadecot.fragment.KadecotCheckServerFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_check_kadecot_server, container, false);
    Button launchKadecot = (Button) root.findViewById(R.id.launch_kadecot);
    launchKadecot.setOnClickListener(new View.OnClickListener() {
        @Override//  w ww.java2  s  .c  o  m
        public void onClick(final View view) {
            PackageManager pm = getActivity().getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage(getString(R.string.kadecot_package_name));
            try {
                startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(getActivity(), getString(R.string.not_install_kadecot_body), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });
    return root;
}

From source file:com.gigigo.orchextra.device.notifications.AndroidNotificationBuilder.java

public PendingIntent getPendingIntent(AndroidBasicAction androidBasicAction) {
    PackageManager pm = context.getPackageManager();

    Intent intent = pm.getLaunchIntentForPackage(context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(String.valueOf(System.currentTimeMillis()));
    intent.putExtra(EXTRA_NOTIFICATION_ACTION, androidBasicAction);

    return PendingIntent.getActivity(context, 1, intent, 0);
}

From source file:fr.RivaMedia.AnnoncesAutoGenerique.alertes.GcmIntentService.java

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

    //TODO: remplir
    //Intent de lancement

    PackageManager pm = getPackageManager();
    Intent lancement = pm.getLaunchIntentForPackage(getPackageName());

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, lancement, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.app_icon)
            .setContentTitle(titre).setContentText(message);

    mBuilder.setContentIntent(contentIntent);
    Notification notif = mBuilder.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, notif);
}

From source file:com.phonegap.plugins.ExternalAppLauncher.ExternalAppLauncher.java

/**
 * handle the required pre-installed app
 *///w ww .j  av  a2 s .  c  o m
private boolean launchApp(Context context, PackageManager pm, String packageName) {
    Log.d(pluginName, "Launching App " + packageName);
    Intent intent = pm.getLaunchIntentForPackage(packageName);
    Boolean result = false;
    try {
        context.startActivity(intent);
        result = true;
    } catch (Exception ex) {
        result = false;
    }
    return result;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static void openSpecialAppByPkgName(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    Intent launchIntentForPackage = pm.getLaunchIntentForPackage(packageName);
    if (launchIntentForPackage != null) {
        launchIntentForPackage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivitySafely(context, launchIntentForPackage);
    }//  w  w  w . jav  a 2s  . co m
}

From source file:com.popdeem.sdk.core.gcm.GCMIntentService.java

private void handleMessage(Intent intent) {
    Bundle extras = intent.getExtras();/*from   w  w w .  j  a  va2 s .  c om*/

    final String sender = extras.getString("sender", "");
    if (sender.equalsIgnoreCase(PD_SENDER_VALUE)) {
        PDLog.d(GCMIntentService.class, extras.toString());

        // Get extras
        String title = extras.getString(PD_KEY_TITLE, getString(R.string.app_name));
        String message = extras.getString(PD_KEY_MESSAGE, "");
        String imageUrl = extras.getString(PD_KEY_IMAGE_URL, "");
        String targetUrl = extras.getString(PD_KEY_TARGET_URL, null);
        String deepLink = extras.getString(PD_KEY_DEEP_LINK, null);
        String messageId = extras.getString(PD_KEY_MESSAGE_ID, null);

        // If app is open, show a dialog, else show a notification
        if (PopdeemSDK.currentActivity() != null) {
            if (PopdeemSDK.currentActivity() instanceof FragmentActivity
                    || PopdeemSDK.currentActivity() instanceof AppCompatActivity) {
                FragmentManager fm = ((FragmentActivity) PopdeemSDK.currentActivity())
                        .getSupportFragmentManager();
                PDUINotificationDialogFragment.showNotificationDialog(fm, title, message, imageUrl, targetUrl,
                        deepLink, messageId);
            }
        } else {
            // Create Pending Intent for Notification
            PackageManager pm = getPackageManager();
            Intent openAppIntent = pm.getLaunchIntentForPackage(getPackageName());
            openAppIntent.putExtra(PD_NOTIFICATION_INTENT_MESSAGE_ID_KEY, messageId);
            openAppIntent.putExtra(PD_NOTIFICATION_INTENT_URL_KEY, targetUrl != null ? targetUrl : deepLink);
            openAppIntent.putExtra(PD_NOTIFICATION_INTENT_IMAGE_URL_KEY, imageUrl);
            openAppIntent.putExtra(PD_NOTIFICATION_INTENT_TITLE_KEY, title);
            openAppIntent.putExtra(PD_NOTIFICATION_INTENT_MESSAGE_KEY, message);

            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, openAppIntent, 0);

            int id = (int) PDNumberUtils.toLong(messageId, 1);
            sendNotification(title, message, pendingIntent, id);
        }
    }
}

From source file:org.androidsoft.app.permission.ui.ApplicationFragment.java

/**
 * Open the application/*from  w  ww. ja va  2s.  c o m*/
 */
private void open() {
    PackageManager pm = mActivity.getPackageManager();
    Intent intentOpen = pm.getLaunchIntentForPackage(mPackageName);
    if (intentOpen != null) {
        intentOpen.addCategory(Intent.CATEGORY_LAUNCHER);
        startActivity(intentOpen);
    } else {
        Toast.makeText(mActivity, getString(R.string.message_error_open), Toast.LENGTH_LONG).show();
    }
}

From source file:com.tenforwardconsulting.cordova.bgloc.LocationService.java

/**
 * Forces the main activity to re-launch if it's unloaded.
 *//*from  w  w w. j a v  a2s .com*/
private void forceMainActivityReload() {
    PackageManager pm = getPackageManager();
    Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
    startActivity(launchIntent);
}