Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

In this page you can find the example usage for android.os Bundle get.

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:activity.DetailsActivity.java

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

    Bundle extras = getIntent().getExtras();
    if (extras != null) {

        Bundle args = new Bundle(extras);

        String label = extras.getString("label");

        if ("CLDOC".equals(label)) {
            Document mCurrentResource = new Select().from(Document.class).where("Id = ?", extras.get("resID"))
                    .executeSingle();//from  ww w .  ja va2 s .  co  m
            openFileInMemory(mCurrentResource);
            finish();
        } else {
            mFragment = (DetailFragment) Fragment.instantiate(this, getDetailFragmentName(label), args);
            getSupportFragmentManager().beginTransaction()
                    .add(android.R.id.content, mFragment, "resource_detail").commit();
        }
    } else {
        finish();
    }
}

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  ww  .  ja v a 2 s .  co 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);

        }
    }

}

From source file:bolts.AppLinkNavigation.java

/**
 * Gets a JSONObject equivalent to the input bundle for use when falling back to a web navigation.
 *//*  ww  w . j  ava 2s  .  co  m*/
private JSONObject getJSONForBundle(Bundle bundle) throws JSONException {
    JSONObject root = new JSONObject();
    for (String key : bundle.keySet()) {
        root.put(key, getJSONValue(bundle.get(key)));
    }
    return root;
}

From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;//ww  w  . j a  v  a 2s .c o  m

    String contact = "";
    String sender = "";
    String body = "";
    String account = "";

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean pushPreference = prefs.getBoolean("cbPush", true);

    if (pushPreference) {
        if (bundle != null && accountExist(context)) {
            Object[] pdus = (Object[]) bundle.get("pdus");

            msgs = new SmsMessage[pdus.length];
            msgs[0] = SmsMessage.createFromPdu((byte[]) pdus[0]);

            contact = msgs[0].getOriginatingAddress();
            body = msgs[0].getMessageBody().toString();
            account = getAccount(context);
            sender = getNameFromPhoneNumber(context, contact);

            Toast.makeText(context, R.string.toast_push, Toast.LENGTH_LONG).show();
            postData(account, contact, body, sender);
        }
    }
}

From source file:org.alfresco.mobile.android.application.mdm.mobileiron.MobileIronManagerImpl.java

@Override
public void setConfig(Bundle b) {
    configBundle = new Bundle(b);

    // Verification : Configuration presents ?
    for (int i = 0; i < MANDATORUY_CONFIGURATION_KEYS.length; i++) {
        if (!b.containsKey(MANDATORUY_CONFIGURATION_KEYS[i])) {
            throw new AlfrescoAppException(MANDATORUY_CONFIGURATION_KEYS[i] + " parameter is missing.");
        }//from ww  w .  jav  a  2  s .co  m
    }

    // Next configuration respect the format

    // REPOSITORY URL
    String repositoryURL = (String) b.get(ALFRESCO_REPOSITORY_URL);
    if (TextUtils.isEmpty(repositoryURL)) {
        throw new AlfrescoAppException(ALFRESCO_REPOSITORY_URL + " can't be empty.");
    }

    URL u = null;
    try {
        u = new URL(repositoryURL);
    } catch (MalformedURLException e) {
        throw new AlfrescoAppException(ALFRESCO_REPOSITORY_URL + " seems to be wrong.");
    }

    // USERNAME
    String username = (String) b.get(ALFRESCO_USERNAME);
    if (TextUtils.isEmpty(username)) {
        throw new AlfrescoAppException(ALFRESCO_USERNAME + " can't be empty.");
    }
}

From source file:pj.rozkladWKD.C2DMReceiver.java

