Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

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

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

        // Use the query to search your data somehow
        searchField = intent.getStringExtra(SearchManager.QUERY);

        //            Log.d("Debug", "Search for..." + searchField);

        // Autorefresh
        refreshSwipeLayout();//  w ww  . j a  va  2 s . c om
        refreshCurrent();
    }

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        // Add torrent (file, url or magnet)
        addTorrentByIntent(intent);

        // // Activity is visible
        activityIsVisible = true;

        // Autorefresh
        refreshCurrent();

    }

    try {

        if (intent.getStringExtra("from").equals("NotifierService")) {

            saveLastState("completed");
            setSelectionAndTitle("completed");
            refresh("completed", currentLabel);
        }

        if (intent.getStringExtra("from").equals("RSSItemActivity")) {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);

            // // Activity is visble
            activityIsVisible = true;

            // Autorefresh
            refreshCurrent();
        }

        //            Log.d("Debug", "lastState (handle intent):End " );
    } catch (Exception e) {

        //            Log.e("Debug", "Handle intent: " + e.toString() );

    }
}

From source file:edu.mit.viral.shen.DroidFish.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case RESULT_SETTINGS:
        handlePrefsChange();//w w w .ja v a2s .  com
        break;
    case RESULT_EDITBOARD:
        if (resultCode == RESULT_OK) {
            try {
                String fen = data.getAction();
                startPosition = fen;
                ctrl.setData(fen);
                ctrl.setFENOrPGN(fen);
                mDatabase.updateStartFen(fen, game_number);
                ctrl.setFENOrPGN(fen);
                setBoardFlip(false);
            } catch (ChessParseError e) {
            }
        }
        break;
    case RESULT_LOAD_PGN:
        if (resultCode == RESULT_OK) {
            try {
                String pgn = data.getAction();
                int modeNr = ctrl.getGameMode().getModeNr();
                if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME))
                    newGameMode(GameMode.EDIT_GAME);
                ctrl.setFENOrPGN(pgn);
                setBoardFlip(true);
            } catch (ChessParseError e) {
                Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
            }
        }
        break;
    case RESULT_SELECT_SCID:
        if (resultCode == RESULT_OK) {
            String pathName = data.getAction();
            if (pathName != null) {
                Editor editor = settings.edit();
                editor.putString("currentScidFile", pathName);
                editor.putInt("currFT", FT_SCID);
                editor.commit();
                Intent i = new Intent(DroidFish.this, LoadScid.class);
                i.setAction("edu.mit.viral.shen.loadScid");
                i.putExtra("edu.mit.viral.shen.pathname", pathName);
                startActivityForResult(i, RESULT_LOAD_PGN);
            }
        }
        break;
    case RESULT_OI_PGN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadPGNFromFile(pathName);
        }
        break;
    case RESULT_OI_PGN_SAVE:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null) {
                if ((pathName.length() > 0) && !pathName.contains("."))
                    pathName += ".pgn";
                savePGNToFile(pathName, false);
            }
        }
        break;
    case RESULT_OI_FEN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadFENFromFile(pathName);
        }
        break;
    case RESULT_GET_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getStringExtra(Intent.EXTRA_TEXT);
            if (fen == null) {
                String pathName = getFilePathFromUri(data.getData());
                loadFENFromFile(pathName);
            }
            setFenHelper(fen);
        }
        break;
    case RESULT_LOAD_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getAction();
            setFenHelper(fen);
        }
        break;
    }
}

