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.baruckis.nanodegree.spotifystreamer.PlayerService.java

private void buildNotification(NotificationCompat.Action action, boolean updateLargeIcon) {

    CustomTrack playSong = getCurrentTrack();

    if (playSong == null)
        return;//  w ww  . j av a  2 s . c om

    NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
    style.setShowActionsInCompactView(0, 1, 2);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // open last activity when tapping notification
    Intent openAppIntent = new Intent(this, MainArtistsListActivity.class);
    openAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    openAppIntent.setAction(Intent.ACTION_MAIN);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, openAppIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    builder.setSmallIcon(android.R.drawable.ic_media_play).setLargeIcon(mLargeIconBitmap)
            .setContentTitle(playSong.getTrackName()).setContentText(playSong.getArtistsNamesList())
            .setStyle(style).setShowWhen(false) // hide time in notification
            .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS))
            .addAction(action).addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT));

    if (updateLargeIcon) {

        Picasso.Builder picassoBuilder = new Picasso.Builder(this);
        Picasso picasso = picassoBuilder.build();
        // to avoid too many requests when user jumps on different tracks too fast, cancel latest one.
        picasso.cancelRequest(mTarget);

        mTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                mLargeIconBitmap = bitmap;
                builder.setLargeIcon(mLargeIconBitmap);

                mNotification = builder.build();

                if (mShowNotification) {
                    showCancelNotification(true);
                }
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }
        };

        String url = playSong.getCustomImageBig().getUrl();

        if (url != null) {
            picasso.load(url).into(mTarget);
        }
    }

    mNotification = builder.build();
    if (mShowNotification) {
        showCancelNotification(true);
    }
}

From source file:cz.maresmar.sfm.view.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Welcome guide
    if (mPrefs.getBoolean(SettingsContract.FIRST_RUN, SettingsContract.FIRST_RUN_DEFAULT)) {
        Intent firstRunIntent = new Intent(this, WelcomeActivity.class);
        firstRunIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(firstRunIntent);//w  ww .j av a  2  s .c  o  m
        finish();
    }
    // Main UI
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Floating button
    mOkFab = findViewById(R.id.main_ok_fab);
    mOkFab.setOnClickListener(view -> {
        AsyncTask.execute(() -> ActionUtils.saveEdits(this, getUserUri()));
        setMenuEditUiShown(false);
        Snackbar.make(view, R.string.main_edit_saved_text, Snackbar.LENGTH_LONG).setAction("Ok", v -> {
        }).show();
    });
    mDiscardFab = findViewById(R.id.main_discard_fab);
    mDiscardFab.setOnClickListener(view -> {
        AsyncTask.execute(() -> ActionUtils.discardEdits(this, getUserUri()));
        setMenuEditUiShown(false);
    });

    // Material Drawer
    // Prepare users section
    mProfiles = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header)
            .addProfiles(ADD_USER_DRAWER_ITEM, MANAGE_USER_DRAWER_ITEM).withOnAccountHeaderListener(this)
            .build();

    // Prepare menu section
    mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(mProfiles)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(R.string.drawer_today).withIcon(R.drawable.ic_today)
                            .withIconTintingEnabled(true).withIdentifier(TODAY_DRAWER_ID),
                    new PrimaryDrawerItem().withName(R.string.drawer_day).withIcon(R.drawable.ic_days)
                            .withIconTintingEnabled(true).withIdentifier(DAY_DRAWER_ID),
                    mPortalDrawerItem = new ExpandableDrawerItem().withName(R.string.drawer_portal)
                            .withIcon(R.drawable.ic_location).withIconTintingEnabled(true)
                            .withIdentifier(PORTAL_EXPANDABLE_DRAWER_ID).withSelectable(false)
                            .withSubItems(ADD_PORTAL_DRAWER_ITEM, MANAGE_PORTAL_DRAWER_ITEM),
                    new PrimaryDrawerItem().withName(R.string.drawer_orders)
                            .withIcon(R.drawable.ic_shopping_cart).withIconTintingEnabled(true)
                            .withIdentifier(ORDERS_DRAWER_ID),
                    new SectionDrawerItem().withName(R.string.drawer_help_and_settings_group),
                    new SecondaryDrawerItem().withName(R.string.drawer_feedback).withIcon(R.drawable.ic_send)
                            .withIconTintingEnabled(true).withIdentifier(FEEDBACK_DRAWER_ID)
                            .withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_settings)
                            .withIcon(R.drawable.ic_settings).withIconTintingEnabled(true)
                            .withIdentifier(SETTINGS_DRAWER_ID).withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_help).withIcon(R.drawable.ic_help)
                            .withIconTintingEnabled(true).withIdentifier(HELP_DRAWER_ID).withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_about).withIcon(R.drawable.ic_info)
                            .withIconTintingEnabled(true).withIdentifier(ABOUT_DRAWER_ID).withSelectable(false))
            .withOnDrawerItemClickListener(this).withOnDrawerNavigationListener(this)
            .withActionBarDrawerToggleAnimated(true).withSavedInstance(savedInstanceState).build();

    // Selected user
    if (mSelectedUserId == SettingsContract.LAST_USER_UNKNOWN) {
        mSelectedUserId = mPrefs.getLong(SettingsContract.LAST_USER, SettingsContract.LAST_USER_UNKNOWN);
    }

    // Selected fragment
    if (mSelectedFragmentId == SettingsContract.LAST_FRAGMENT_UNKNOWN) {
        mSelectedFragmentId = mPrefs.getLong(SettingsContract.LAST_FRAGMENT,
                SettingsContract.LAST_FRAGMENT_UNKNOWN);
    }

    String action;
    if (getIntent().getAction() != null) {
        action = getIntent().getAction();
    } else {
        action = Intent.ACTION_MAIN;
    }

    switch (action) {
    case Intent.ACTION_MAIN:
        break;
    case SHOW_ORDERS_ACTION:
        mSelectedFragmentId = ORDER_FRAGMENT_ID;
        break;
    case SHOW_CREDIT_ACTION:
        mDrawer.openDrawer();
        break;
    default:
        throw new UnsupportedOperationException("Unknown action " + action);

    }
    mAppBarLayout = findViewById(R.id.appbar);

    mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getIntArray(R.array.swipeRefreshColors));
    mSwipeRefreshLayout.setOnRefreshListener(this::startRefresh);

    // Load users from db
    getSupportLoaderManager().initLoader(USER_LOADER_ID, null, this);

    LocalBroadcastManager.getInstance(this).registerReceiver(mSyncResultReceiver,
            new IntentFilter(SyncHandler.BROADCAST_SYNC_EVENT));
    LocalBroadcastManager.getInstance(this).registerReceiver(mActionsEventReceiver,
            new IntentFilter(ActionUtils.BROADCAST_ACTION_EVENT));
}