@Override
public void onMessage(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (!Prefs.get(context).getBoolean(Prefs.PUSH_TURNED_ON, true)) {
        RozkladWKDApplication app = (RozkladWKDApplication) getApplication();
        SharedPreferences.Editor edit = Prefs.get(context).edit();
        edit.putBoolean(Prefs.PUSH_TURNED_ON, false);
        edit.commit();/*from w w w .j a  v a2  s.c  o  m*/
        app.registerPushes();
    } else {
        if (extras != null) {
            String type = (String) extras.get("type");
            String msg = (String) extras.get("msg");
            String username = (String) extras.get("usr");

            if (RozkladWKD.DEBUG_LOG) {
                Log.d("PUSH", type + ": " + msg);
            }

            String[] categories = Prefs.getStringArray(context, Prefs.PUSH_CATEGORIES,
                    Prefs.DEFAULT_PUSH_CATEGORIES);

            Prefs.getNotificationMessageNextNumber(context, type);
            if (!username.equals(Prefs.get(context).getString(Prefs.USERNAME, "")) && categories != null
                    && type != null) {
                for (String category : categories) {
                    if (type.equals(category)) {
                        Intent notificationIntent = new Intent(this, MessageActivity.class);
                        notificationIntent.putExtra("page", type.equals(MessagesPagerAdapter.MESSAGE_EVENTS) ? 0
                                : (type.equals(MessagesPagerAdapter.MESSAGE_WKD) ? 1 : 2));
                        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

                        showNotification(msg,
                                String.format(getString(R.string.new_message),
                                        getResources().getString(getResources().getIdentifier(type, "string",
                                                context.getPackageName()))),
                                msg, contentIntent, Prefs.getNotificationMessageNextNumber(context));
                        break;
                    }
                }
            }
            context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));

        }
    }
}