From source file:com.if3games.chessonline.DroidFish.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case RESULT_SETTINGS:
        handlePrefsChange();//from  ww w. ja v a  2s.c  o  m
        break;
    case RESULT_EDITBOARD:
        if (resultCode == RESULT_OK) {
            try {
                String fen = data.getAction();
                ctrl.setFENOrPGN(fen);
                setBoardFlip(false);
            } catch (ChessParseError e) {
            }
        }
        break;
    case RESULT_LOAD_PGN:
        if (resultCode == RESULT_OK) {
            try {
                String pgn = data.getAction();
                int modeNr = ctrl.getGameMode().getModeNr();
                if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME))
                    newGameMode(GameMode.EDIT_GAME);
                ctrl.setFENOrPGN(pgn);
                setBoardFlip(true);
            } catch (ChessParseError e) {
                Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
            }
        }
        break;
    case RESULT_SELECT_SCID:
        if (resultCode == RESULT_OK) {
            String pathName = data.getAction();
            if (pathName != null) {
                Editor editor = settings.edit();
                editor.putString("currentScidFile", pathName);
                editor.putInt("currFT", FT_SCID);
                editor.commit();
                Intent i = new Intent(DroidFish.this, LoadScid.class);
                i.setAction("com.if3games.chessonline.loadScid");
                i.putExtra("com.if3games.chessonline.pathname", pathName);
                startActivityForResult(i, RESULT_LOAD_PGN);
            }
        }
        break;
    case RESULT_OI_PGN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadPGNFromFile(pathName);
        }
        break;
    case RESULT_OI_PGN_SAVE:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null) {
                if ((pathName.length() > 0) && !pathName.contains("."))
                    pathName += ".pgn";
                savePGNToFile(pathName, false);
            }
        }
        break;
    case RESULT_OI_FEN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadFENFromFile(pathName);
        }
        break;
    case RESULT_GET_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getStringExtra(Intent.EXTRA_TEXT);
            if (fen == null) {
                String pathName = getFilePathFromUri(data.getData());
                loadFENFromFile(pathName);
            }
            setFenHelper(fen);
        }
        break;
    case RESULT_LOAD_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getAction();
            setFenHelper(fen);
        }
        break;
    // GMS
    case RC_SELECT_PLAYERS:
        // we got the result from the "select players" UI -- ready to create the room
        handleSelectPlayersResult(resultCode, data, gmsGameVariantNumber);
        break;
    case RC_INVITATION_INBOX:
        // we got the result from the "select invitation" UI (invitation inbox). We're
        // ready to accept the selected invitation:
        handleInvitationInboxResult(resultCode, data);
        break;
    case RC_WAITING_ROOM:
        // we got the result from the "waiting room" UI.
        if (resultCode == Activity.RESULT_OK) {
            // ready to start playing
            //Log.d(TAG, "Starting game (waiting room returned OK).");
            //if(!imNotFirst)
            //sendImFirstLevelNumberForStart();
            if (gmsGameVariantNumber != -1)
                startGame(true, gmsGameVariantNumber);
        } else if (resultCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            // player indicated that they want to leave the room
            leaveRoom();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Dialog was cancelled (user pressed back key, for instance). In our game,
            // this means leaving the room too. In more elaborate games, this could mean
            // something else (like minimizing the waiting room UI).
            leaveRoom();
        }
        break;
    }
}

From source file:it.feio.android.omninotes.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }/*from w w w.  jav  a2  s.  co m*/
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            AttachmentTask task = new AttachmentTask(this, uri, name, this);
            task.execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                AttachmentTask task = new AttachmentTask(this, uriSingle, name, this);
                task.execute();
            }
        }

        //         i.setAction(null);
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST)) {
        showKeyboard = true;
    }

}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }/*from   ww w  .  jav a 2s. co  m*/
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            new AttachmentTask(this, uri, name, this).execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                new AttachmentTask(this, uriSingle, name, this).execute();
            }
        }
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST,
            Constants.ACTION_SHORTCUT_WIDGET, Constants.ACTION_WIDGET)) {
        showKeyboard = true;
    }

    i.setAction(null);
}

From source file:com.if3games.chessonline.DroidFish.java

/**
 * Return PGN/FEN data or filename from the Intent. Both can not be non-null.
 * @return Pair of PGN/FEN data and filename.
 *///ww  w  . j a  va  2 s  .  c o  m
