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.xargsgrep.portknocker.asynctask.RetrieveApplicationsAsyncTask.java

@Override
protected List<Application> doInBackground(Void... params) {
    PackageManager packageManager = activity.getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager
            .getInstalledApplications(PackageManager.GET_META_DATA);

    List<Application> applications = new ArrayList<Application>();
    for (ApplicationInfo applicationInfo : installedApplications) {
        if (isSystemPackage(applicationInfo)
                || packageManager.getLaunchIntentForPackage(applicationInfo.packageName) == null)
            continue;
        applications.add(new Application(packageManager.getApplicationLabel(applicationInfo).toString(),
                applicationInfo.loadIcon(packageManager), applicationInfo.packageName));
    }//from www . j a  v  a 2 s .  com

    Collections.sort(applications, new Comparator<Application>() {
        @Override
        public int compare(Application app1, Application app2) {
            return app1.getLabel().compareTo(app2.getLabel());
        }
    });
    applications.add(0, new Application("None", null, ""));

    return applications;
}

From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(EngagementNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {//from w ww.  ja  v  a 2  s . c o  m
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && EngagementActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(CapptainNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {//w  w w .j  a v  a2 s.  c o  m
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && CapptainActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.NotifyMe.GcmIntentService.java

private Intent getWeatherAppIntent() {
    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    String genieWidgetPackage = null;
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo packageInfo : packages) {
        if (packageInfo.packageName.toLowerCase().contains("weather")) {
            return pm.getLaunchIntentForPackage(packageInfo.packageName);
        } else if (packageInfo.packageName.toLowerCase().contains("geniewidget")) {
            genieWidgetPackage = packageInfo.packageName;
        }/*from w w  w  .j a  va2s. c o  m*/
    }
    // Didn't find a weather app - Try Google News and Weather
    // Will return null if not found.
    return pm.getLaunchIntentForPackage(genieWidgetPackage);
}

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withSelectionListEnabledForSingleProfile(false)
            .withDividerBelowHeader(false).withCompactStyle(true).build();

    DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override//from  w ww .  java 2s  . co m
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });

    drawer = new DrawerBuilder().withActivity(this)
            //.withToolbar(toolbar)
            .withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1)
            .addDrawerItems(
                    new PrimaryDrawerItem().withIdentifier(0).withName(R.string.action_view_profile)
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
                    new PrimaryDrawerItem().withIdentifier(1)
                            .withName(getString(R.string.action_view_favourites)).withSelectable(false)
                            .withIcon(GoogleMaterial.Icon.gmd_star),
                    new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_blocks))
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
                    new PrimaryDrawerItem().withIdentifier(5).withName("#gopseudo").withSelectable(false)
                            .withIcon(R.mipmap.ic_evil_logo))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem != null) {
                        long drawerItemIdentifier = drawerItem.getIdentifier();

                        if (drawerItemIdentifier == 0) {
                            if (loggedInAccountId != null) {
                                Intent intent = new Intent(MainActivity.this, AccountActivity.class);
                                intent.putExtra("id", loggedInAccountId);
                                startActivity(intent);
                            }
                        } else if (drawerItemIdentifier == 1) {
                            Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 2) {
                            Intent intent = new Intent(MainActivity.this, BlocksActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 3) {
                            Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 4) {
                            logout();
                        } else if (drawerItemIdentifier == 5) {
                            if (Utils.isPackageInstalled("co.gopseudo.android",
                                    MainActivity.this.getPackageManager())) {
                                PackageManager pm = MainActivity.this.getPackageManager();
                                Intent launchIntent = pm.getLaunchIntentForPackage("co.gopseudo.android");
                                MainActivity.this.startActivity(launchIntent);
                            } else {
                                Utils.urlIntent(MainActivity.this,
                                        "https://play.google.com/store/apps/details?id=co.gopseudo.android");
                            }
                        }
                    }

                    return false;
                }
            }).build();

    drawer.addStickyFooterItem(new SecondaryDrawerItem().withIdentifier(3)
            .withName(getString(R.string.action_view_preferences)).withSelectable(false));
    drawer.addStickyFooterItem(new SecondaryDrawerItem().withIdentifier(4)
            .withName(getString(R.string.action_logout)).withSelectable(false));
}