From source file:hack.ddakev.roadrant.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
        OutputStream outStream = null;
        try {/* w  ww.  j a  v a  2 s.  c  o m*/

            outStream = new FileOutputStream(new File(getBaseContext().getFilesDir().getPath() + "/temp.png"));
            imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
            File file = new File(getBaseContext().getFilesDir().getPath() + "/temp.png");
            System.out.println(file.toString());
            System.out.println("Getting license number...");
            new HTTPAsyncSend(file).execute(
                    "https://api.openalpr.com/v1/recognize?tasks=plate&country=us&secret_key=sk_cb754bf37e493856189ecd1f");
            System.out.println("Got license number (probably)");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.mifos.androidclient.templates.OperationFormActivity.java

@Override
protected void onRestoreInstanceState(Bundle bundle) {
    super.onRestoreInstanceState(bundle);
    if (bundle != null && bundle.containsKey(PREVIOUS_STATE_BUNDLE_KEY)) {
        mPreviousResult = (Map<String, String>) bundle.get(PREVIOUS_STATE_BUNDLE_KEY);
        updateViewForResponse(mPreviousResult);
    }//  ww w  . j  av a2s . co m
}

From source file:com.chatwing.whitelabel.services.NotificationIntentService.java

@Override
public void onMessageReceived(String from, Bundle extras) {
    if (mUserManager.getCurrentUser() == null)
        return;//No login no push
    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {/*from  w  ww.j  a  v  a 2s  .  c  o m*/
        Set<String> keys = extras.keySet();
        for (String k : keys) {
            LogUtils.v("Key in GCM " + k + ":" + extras.get(k));
        }

        if (!supportVersion(extras)) {
            return;
        }

        if (handleBroadCastEvent(extras)) {
            return;
        }
        String params = extras.getString("params");
        if (params == null)
            return;
        MessageResponse messageResponse = getMessagesFromParams(params);
        if (messageResponse == null)
            return;
        Message[] messages = messageResponse.getMessages();
        User targetUser = messageResponse.getChatUser();
        if (messages == null || messages.length == 0) {
            return;
        }

        if (!shouldShowNotification(messages[0])) {
            return;
        }

        //Fill chatbox_id or conversation_id to message
        fillGroupIDToMessage(messages, extras.getString("type"), messageResponse);

        insertNotificationMessagesToDb(messages);

        if (extras.getString("type").equals("conversation_notification")) {
            String conversationId = messageResponse.getConversation().getId();
            List<Message> freshConversations = getMessagesByGroup(conversationId);
            LogUtils.v("Test notification not receive getMessagesByGroup " + freshConversations.size());

            mCWNotificationManager.notifyForBox(freshConversations, messageResponse.getConversation().getId(),
                    targetUser, false); // We use GCM notification just as backup plan to update latest message so no need to make sound
        } else {
            ChatBox chatbox = messageResponse.getChatbox();

            List<Message> freshChatboxes = getMessagesByGroup(chatbox.getId());
            mCWNotificationManager.notifyForBox(freshChatboxes, chatbox.getName(), chatbox.getId(), false); // We use GCM notification just as backup plan to update latest message so no need to make sound
        }
    }
}

From source file:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    // setContentView(R.layout.fragment_camera);
    Log.i("EDebug::FaceRecog OnCreate: ", "In OnCreate");
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }/*from   www .  ja va2 s .  c  om*/

    setUpCamera();
    Intent intent = getIntent();
    // String message = intent.getStringExtra("Check1");
    extras = intent.getExtras();
    // message = "Check1::"+ (String) extras.get("Check1");
    Bundle b = (Bundle) extras.get("list");
    // ArrayList<String> al = (ArrayList<String>) b.get("al");
    ocrResponse = (ArrayList<String>) b.get("ocrresponse");
    licenseBytes = (byte[]) b.get("licensebytes");
    licenseImgPath = (String) b.get("licenseImgPath");

    try {
        // ocrResponse = new ArrayList<String>();
        // ocrResponse.add("V& LIMITED TERM");
        // ocrResponse.add("IDENTIFICATION CARD");
        // ocrResponse.add("Lid 37998217");
        // ocrResponse.add("La iss 12/20/2013 4b Exp 10/30/2016");
        // ocrResponse.add("13 DOB 10/29/1991");
        // ocrResponse.add("1ARRABOLU");
        // ocrResponse.add("2 VEERA VENKATA RAVI TEJA");
        // ocrResponse.add("8 7777 MCCALLUM BLVD #316");
        // ocrResponse.add( "RICHARDSON TX 75252");
        // ocrResponse.add("16 Hgt 5-11   15   Sex   M   16   E");
        // ocrResponse.add("5 DD 01114301126250715756");

        // Bitmap baseImg =
        // BitmapFactory.decodeFile(String.valueOf(Environment.getExternalStoragePublicDirectory((
        // Environment.DIRECTORY_PICTURES + "/IOT/dule00.jpg"))));
        // ByteArrayOutputStream bos = new ByteArrayOutputStream();
        // baseImg.compress(Bitmap.CompressFormat.JPEG, 100, bos);
        // licenseBytes = bos.toByteArray();
        // bos.flush();
        // bos.close();
        // Log.i("EDebug::compareImageBytes = ",""+licenseBytes.length);
        //
        // Bitmap compImg =
        // BitmapFactory.decodeFile(String.valueOf(Environment.getExternalStoragePublicDirectory((
        // Environment.DIRECTORY_PICTURES + "/IOT/dule02.jpg"))));
        // ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
        // compImg.compress(Bitmap.CompressFormat.JPEG, 100, bos2);
        // compareImageBytes = bos2.toByteArray();
        // bos2.flush();
        // bos2.close();
        // Log.i("EDebug::compareImageBytes = ",""+compareImageBytes.length);
    } catch (Exception ex) {
        Log.e("EDebug::OnCreate Error - ", "Error::" + ex.getLocalizedMessage() + "::" + ex.getMessage());
    }
    // Log.i("EDebug::FaceRecog OnCreate: ", message);
    Log.i("EDebug::FaceRecog OnCreate: licenseImgPath = ", "" + licenseImgPath);
    Log.i("EDebug::FaceRecog OnCreate: ocrResponse=", "" + ocrResponse.toString());
    Log.i("EDebug::FaceRecog OnCreate: licenseBytes = ", "" + licenseBytes.length);
}