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:jieehd.villain.updater.VillainUpdater.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;

    }//from   w  ww.  j a  v a  2  s  . c o  m
    if (haveConnectedWifi == false && haveConnectedMobile == false) {
        Log.d("Network State", "false");
        AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this);
        alert.setTitle("No Data Connection!");
        alert.setMessage(
                "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates.");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                // TODO Auto-generated method stub
                final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                final ComponentName cn = new ComponentName("com.android.settings",
                        "com.android.settings.wifi.WifiSettings");
                intent.setComponent(cn);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }

        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                return;
            }
        });
        alert.show();

    } else {
        download();
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * Home/*  w w  w. java 2  s  .  c  o  m*/
 * @param context
 */
public static void goHome(Context context) {
    Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(mHomeIntent);
}

From source file:com.thelastcrusade.soundstream.CoreActivity.java

@Override
public void onBackPressed() {
    //if we are in the connect fragment or the menu is open, 
    //back out of the app by pulling up the home screen
    if (getTitle().equals(getString(R.string.select)) || getSlidingMenu().isMenuShowing()) {
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);//  ww  w  .  j  a v  a  2s.  c  o m
    }
    //otherwise, open the menu
    else {
        showMenu();
    }

}

From source file:com.uphyca.testing.support.v4.FragmentUnitTestCase.java

private void attachActivity(Object lastNonConfigurationInstance) throws Exception {
    if (mActivityAttached) {
        return;/*  ww w  . j  ava  2s .c om*/
    }

    IBinder token = null;
    if (mApplication == null) {
        setApplication(Robolectric.application);
    }
    if (mActivity == null) {
        setActivity(new MockFragmentActivity());
    }
    ComponentName cn = new ComponentName(mActivity.getClass().getPackage().getName(),
            mActivity.getClass().getName());
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(cn);
    ActivityInfo info = new ActivityInfo();
    CharSequence title = mActivity.getClass().getName();
    mMockParent = new MockParent();
    String id = null;
    ActivityTrojanHorse.callAttach(getInstrumentation(), mActivity, mFragmentContext, token, mApplication,
            intent, info, title, mMockParent, id, lastNonConfigurationInstance);

    mActivityAttached = true;
}

From source file:org.bohrmeista.chan.ui.service.WatchNotifier.java

@SuppressWarnings("deprecation")
private Notification getNotificationFor(String tickerText, String title, String content, int count,
        List<CharSequence> lines, boolean makeSound, Pin targetPin) {

    Intent intent = new Intent(this, BoardActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    intent.putExtra("pin_id", targetPin == null ? -1 : targetPin.id);

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(pendingIntent);

    if (tickerText != null) {
        tickerText = tickerText.substring(0, Math.min(tickerText.length(), 50));
    }/*w  w w  .ja v  a 2s.c  o  m*/

    builder.setTicker(tickerText);
    builder.setContentTitle(title);
    builder.setContentText(content);

    if (count >= 0) {
        builder.setContentInfo(Integer.toString(count));
        builder.setNumber(count);
    }

    builder.setSmallIcon(R.drawable.ic_stat_notify);

    Intent pauseWatching = new Intent(this, WatchNotifier.class);
    pauseWatching.putExtra("pause_pins", true);

    PendingIntent pauseWatchingPending = PendingIntent.getService(this, 0, pauseWatching,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.addAction(R.drawable.ic_action_pause, getString(R.string.watch_pause_pins), pauseWatchingPending);

    if (makeSound) {
        builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }

    if (lines != null) {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
        for (CharSequence line : lines.subList(Math.max(0, lines.size() - 10), lines.size())) {
            style.addLine(line);
        }
        style.setBigContentTitle(title);
        builder.setStyle(style);
    }

    return builder.getNotification();
}

From source file:org.chromium.chrome.browser.sync.SyncNotificationController.java

/**
 * Creates an intent that launches an activity that requests the users password/passphrase.
 *
 * @return the intent for opening the password/passphrase activity
 *///from w  w w  .ja  v  a 2  s  .  c om
private Intent createPasswordIntent() {
    // Make sure we don't prompt too many times.
    mProfileSyncService.setPassphrasePrompted(true);

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(new ComponentName(mApplicationContext, mPassphraseRequestActivity));
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    // This activity will become the start of a new task on this history stack.
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // Clears the task stack above this activity if it already exists.
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return intent;
}

From source file:com.itime.team.itime.services.ITimeGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM message received.//from   w w  w .  j a  v  a2 s .c  o  m
 */
private void sendNotification(Bundle data) {
    ParcelableMessage message = new ParcelableMessage(data);
    if (message.messageType == null) {
        return;
    }

    Intent intent = new Intent(this, CheckLoginActivity.class);
    // Set ACTION_MAIN and CATEGORY_LAUNCHER is the key!
    // Even though CheckLoginActivity is finish and no longer exist, the app will return to the
    // foreground and CheckLoginActivity would not be created again. Demonstrated in the logcat
    // where on CheckLoginActivity onCreate, onResume.
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    // Do add this flags otherwise it will clear all the activity in the stack
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    String messageTitle = data.getString("alert", "ITime Message");
    String messageBody = data.getString("message_body", "ITime Message");
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notifications_active_black).setContentTitle(messageTitle)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.dcs.fakecurrencydetector.MainActivity.java

public void AppExit() {

    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/* w  w  w  . j av  a2s . c  o m*/

    /*int pid = android.os.Process.myPid();=====> use this if you want to kill your activity. But its not a good one to do.
    android.os.Process.killProcess(pid);*/

}

From source file:com.example.administrator.winsoftsalesproject.activity.NavHomeActivity.java

public void exitDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Do You Want To Exit?").setTitle("Exit App");

    builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
        @Override//  w w  w.ja  v  a2 s .c  o m
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            Intent homeIntent = new Intent(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_HOME);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            sessionManger.logoutUser();
            NavHomeActivity.this.finish();
            startActivity(homeIntent);
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}

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

public ArrayMap<String, String> getAvailableIconPacks() {
    ArrayMap<String, String> availableIconPacks = new ArrayMap<>();

    PackageManager pm = mContext.getPackageManager();

    // fetch installed icon packs for popular launchers
    Intent novaIntent = new Intent(Intent.ACTION_MAIN);
    novaIntent.addCategory(NOVA_LAUNCHER_THEME_NAME);
    List<ResolveInfo> novaTheme = pm.queryIntentActivities(novaIntent, PackageManager.GET_META_DATA);
    List<ResolveInfo> goTheme = pm.queryIntentActivities(new Intent(GO_LAUNCHER_THEME_NAME),
            PackageManager.GET_META_DATA);

    // merge those lists
    List<ResolveInfo> rinfo = new ArrayList<>(novaTheme);
    rinfo.addAll(goTheme);/*from w  w w. ja v  a  2s.co  m*/

    for (ResolveInfo ri : rinfo) {
        String packageName = ri.activityInfo.packageName;

        try {
            ApplicationInfo ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
            String label = pm.getApplicationLabel(ai).toString();
            Log.d(TAG, "Icon package = " + packageName + " title " + label);
            availableIconPacks.put(packageName, label);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Package not found = " + e);
        }
    }

    return availableIconPacks;
}