Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

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

Prototype

String ACTION_MAIN

To view the source code for android.content Intent ACTION_MAIN.

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

Usage

From source file:com.ce.skuniv.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();/*from  w  w w.j  a  v  a  2  s  . c o m*/
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    //      mNotificationManager.notify(Id, mBuilder.build());
}

From source file:com.ezio.multiwii.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();//from w  w w . j  a  v  a  2  s.  co m
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

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

From source file:com.codyy.lib.utils.ActivityUtils.java

/**
 * ?launcher activity/*ww w . j  a va 2  s . c om*/
 *
 * @param context     
 * @param packageName ??
 * @return launcher activity
 */
public static String getLauncherActivity(Context context, String packageName) {
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo info : infos) {
        if (info.activityInfo.packageName.equals(packageName)) {
            return info.activityInfo.name;
        }
    }
    return "no " + packageName;
}

From source file:hku.fyp14017.blencode.utils.StatusBarNotificationManager.java

public int createUploadNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }//from  w w  w. j  ava2s. c  om
    initNotificationManager(context);

    Intent uploadIntent = new Intent(context, MainMenuActivity.class);
    uploadIntent.setAction(Intent.ACTION_MAIN);
    uploadIntent = uploadIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, uploadIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationData data = new NotificationData(context, pendingIntent,
            hku.fyp14017.blencode.R.drawable.ic_stat, programName,
            hku.fyp14017.blencode.R.string.notification_upload_title_pending,
            hku.fyp14017.blencode.R.string.notification_upload_title_finished,
            hku.fyp14017.blencode.R.string.notification_upload_pending,
            hku.fyp14017.blencode.R.string.notification_upload_finished);

    int id = createNotification(context, data);
    showOrUpdateNotification(id, 0);
    return id;
}

From source file:com.android.leanlauncher.AppInfo.java

public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info, UserHandleCompat user) {
    long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
    return new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .setComponent(info.getComponentName())
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
            .putExtra(EXTRA_PROFILE, serialNumber);
}

From source file:org.mozilla.focus.shortcut.HomeScreen.java

/**
 * Switch to the the default home screen activity (launcher).
 *//*from   w  ww . ja  v  a2  s .  com*/
private static void goToHomeScreen(Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);

    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:org.mozilla.focus.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Settings.getInstance(this).shouldUseSecureMode()) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
    }/*from   w  w w  .  j  a v  a  2  s. c om*/

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    setContentView(R.layout.activity_main);

    SafeIntent intent = new SafeIntent(getIntent());

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0
            && !BrowsingSession.getInstance().isActive()) {
        // This Intent was launched from history (recent apps). Android will redeliver the
        // original Intent (which might be a VIEW intent). However if there's no active browsing
        // session then we do not want to re-process the Intent and potentially re-open a website
        // from a session that the user already "erased".
        intent = new SafeIntent(new Intent(Intent.ACTION_MAIN));
        setIntent(intent.getUnsafe());
    }

    if (savedInstanceState == null) {
        WebViewProvider.performCleanup(this);

        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            final String url = intent.getDataString();

            BrowsingSession.getInstance().loadCustomTabConfig(intent);

            if (Settings.getInstance(this).shouldShowFirstrun()) {
                pendingUrl = url;
                showFirstrun();
            } else {
                showBrowserScreen(url);
            }
        } else {
            if (Settings.getInstance(this).shouldShowFirstrun()) {
                showFirstrun();
            } else {
                showHomeScreen();
            }
        }
    }

    WebViewProvider.preload(this);
}

From source file:de.lespace.apprtc.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from ww w .j a  va2 s .  c o  m
*/
private void sendNotification(String message) {
    Intent intent = new Intent(this, ConnectActivity.class);
    // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, //0 Request code
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

}

From source file:cm.aptoide.ptdev.preferences.ManagerPreferences.java

private void removeLauncherShortcut(Context context) {
    final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));

    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Aptoide.getConfiguration().getMarketName());
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

    context.sendBroadcast(intent, null);
}

From source file:com.esminis.server.library.service.server.ServerNotification.java

public void show(Context context, CharSequence title, CharSequence titlePublic) {
    if (!preferences.contains(context, Preferences.SHOW_NOTIFICATION_SERVER)
            || !preferences.getBoolean(context, Preferences.SHOW_NOTIFICATION_SERVER)) {
        hide(context);/* w ww  .  j  av  a  2s.  c  o m*/
        return;
    }
    if (!serviceIsRunning) {
        serviceIsRunning = true;
        context.startService(new Intent(context, ServerNotificationService.class));
    }
    if (notification == null) {
        Builder builder = setupNotificationBuilder(context, title)
                .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                .setPublicVersion(setupNotificationBuilder(context, titlePublic).build());
        Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        builder.setContentIntent(
                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        notification = builder.build();
    }
    getManager(context).notify(NOTIFICATION_ID, notification);
}