private final Pair<String, String> getPgnOrFenIntent() {
    String pgnOrFen = null;
    String filename = null;
    try {
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            Bundle b = intent.getExtras();
            if (b != null) {
                Object strm = b.get(Intent.EXTRA_STREAM);
                if (strm instanceof Uri) {
                    data = (Uri) strm;
                    if ("file".equals(data.getScheme())) {
                        filename = data.getEncodedPath();
                        if (filename != null)
                            filename = Uri.decode(filename);
                    }
                }
            }
        }
        if (data == null) {
            if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()))
                    && ("application/x-chess-pgn".equals(intent.getType())
                            || "application/x-chess-fen".equals(intent.getType())))
                pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else {
            String scheme = intent.getScheme();
            if ("file".equals(scheme)) {
                filename = data.getEncodedPath();
                if (filename != null)
                    filename = Uri.decode(filename);
            }
            if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) {
                ContentResolver resolver = getContentResolver();
                InputStream in = resolver.openInputStream(intent.getData());
                StringBuilder sb = new StringBuilder();
                while (true) {
                    byte[] buffer = new byte[16384];
                    int len = in.read(buffer);
                    if (len <= 0)
                        break;
                    sb.append(new String(buffer, 0, len));
                }
                pgnOrFen = sb.toString();
            }
        }
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show();
    }
    return new Pair<String, String>(pgnOrFen, filename);
}

From source file:at.flack.receiver.SmsReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    notify = sharedPrefs.getBoolean("notifications", true);
    vibrate = sharedPrefs.getBoolean("vibration", true);
    headsup = sharedPrefs.getBoolean("headsup", true);
    led_color = sharedPrefs.getInt("notification_light", -16776961);
    boolean all = sharedPrefs.getBoolean("all_sms", true);

    if (notify == false)
        return;/* w w w. j  a  v a  2  s  . c  o  m*/

    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;
    String str = "";
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            str += msgs[i].getMessageBody().toString();
            str += "\n";
        }

        NotificationCompat.Builder mBuilder;

        if (main != null) {
            main.addNewMessage(str);
            return;
        }

        boolean use_profile_picture = false;
        Bitmap profile_picture = null;

        String origin_name = null;
        try {
            origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress());
            if (origin_name == null)
                origin_name = msgs[0].getDisplayOriginatingAddress();
        } catch (Exception e) {
        }
        if (origin_name == null)
            origin_name = "Unknown";
        try {
            profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                    fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300);
            use_profile_picture = true;
        } catch (Exception e) {
            use_profile_picture = false;
        }

        Resources res = context.getResources();
        int positionOfBase64End = str.lastIndexOf("=");
        if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) {
            mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon)
                    .setContentTitle(origin_name).setColor(0xFFB71C1C)
                    .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).setAutoCancel(true);
            if (use_profile_picture && profile_picture != null) {
                mBuilder = mBuilder.setLargeIcon(profile_picture);
            } else {
                mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                        context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
            }

        } else if (str.toString().charAt(0) == '%'
                && (str.toString().length() == 10 || str.toString().length() == 9)) {
            int lastIndex = str.toString().lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C)
                        .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                        .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {
                return;
            }
        } else if (str.toString().charAt(0) == '%' && str.toString().length() >= 120
                && str.toString().length() < 125) { // DH Handshake
            int lastIndex = str.toString().lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C)
                        .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                        .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {
                return;
            }
        } else { // unencrypted messages
            if (all) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(str))
                        .setSmallIcon(R.drawable.raven_notification_icon);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {
                return;
            }
        }

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
        mBuilder.setLights(led_color, 750, 4000);
        if (vibrate) {
            mBuilder.setVibrate(new long[] { 0, 100, 200, 300 });
        }

        Intent resultIntent = new Intent(context, MainActivity.class);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress());

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        if (Build.VERSION.SDK_INT >= 16 && headsup)
            mBuilder.setPriority(Notification.PRIORITY_HIGH);
        if (Build.VERSION.SDK_INT >= 21)
            mBuilder.setCategory(Notification.CATEGORY_MESSAGE);

        final NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop)
            mNotificationManager.notify(7, mBuilder.build());

        // Save SMS if default app
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
                && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) {
            ContentValues values = new ContentValues();
            values.put("address", msgs[0].getDisplayOriginatingAddress());
            values.put("body", str.replace("\n", "").replace("\r", ""));

            if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
                context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values);

        }
    }

}