From source file:info.snowhow.plugin.RecorderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(LOG_TAG, "Received start id " + startId + ": " + intent);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showNoGPSAlert();/* w  w  w .j  a v  a 2s.  c o m*/
    }
    runningID = startId;
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.

    if (intent == null) {
        tf = sharedPref.getString("runningTrackFile", "");
        Log.w(LOG_TAG, "Intent is null, trying to continue to write to file " + tf + " lm " + locationManager);
        minimumPrecision = sharedPref.getFloat("runningPrecision", 0);
        distanceChange = sharedPref.getLong("runningDistanceChange", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES);
        updateTime = sharedPref.getLong("runningUpdateTime", MINIMUM_TIME_BETWEEN_UPDATES);
        updateTimeFast = sharedPref.getLong("runningUpdateTimeFast", MINIMUM_TIME_BETWEEN_UPDATES_FAST);
        speedLimit = sharedPref.getLong("runningSpeedLimit", SPEED_LIMIT);
        adaptiveRecording = sharedPref.getBoolean("adaptiveRecording", false);
        int count = sharedPref.getInt("count", 0);
        if (count > 0) {
            firstPoint = false;
        }
        if (tf == null || tf == "") {
            Log.e(LOG_TAG, "No trackfile found ... exit clean here");
            cleanUp();
            return START_NOT_STICKY;
        }
    } else {
        tf = intent.getStringExtra("fileName");
        Log.d(LOG_TAG, "FILENAME for recording is " + tf);
        minimumPrecision = intent.getFloatExtra("precision", 0);
        distanceChange = intent.getLongExtra("distance_change", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES);
        updateTime = intent.getLongExtra("update_time", MINIMUM_TIME_BETWEEN_UPDATES);
        updateTimeFast = intent.getLongExtra("update_time_fast", MINIMUM_TIME_BETWEEN_UPDATES_FAST);
        speedLimit = intent.getLongExtra("speed_limit", SPEED_LIMIT);
        adaptiveRecording = intent.getBooleanExtra("adaptiveRecording", false);
        editor.putString("runningTrackFile", tf);
        editor.putFloat("runningPrecision", minimumPrecision);
        editor.putLong("runningDistanceChange", distanceChange);
        editor.putLong("runningUpdateTime", updateTime);
        editor.putLong("runningUpdateTimeFast", updateTimeFast);
        editor.putLong("runningSpeedLimit", speedLimit);
        editor.putBoolean("adaptiveRecording", adaptiveRecording);
        editor.commit();
    }

    Intent cordovaMainIntent;
    try {
        PackageManager packageManager = this.getPackageManager();
        cordovaMainIntent = packageManager.getLaunchIntentForPackage(this.getPackageName());
        Log.d(LOG_TAG, "got cordovaMainIntent " + cordovaMainIntent);
        if (cordovaMainIntent == null) {
            throw new PackageManager.NameNotFoundException();
        }
    } catch (PackageManager.NameNotFoundException e) {
        cordovaMainIntent = new Intent();
    }
    PendingIntent pend = PendingIntent.getActivity(this, 0, cordovaMainIntent, 0);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ifString), 0);
    NotificationCompat.Action stop = new NotificationCompat.Action.Builder(android.R.drawable.ic_delete,
            "Stop recording", pendingIntent).build();
    note = new NotificationCompat.Builder(this).setContentTitle(applicationName + " GPS tracking")
            .setSmallIcon(android.R.drawable.ic_menu_mylocation).setOngoing(true).setContentIntent(pend)
            .setContentText("No location yet.");
    note.addAction(stop);

    nm = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE);
    nm.notify(0, note.build());

    recording = true;
    Log.d(LOG_TAG, "recording in handleIntent");
    try { // create directory first, if it does not exist
        File trackFile = new File(tf).getParentFile();
        if (!trackFile.exists()) {
            trackFile.mkdirs();
            Log.d(LOG_TAG, "done creating path for trackfile: " + trackFile);
        }
        Log.d(LOG_TAG, "going to create RandomAccessFile " + tf);
        myWriter = new RandomAccessFile(tf, "rw");
        if (intent != null) { // start new file
            // myWriter.setLength(0);    // delete all contents from file
            String trackName = intent.getStringExtra("trackName");
            String trackHead = initTrack(trackName).toString();
            myWriter.write(trackHead.getBytes());
            // we want to write JSON manually for streamed writing
            myWriter.seek(myWriter.length() - 1);
            myWriter.write(",\"coordinates\":[]}".getBytes());
        }
    } catch (IOException e) {
        Log.d(LOG_TAG, "io error. cannot write to file " + tf);
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, distanceChange, mgpsll);
    if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, updateTime, distanceChange,
                mnetll);
    }
    return START_STICKY;
}