From source file:org.wso2.app.catalog.AppListActivity.java

/**
 * Load device home screen.// ww  w .  ja  v a  2  s  .com
 */
private void loadHomeScreen() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    super.onBackPressed();
}

From source file:com.brewcrewfoo.performance.activities.PCSettings.java

public static boolean isDownloadManagerAvailable(Context context) {
    try {/* w  w w .ja  va 2s. co  m*/
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClassName("com.android.providers.downloads.ui",
                "com.android.providers.downloads.ui.DownloadList");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:info.papdt.blacklight.ui.statuses.AbsTimeLineFragment.java

protected void newPost() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.setClass(getActivity(), NewPostActivity.class);
    startActivity(i);//from w  w  w  . j  a  v  a 2  s.  c om
}

From source file:org.eyeseetea.malariacare.DashboardActivity.java

public void confirmExitApp() {
    Log.d(TAG, "back pressed");
    new AlertDialog.Builder(this).setTitle(R.string.confirmation_really_exit_title)
            .setMessage(R.string.confirmation_really_exit).setNegativeButton(android.R.string.no, null)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }/*from   w  w w . j  a  va2  s .c o m*/
            }).create().show();
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

@SimpleFunction(description = "Create a notication with message to wake up "
        + "another activity when tap on the notification")
public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate,
        String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException {

    Intent activityToLaunch = new Intent(Intent.ACTION_MAIN);

    Log.i(TAG, "packageName: " + packageName);
    Log.i(TAG, "className: " + className);

    // for local AI instance, all classes are under the package
    // "appinventor.ai_test"
    // but for those runs on Google AppSpot(AppEngine), the package name will be
    // "appinventor.ai_GoogleAccountUserName"
    // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr
    // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1

    ComponentName component = new ComponentName(packageName, className);
    activityToLaunch.setComponent(component);
    activityToLaunch.putExtra(extraKey, extraVal);

    Log.i(TAG, "we found the class for intent to send into notificaiton");

    activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0);

    Long currentTimeMillis = System.currentTimeMillis();
    notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis);

    Log.i(TAG, "After creating notification");
    notification.contentIntent = mContentIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // reset the notification
    notification.defaults = 0;//from   ww w .j ava  2s .  c  o  m

    if (enabledSound)
        notification.defaults |= Notification.DEFAULT_SOUND;

    if (enabledVibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text,
            mContentIntent);
    Log.i(TAG, "after updated notification contents");
    mNM.notify(PROBE_NOTIFICATION_ID, notification);
    Log.i(TAG, "notified");

}

From source file:com.samsung.multiwindow.MultiWindow.java

/**
 * Get the MultiWindow enabled applications and activity names
 * //  ww  w  .j  a v  a2  s  .  c  om
 * @param windowType
 *            The window type freestyle or splitstyle.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * 
 */
