Example usage for android.content Intent makeMainActivity

List of usage examples for android.content Intent makeMainActivity

Introduction

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

Prototype

public static Intent makeMainActivity(ComponentName mainActivity) 

Source Link

Document

Create an intent to launch the main (root) activity of a task.

Usage

From source file:Main.java

public static Intent getDefaultAlarmsIntent(Context context) {
    // TODO: consider using AlarmClock.ACTION_SET_ALARM, although it requires a permission
    PackageManager pm = context.getPackageManager();
    for (String packageName : CLOCK_PACKAGES) {
        try {/*from  w w  w  .java 2  s  . c  o m*/
            ComponentName cn = new ComponentName(packageName, "com.android.deskclock.AlarmClock");
            pm.getActivityInfo(cn, 0);
            return Intent.makeMainActivity(cn);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    }
    return getDefaultClockIntent(context);
}

From source file:org.chromium.ChromePushMessaging.java

static public void handlePushMessage(Context context, Intent intent) {
    JSONObject payload = new JSONObject();
    try {//from www . j  a  va 2s.  c  o m
        for (String key : intent.getExtras().keySet()) {
            payload.put(key, intent.getStringExtra(key));
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error construction push message payload: " + e);
        return;
    }
    String payloadString = payload.toString();
    if (webView == null) {
        try {
            String activityClass = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES).activities[0].name;
            Intent activityIntent = Intent.makeMainActivity(new ComponentName(context, activityClass));
            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activityIntent.putExtra(PAYLOAD_LABEL, payloadString);
            pendingMessages.add(payloadString);
            context.startActivity(activityIntent);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to make startActivity intent: " + e);
        }
        return;
    }
    if (!safeToFireMessages) {
        pendingMessages.add(payloadString);
        return;
    }
    fireOnMessage(payloadString);
}

From source file:org.chromium.ChromeGcm.java

static public void startApp(Context context) {
    if (webView == null) {
        try {//  w  w w  . j a  v  a2  s .  c o  m
            String activityClass = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES).activities[0].name;
            Intent activityIntent = Intent.makeMainActivity(new ComponentName(context, activityClass));
            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activityIntent.putExtra(PAYLOAD_LABEL, "dummy");
            context.startActivity(activityIntent);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to make startActivity intent: " + e);
        }
    }
}

From source file:com.google.android.apps.muzei.NewWallpaperNotificationReceiver.java

public static void maybeShowNewArtworkNotification(Context context, Artwork artwork,
        BitmapRegionLoader bitmapRegionLoader) {
    if (artwork == null || artwork.getImageUri() == null || bitmapRegionLoader == null) {
        return;//from   www .j  a v  a 2 s . c o m
    }

    ArtDetailOpenedClosedEvent adoce = EventBus.getDefault().getStickyEvent(ArtDetailOpenedClosedEvent.class);
    if (adoce != null && adoce.isArtDetailOpened()) {
        return;
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    if (!sp.getBoolean(PREF_ENABLED, true)) {
        return;
    }

    String lastSeenImageUri = sp.getString(PREF_LAST_SEEN_NOTIFICATION_IMAGE_URI, null);
    if (TextUtils.equals(lastSeenImageUri, artwork.getImageUri().toString())) {
        return;
    }

    Rect rect = new Rect();
    int width = bitmapRegionLoader.getWidth();
    int height = bitmapRegionLoader.getHeight();
    if (width > height) {
        rect.set((width - height) / 2, 0, (width + height) / 2, height);
    } else {
        rect.set(0, (height - width) / 2, width, (height + width) / 2);
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = ImageUtil.calculateSampleSize(height, 256);
    Bitmap largeIcon = bitmapRegionLoader.decodeRegion(rect, options);

    NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_muzei).setPriority(Notification.PRIORITY_MIN).setAutoCancel(true)
            .setContentTitle(artwork.getTitle())
            .setContentText(context.getString(R.string.notification_new_wallpaper)).setLargeIcon(largeIcon)
            .setContentIntent(PendingIntent.getActivity(context, 0,
                    Intent.makeMainActivity(new ComponentName(context, MuzeiActivity.class)),
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0,
                    new Intent(context, NewWallpaperNotificationReceiver.class)
                            .setAction(ACTION_MARK_NOTIFICATION_READ),
                    PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(nb).bigLargeIcon(null)
            .setBigContentTitle(artwork.getTitle()).setSummaryText(artwork.getByline()).bigPicture(largeIcon);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, style.build());

    // Clear any last-seen notification
    sp.edit().remove(PREF_LAST_SEEN_NOTIFICATION_IMAGE_URI).apply();
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.nowplaying.NowPlayingActivity.java

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Dart.inject(this);
    AndroidInjection.inject(this);

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        final Intent intent = Intent.makeMainActivity(new ComponentName(this, HomeActivity.class));
        startActivity(intent);//ww w.j a  va2s .  c  o  m
        return;
    }

    if (TransitionUtils.supportsActivityTransitions()) {
        NowPlayingActivityLollipop.applyTransitions(this);
    }

    mRequestManager = Glide.with(this);

    mTransitionPostponed = false;
    mTransitionStarted = false;

    final ActivityNowplayingBinding binding = DataBindingUtil.setContentView(this,
            R.layout.activity_nowplaying);
    ButterKnife.bind(this);

    ViewCompat.setTransitionName(albumArt, TRANSITION_NAME_ALBUM_ART);
    ViewCompat.setTransitionName(root, TRANSITION_NAME_ROOT);

    mModel.setBtnPlayRes(R.drawable.ic_play_arrow_white_36dp);
    mModel.setShuffleEnabled(mPlaybackParams.isShuffleEnabled());
    mModel.setRepeatMode(mPlaybackParams.getRepeatMode());

    binding.setModel(mModel);
    setSupportActionBar(toolbar);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int i, final boolean b) {

        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
            mSeekBarTracking = true;
        }

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
            mPlaybackServiceControl.seek((float) seekBar.getProgress() / (float) seekBar.getMax());
            mSeekBarTracking = false;
        }
    });

    mIntentHandler = new NowPlayingActivityIntentHandler(this);
    mIntentHandler.handleIntent(getIntent());

    mNavigationController = new NavigationController(this, findViewById(R.id.drawerLayout));
    mNavigationController.bind();
}

From source file:android.app.Activity.java

/**
 * Obtain an {@link Intent} that will launch an explicit target activity specified by
 * this activity's logical parent. The logical parent is named in the application's manifest
 * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
 * Activity subclasses may override this method to modify the Intent returned by
 * super.getParentActivityIntent() or to implement a different mechanism of retrieving
 * the parent intent entirely./*  www  .jav a 2s .co m*/
 *
 * @return a new Intent targeting the defined parent of this activity or null if
 *         there is no valid parent.
 */
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null ? Intent.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + "' in manifest");
        return null;
    }
}