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.google.android.testing.nativedriver.server.AndroidNativeDriver.java

/** Start a new activity either in a new task or the current task. */
public void startActivity(Class<?> activityClass) {
    Intent intent = new Intent(context.getInstrumentation().getContext(), activityClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    context.getInstrumentation().startActivitySync(intent);
}

From source file:com.fvd.nimbus.MainActivity.java

public static void deleteShortcut(Context context) {
    Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    ComponentName comp = new ComponentName("com.fvd.nimbus", "com.fvd.nimbus.MainActivity");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
    context.sendBroadcast(shortcut);//from   w  w  w .ja va 2 s.com
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.SpydroidActivity.java

@Override
public void onBackPressed() {
    Intent setIntent = new Intent(Intent.ACTION_MAIN);
    setIntent.addCategory(Intent.CATEGORY_HOME);
    setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(setIntent);/*  www  . j a v  a 2s.  co  m*/
}

From source file:com.guodong.sun.guodong.activity.MainActivity.java

@Override
public void onBackPressed() {
    if (JCVideoPlayer.backPress())
        return;//ww w  .  j a v a 2 s .com

    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();
    } else {
        Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
        launcherIntent.addCategory(Intent.CATEGORY_HOME);
        startActivity(launcherIntent);
        //            if ((System.currentTimeMillis() - exitTime) > 2000) {
        //                Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show();
        //                exitTime = System.currentTimeMillis();
        //            } else {
        //                String size = GlideCacheUtil.getInstance().getCacheSize(MainActivity.this);
        //                if (Double.valueOf(size.substring(0, size.length() - 2)) >= 50)
        //                    GlideCacheUtil.getInstance().clearImageAllCache(MainActivity.this);
        //                super.onBackPressed();
        //            }
    }
}

From source file:com.trellmor.berrytubechat.ChatActivity.java

@Override
public void onBackPressed() {
    Intent backtoHome = new Intent(Intent.ACTION_MAIN);
    backtoHome.addCategory(Intent.CATEGORY_HOME);
    backtoHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(backtoHome);/*from ww w .j av a2  s.  c  o m*/
}

From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java

private void open(ApplicationInfo item) {
    // open app/*from w  ww. java  2  s.  c o  m*/
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(item.packageName);
    List<ResolveInfo> resolveInfoList = getActivity().getPackageManager().queryIntentActivities(resolveIntent,
            0);
    if (resolveInfoList != null && resolveInfoList.size() > 0) {
        ResolveInfo resolveInfo = resolveInfoList.get(0);
        String activityPackageName = resolveInfo.activityInfo.packageName;
        String className = resolveInfo.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName componentName = new ComponentName(activityPackageName, className);

        intent.setComponent(componentName);
        startActivity(intent);
    }
}

From source file:org.spinsuite.bchat.util.BCNotificationHandle.java

/**
 * Instance Notification Manager//  w  w  w. java 2 s. co  m
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com
 * @return void
 */
private void instanceNM(String p_SPS_BC_Request_UUID) {
    if (m_NotificationManager == null) {
        m_NotificationManager = (NotificationManager) m_Ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    }
    //   
    m_Builder = new NotificationCompat.Builder(m_Ctx);
    Intent intent = new Intent(m_Ctx, V_BChat.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    //   Add Parameter Request
    intent.putExtra("SPS_BC_Request_UUID", p_SPS_BC_Request_UUID);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //   Set Main Activity
    PendingIntent m_PendingIntent = PendingIntent.getActivity(m_Ctx, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    m_Builder.setContentIntent(m_PendingIntent);
    m_Builder.setAutoCancel(true);
    //   Set Vibration
    m_Builder.setVibrate(new long[] { 1000, 500, 1000, 500, 1000 });
    //   Set Light
    m_Builder.setLights(Color.GREEN, 3000, 3000);
    //   Set Sound
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    m_Builder.setSound(alarmSound);
}

From source file:com.appsimobile.appsihomeplugins.dashclock.phone.SmsExtension.java

@Override
public void onUpdateData(FieldValues.Builder builder) {
    long lastUnreadThreadId = 0;
    Set<Long> unreadThreadIds = new HashSet<Long>();
    Set<String> unreadThreadParticipantNames = new HashSet<String>();
    boolean showingAllConversationParticipants = false;

    Cursor cursor = tryOpenSimpleThreadsCursor();
    if (cursor != null) {
        while (cursor.moveToNext()) {
            if (cursor.getInt(SimpleThreadsQuery.READ) == 0) {
                long threadId = cursor.getLong(SimpleThreadsQuery._ID);
                unreadThreadIds.add(threadId);
                lastUnreadThreadId = threadId;

                // Some devices will fail on tryOpenMmsSmsCursor below, so
                // store a list of participants on unread threads as a fallback.
                String recipientIdsStr = cursor.getString(SimpleThreadsQuery.RECIPIENT_IDS);
                if (!TextUtils.isEmpty(recipientIdsStr)) {
                    String[] recipientIds = TextUtils.split(recipientIdsStr, " ");
                    for (String recipientId : recipientIds) {
                        Cursor canonAddrCursor = tryOpenCanonicalAddressCursorById(Long.parseLong(recipientId));
                        if (canonAddrCursor == null) {
                            continue;
                        }/*from   w w w. j a va 2  s. c o  m*/
                        if (canonAddrCursor.moveToFirst()) {
                            String address = canonAddrCursor.getString(CanonicalAddressQuery.ADDRESS);
                            String displayName = getDisplayNameForContact(0, address);
                            if (!TextUtils.isEmpty(displayName)) {
                                unreadThreadParticipantNames.add(displayName);
                            }
                        }
                        canonAddrCursor.close();
                    }
                }
            }
        }
        cursor.close();

        LOGD(TAG, "Unread thread IDs: [" + TextUtils.join(", ", unreadThreadIds) + "]");
    }

    int unreadConversations = 0;
    StringBuilder names = new StringBuilder();
    cursor = tryOpenMmsSmsCursor();
    if (cursor != null) {
        // Most devices will hit this code path.
        while (cursor.moveToNext()) {
            // Get display name. SMS's are easy; MMS's not so much.
            long id = cursor.getLong(MmsSmsQuery._ID);
            long contactId = cursor.getLong(MmsSmsQuery.PERSON);
            String address = cursor.getString(MmsSmsQuery.ADDRESS);
            long threadId = cursor.getLong(MmsSmsQuery.THREAD_ID);
            if (unreadThreadIds != null && !unreadThreadIds.contains(threadId)) {
                // We have the list of all thread IDs (same as what the messaging app uses), and
                // this supposedly unread message's thread isn't in the list. This message is
                // likely an orphaned message whose thread was deleted. Not skipping it is
                // likely the cause of http://code.google.com/p/dashclock/issues/detail?id=8
                LOGD(TAG, "Skipping probably orphaned message " + id + " with thread ID " + threadId);
                continue;
            }

            ++unreadConversations;
            lastUnreadThreadId = threadId;

            if (contactId == 0 && TextUtils.isEmpty(address) && id != 0) {
                // Try MMS addr query
                Cursor addrCursor = tryOpenMmsAddrCursor(id);
                if (addrCursor != null) {
                    if (addrCursor.moveToFirst()) {
                        contactId = addrCursor.getLong(MmsAddrQuery.CONTACT_ID);
                        address = addrCursor.getString(MmsAddrQuery.ADDRESS);
                    }
                    addrCursor.close();
                }
            }

            String displayName = getDisplayNameForContact(contactId, address);

            if (names.length() > 0) {
                names.append(", ");
            }
            names.append(displayName);
        }
        cursor.close();

    } else {
        // In case the cursor is null (some Samsung devices like the Galaxy S4), use the
        // fall back on the list of participants in unread threads.
        unreadConversations = unreadThreadIds.size();
        names.append(TextUtils.join(", ", unreadThreadParticipantNames));
        showingAllConversationParticipants = true;
    }

    Intent clickIntent;
    if (unreadConversations == 1 && lastUnreadThreadId > 0) {
        clickIntent = new Intent(Intent.ACTION_VIEW, TelephonyProviderConstants.MmsSms.CONTENT_CONVERSATIONS_URI
                .buildUpon().appendPath(Long.toString(lastUnreadThreadId)).build());
    } else {
        clickIntent = IntentCompat.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MESSAGING);
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(),
            DashClockHomeExtension.DASHCLOCK_EXTENSION_SMS, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.leftImageResId(R.drawable.ic_extension_sms).intent(pendingIntent).header(getResources()
            .getQuantityString(R.plurals.sms_title_template, unreadConversations, unreadConversations));
    if (unreadConversations > 0) {
        builder.text(getString(showingAllConversationParticipants ? R.string.sms_body_all_participants_template
                : R.string.sms_body_template, names.toString()));
    }

    /*
            
    publishUpdate(new ExtensionData()
        .visible(unreadConversations > 0)
        .icon(R.drawable.ic_extension_sms)
        .status(Integer.toString(unreadConversations))
        .expandedTitle(
                getResources().getQuantityString(
                        R.plurals.sms_title_template, unreadConversations,
                        unreadConversations))
        .expandedBody(getString(showingAllConversationParticipants
                ? R.string.sms_body_all_participants_template
                : R.string.sms_body_template,
                names.toString()))
        .clickIntent(clickIntent));
    */
}

From source file:com.abhinavjhanwar.android.egg.neko.Cat.java

public Notification.Builder buildNotification(Context context) {
    final Bundle extras = new Bundle();
    extras.putString("android.substName", context.getString(R.string.app_name));
    final Intent intent = new Intent(Intent.ACTION_MAIN).setClass(context, NekoLand.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return new Notification.Builder(context)
                .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon))
                .setLargeIcon(createLargeIcon(context)).setColor(getBodyColor())
                .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(NekoService.notificationText)
                .setShowWhen(true).setCategory(Notification.CATEGORY_STATUS).setContentText(getName())
                .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)).setAutoCancel(true)
                .setVibrate(PURR).addExtras(extras);
    }/* www.j  av  a 2  s.co  m*/
    return new Notification.Builder(context).setSmallIcon(R.drawable.stat_icon)
            .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(OldService.notificationText)
            .setContentText(getName()).setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
            .setAutoCancel(true).setVibrate(PURR);
}