From source file:uk.org.openseizuredetector.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.v(TAG, "Option " + item.getItemId() + " selected");
    switch (item.getItemId()) {
    case R.id.action_launch_pebble_app:
        Log.v(TAG, "action_launch_pebble_app");
        try {/*from w w  w . j  ava 2s.c o  m*/
            PackageManager pm = this.getPackageManager();
            Intent pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android");
            this.startActivity(pebbleAppIntent);
        } catch (Exception ex) {
            Log.v(TAG, "exception starting pebble App " + ex.toString());
        }
        return true;
    case R.id.action_start_stop:
        // Respond to the start/stop server menu item.
        Log.v(TAG, "action_sart_stop");
        if (mBound) {
            Log.v(TAG, "Stopping Server");
            unbindFromServer();
            stopServer();
        } else {
            Log.v(TAG, "Starting Server");
            startServer();
            // and bind to it so we can see its data
            bindToServer();
        }
        return true;
    case R.id.action_test_fault_beep:
        Log.v(TAG, "action_test_fault_beep");
        if (mBound) {
            mSdServer.faultWarningBeep();
        }
        return true;
    case R.id.action_test_alarm_beep:
        Log.v(TAG, "action_test_alarm_beep");
        if (mBound) {
            mSdServer.alarmBeep();
        }
        return true;
    case R.id.action_test_warning_beep:
        Log.v(TAG, "action_test_warning_beep");
        if (mBound) {
            mSdServer.warningBeep();
        }
        return true;
    case R.id.action_test_sms_alarm:
        Log.v(TAG, "action_test_sms_alarm");
        if (mBound) {
            mSdServer.sendSMSAlarm();
        }
        return true;
    case R.id.action_settings:
        Log.v(TAG, "action_settings");
        try {
            Intent prefsIntent = new Intent(MainActivity.this, PrefActivity.class);
            this.startActivity(prefsIntent);
        } catch (Exception ex) {
            Log.v(TAG, "exception starting settings activity " + ex.toString());
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:edu.sage.spark.ui.ContactList.java

public void openCloud() {
    PackageManager pm = this.getPackageManager();
    Intent appStartIntent = pm.getLaunchIntentForPackage("edu.sage.cloud");
    if (null != appStartIntent) {
        this.startActivity(appStartIntent);
        this.finish();
    } else {/*from  w  w  w  .  ja v a  2 s.com*/
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("market://details?id=edu.sage.cloud"));
        startActivity(i);
    }
}

From source file:edu.sage.spark.ui.ContactList.java

private void sageMail() {
    PackageManager pm = this.getPackageManager();
    Intent appStartIntent = pm.getLaunchIntentForPackage("edu.sage.mail");
    if (null != appStartIntent) {
        this.startActivity(appStartIntent);
        this.finish();
    } else {/*from  ww  w. j av a 2s .c  o  m*/
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("market://details?id=edu.sage.mail"));
        startActivity(i);
    }
}

From source file:com.fitc.dooropener.lib.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param status GCM message received.//from  w w  w. jav  a  2s  .c o m
 */
private void sendNotification(GcmDataPayload status) {

    /**
     * This code should find launcher activity of app using this librbary and set it as the what gets launched
     */
    Intent intent = null;
    final PackageManager packageManager = getPackageManager();
    Log.i(TAG, "PACKAGE NAME " + getPackageName());

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);

    for (final ResolveInfo resolveInfo : appList) {
        if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)
        {
            intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            break;
        }
    }
    PendingIntent pendingIntent = null;
    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(getResources().getString(R.string.notif_content_title))
            .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri);

    if (pendingIntent != null) {
        notificationBuilder.setContentIntent(pendingIntent);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}