private void getMultiWindowApps(final String windowType, final CallbackContext callbackContext)
        throws JSONException {

    if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
        Log.d(TAG, "Inside getMultiWindowApps");
    }
    cordova.getThreadPool().execute(new Runnable() {

        public void run() {

            JSONArray multiWindowApps = new JSONArray();
            Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
            List<ResolveInfo> resolveInfos = cordova.getActivity().getPackageManager().queryIntentActivities(
                    intent, PackageManager.GET_RESOLVED_FILTER | PackageManager.GET_META_DATA);

            try {
                // Get the multiwindow enabled applications

                int index = 0;
                for (ResolveInfo r : resolveInfos) {
                    if (r.activityInfo != null && r.activityInfo.applicationInfo.metaData != null) {
                        if (r.activityInfo.applicationInfo.metaData
                                .getBoolean("com.sec.android.support.multiwindow")
                                || r.activityInfo.applicationInfo.metaData
                                        .getBoolean("com.samsung.android.sdk.multiwindow.enable")) {
                            JSONObject appInfo = new JSONObject();
                            boolean bUnSupportedMultiWinodw = false;
                            if (windowType.equalsIgnoreCase("splitstyle")) {
                                if (r.activityInfo.metaData != null) {
                                    String activityWindowStyle = r.activityInfo.metaData
                                            .getString("com.sec.android.multiwindow.activity.STYLE");
                                    if (activityWindowStyle != null) {
                                        ArrayList<String> activityWindowStyles = new ArrayList<String>(
                                                Arrays.asList(activityWindowStyle.split("\\|")));
                                        if (!activityWindowStyles.isEmpty()) {
                                            if (activityWindowStyles.contains("fullscreenOnly")) {
                                                bUnSupportedMultiWinodw = true;
                                            }
                                        }
                                    }
                                }
                            }

                            if (!bUnSupportedMultiWinodw || !windowType.equalsIgnoreCase("splitstyle")) {
                                appInfo.put("packageName", r.activityInfo.applicationInfo.packageName);
                                appInfo.put("activity", r.activityInfo.name);
                                multiWindowApps.put(index++, appInfo);
                            }
                        }
                    }
                }
                callbackContext.success(multiWindowApps);
            } catch (Exception e) {

                callbackContext.error(e.getMessage());
            }

        }
    });
}

From source file:org.mariotaku.twidere.provider.TweetStoreProvider.java

private void onNewItemsInserted(final Uri uri, final int count, final ContentValues... values) {
    if (uri == null || values == null || values.length == 0 || count == 0)
        return;//www.ja  v  a2s  .com
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    switch (getTableId(uri)) {
    case URI_STATUSES: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false))
            return;
        final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount);
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME);
        content_intent.putExtras(content_extras);
        builder.setOnlyAlertOnce(true);
        final Notification notification = buildNotification(builder, res.getString(R.string.new_notifications),
                message, message, R.drawable.ic_stat_tweet, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, notification);
        break;
    }
    case URI_MENTIONS: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false))
            return;
        if (mNewMentionsCount > 1) {
            builder.setNumber(mNewMentionsCount);
        }
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        ContentValues notification_value = null;
        int notified_count = 0;
        for (final ContentValues value : values) {
            final String screen_name = value.getAsString(Statuses.SCREEN_NAME);
            if (!isFiltered(mDatabase, screen_name, value.getAsString(Statuses.SOURCE),
                    value.getAsString(Statuses.TEXT_PLAIN))) {
                if (notification_value == null) {
                    notification_value = value;
                }
                screen_names.add(screen_name);
                notified_count++;
            }
        }
        if (notified_count == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_STATUS);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID,
                    notification_value.getAsString(Statuses.ACCOUNT_ID));
            uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID,
                    notification_value.getAsString(Statuses.STATUS_ID));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());

        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS);
            content_intent.putExtras(content_extras);
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_mention_multiple,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_mention,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME));
        }
        final String message = notification_value.getAsString(Statuses.TEXT_PLAIN);
        final String profile_image_url_string = notification_value.getAsString(Statuses.PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_mention, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, notification);
        break;
    }
    case URI_DIRECT_MESSAGES_INBOX: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false))
            return;
        if (mNewMessagesCount > 1) {
            builder.setNumber(mNewMessagesCount);
        }
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        final ContentValues notification_value = values[0];
        for (final ContentValues value : values) {
            screen_names.add(value.getAsString(DirectMessages.SENDER_SCREEN_NAME));
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_direct_message_multiple,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_direct_message,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME));
        }
        final String message = notification_value.getAsString(DirectMessages.TEXT_PLAIN);
        final String profile_image_url_string = notification_value
                .getAsString(DirectMessages.SENDER_PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        if (values.length == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            final long account_id = notification_value.getAsLong(DirectMessages.ACCOUNT_ID);
            final long conversation_id = notification_value.getAsLong(DirectMessages.SENDER_ID);
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
            uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES);
            content_intent.putExtras(content_extras);
        }
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_direct_message, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, notification);
        break;
    }
    }
}

From source file:com.sdingba.su.lanya.MainActivity.java

@Override
public void onBackPressed() {
    if (mState == UART_PROFILE_CONNECTED) {
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);//from w ww.  ja va 2  s. c  om
        showMessage("onBackPressed : nRFUART's running in background.\n " + " Disconnect to exit");
    } else {
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.popup_title)
                .setMessage(R.string.popup_message)
                .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.popup_no, null).show();
    }
}