From source file:com.microsoft.rightsmanagement.sampleapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // instantiate/get reference on retain-able Fragment instance which hold IAsyncTask
    FragmentManager fragmentManager = getSupportFragmentManager();
    mMsipcTaskFragment = (MsipcTaskFragment) fragmentManager.findFragmentByTag(MsipcTaskFragment.TAG);
    // If the Fragment is not null then it is retained across a configuration change.
    if (mMsipcTaskFragment == null) {
        mMsipcTaskFragment = new MsipcTaskFragment();
        fragmentManager.beginTransaction().add(mMsipcTaskFragment, MsipcTaskFragment.TAG).commit();
    }/*ww  w.  j  a va 2s .com*/
    mTextEditorFragment = (TextEditorFragment) getSupportFragmentManager()
            .findFragmentByTag(TextEditorFragment.TAG);
    if (savedInstanceState == null) {
        // handle incoming intent
        Intent incommingIntent = getIntent();
        String action = incommingIntent.getAction();
        if ((action.compareTo(Intent.ACTION_VIEW) == 0) || (action.compareTo(Intent.ACTION_EDIT) == 0)) {
            // Application state doesn't exist. intent is view.
            mUriOfFilePendingConsumption = incommingIntent.getData();
        } else if (action.compareTo(Intent.ACTION_MAIN) == 0) {
            // Show Log dialog only on first launch
            showCustomerExperienceDataConsentDialogFragmentIfNeeded(new CompletionCallback<Void>() {

                @Override
                public void onSuccess(Void item) {
                    setToShowCustomerExperienceDataConsentDialogFragmentAgainOnStart(false);
                }

                @Override
                public void onCancel() {
                    setToShowCustomerExperienceDataConsentDialogFragmentAgainOnStart(true);
                    finish();
                }
            });
            createTextEditorFragment(TextEditorMode.NotEnforced, null);
        } else {
            throw new RuntimeException("shouldn't reach here");
        }
    }
}