Example usage for android.os Bundle toString

List of usage examples for android.os Bundle toString

Introduction

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

Prototype

@Override
    public synchronized String toString() 

Source Link

Usage

From source file:cz.vutbr.fit.stud.xslade12.lostphone.services.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    //  getMessageType() intent parametr mus bt intent pijat v GcmBroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(TAG, "Deleted messages on server: " + extras.toString());
        }/*ww w  .  ja  va  2  s  .c om*/
        // Regulerni zprava
        else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            try {
                // Vytvori ze zpravy pkaz
                Command cmd = Command.createFromBundle(extras);
                // Zpracuje prikaz
                Worker worker = new Worker(this);
                worker.proccess(cmd);

            } catch (Exception ex) {
                Log.i(TAG, "Error:  " + ex.getMessage());
            }
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    //        GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:edu.rosehulman.gcmtutorialandroid.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);
    Log.d("GCM", "Message type:" + messageType);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Toast.makeText(MainActivity.mMainActivity, "Error: " + extras.toString(), Toast.LENGTH_SHORT)
                    .show();//  w  ww.  j  ava  2  s  .co  m
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Toast.makeText(MainActivity.mMainActivity, "Deleted message: " + extras.toString(),
                    Toast.LENGTH_SHORT).show();
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // If it's a regular GCM message, do some work.
            try {
                JSONObject jsonObj = new JSONObject(extras.getString("data"));
                MainActivity.mMainActivity.receivedGcmJson(jsonObj);
                //               Log.d("GCM", "simple_string: " + jsonObj.getString("simple_string"));
                //               Log.d("GCM", "int_value: " + jsonObj.getInt("int_value"));
                //               Log.d("GCM", "float_value: " + jsonObj.getDouble("float_value"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.ta.truckmap.gpstracking.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

            for (int i = 0; i < 1; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }//  ww w  .ja v  a 2s .  c o m
            }

            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.

            realMsg = extras.getString("payload");

            /*if (Utility.getSharedPrefStringData(getApplicationContext(), "driverrtype").equalsIgnoreCase("1"))
            {*/
            displayMsg(realMsg);
            /*}*/

            Log.i(TAG, "Received: " + extras.toString());

        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.swisscom.safeconnect.utils.gcm.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    setResultCode(Activity.RESULT_OK);//  ww w  .  j a va 2 s.co  m
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Error receiving push notification: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Deleted messages on server: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Received: " + extras.toString());

            String key = extras.getString("key");
            String args_json = extras.getString("args");

            if (key != null) {
                int resId = context.getResources().getIdentifier(key, "string", context.getPackageName());

                if (resId != 0) {
                    Object[] args = convertJsonToStringArray(args_json);
                    String title = context.getString(R.string.push_title);
                    String msg = context.getString(resId, args);
                    //String title = extras.getString("title");
                    //String msg = extras.getString("message");
                    sendNotification(title, msg, context);
                }
            }
        }
    }
}

From source file:com.app.ntuc.notifs.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  www . j  a  va  2  s.co m*/
 */
private void sendNotification(String body, String title, Bundle bundle) {
    Intent intent = new Intent(this, MainActivity2_.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(bundle.toString());
    bigText.setBigContentTitle(body);
    bigText.setSummaryText(title);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    notificationBuilder.setContentTitle(body).setContentText(title);

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

    notificationManager.notify(6969, notificationBuilder.build());
}

From source file:com.smart.taxi.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        String msg = extras.toString();
        /*//w w w  .  j  ava2s.c o m
         * Filter messages based on message type. Since it is likely that GCM
         * will be extended in the future with new message types, just ignore
         * any message types you're not interested in, or that you don't
         * recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            /*for (int i=0; i<0; i++) {
            Log.i(TAG, "Working... " + (i+1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            }*/
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification(extras);
            try {

                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock wl = pm.newWakeLock(
                        PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
                wl.acquire();
                wl.release();

            } catch (Exception ex) {
                Log.e("Wake lock acquire error:", ex.toString());
            }
            // Log.i(TAG, "Received: " + extras.toString());

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MyPageFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (outState != null) {
        Log.d(TAG, outState.toString());
    }/* w ww .  j  a v a  2  s .co m*/

    if (mCRecyclerView != null && mCRecyclerView.getAdapter() != null) {
        ((MyPageExpandableListAdapter) mCRecyclerView.getAdapter()).onSaveInstanceState(outState);
        Parcelable layoutState = mCRecyclerView.getLayoutManager().onSaveInstanceState();
        if (outState != null) {
            outState.putParcelable("recycleLayout", layoutState);
        }
    }

}

From source file:com.linute.linute.API.MyGcmListenerService.java

private Intent buildIntent(Bundle data, String action) {
    Intent intent;//from w  w w . j a  v a2s. com

    //Log.i(TAG, "action : "  + action);
    Log.d(TAG, "sendNotification: " + data.toString());

    boolean isLoggedIn = getSharedPreferences(LinuteConstants.SHARED_PREF_NAME, MODE_PRIVATE)
            .getBoolean("isLoggedIn", false);

    if (!isLoggedIn) {
        intent = new Intent(this, PreLoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return intent;
    }

    if (action == null) {
        intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return intent;
    }

    int type = gettNotificationType(data.getString("action"));
    if (type == LinuteConstants.MISC) {
        intent = new Intent(this, LaunchActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return intent;
    }

    if (type == LinuteConstants.GLOBAL) {
        intent = new Intent(this, LaunchActivity.class);
        intent.putExtra(LaunchActivity.EXTRA_REPORT_NOTIF_OPENED, true);
        intent.putExtra(LaunchActivity.EXTRA_NOTIF_ID, data.getString("nid"));
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return intent;
    }

    intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("NOTIFICATION", type);
    if (type == LinuteConstants.MESSAGE) {
        intent.putExtra("NOTIFICATION", type);

        try {
            JSONObject image = new JSONObject(
                    data.getString("roomProfileImage", "{original:'', thumbnail:''}"));
            JSONArray users = new JSONArray(data.getString("roomUsers", "[]"));

            String myId = Utils.getMyId(getApplicationContext());

            ArrayList<User> usersList = new ArrayList<>(users.length());
            for (int u = 0; u < users.length(); u++) {
                JSONObject userJson = users.getJSONObject(u);
                if (!myId.equals(userJson.getString("id"))) {
                    usersList.add(new User(userJson.getString("id"), userJson.getString("firstName"), "", ""));
                }
            }

            Log.d("AAA", data.getString("room", ""));

            ChatRoom chatRoom = new ChatRoom(data.getString("room", ""),
                    Integer.parseInt(data.getString("roomType", "" + ChatRoom.ROOM_TYPE_GROUP)),
                    data.getString("roomNameOfGroup", null), image.getString("thumbnail"), usersList, "", true,
                    0, false, 0);

            intent.putExtra("chatRoom", chatRoom);

            /*intent.putExtra("ownerID", data.getString("ownerID"));
            intent.putExtra("ownerFirstName", data.getString("ownerFullName"));
            intent.putExtra("ownerLastName", data.getString("ownerLastName"));
            intent.putExtra("room", data.getString("room"));*/
        } catch (JSONException e) {
            e.printStackTrace();
        }

    } else if (type == LinuteConstants.FEED_DETAIL) {
        intent.putExtra("event", data.getString("event"));
    } else {
        intent.putExtra("user", data.getString("user"));
    }

    return intent;
}

From source file:com.pulp.campaigntracker.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    TLog.v(TAG, "extras : " + extras.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   w  w  w .  ja v  a 2s.  c  o m
         * Filter messages based on message type. Since it is likely that
         * GCM will be extended in the future with new message types, just
         * ignore any message types you're not interested in, or that you
         * don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.i(TAG, "Send error: " + extras.toString());

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(TAG, "Deleted messages on server: " + extras.toString());

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

            if (!mAppPref.getString(ConstantUtils.USER_EMAIL, "").isEmpty()
                    && !mAppPref.getString(ConstantUtils.LOGIN_ID, "").isEmpty()) {

                GCM mMessage = parseMessageObject(extras.getString(MESSAGE));
                // Post notification of received message.
                sendNotification(mMessage);
                Log.i(TAG, "Received: " + extras.getString(MESSAGE));
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.neighbor.ex.tong.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e("GcmIntentService", "Send error : " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.e("GcmIntentService", "Deleted messages on server : " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String msg = "";
            String SenderCarNo = "";
            String Userseq = "";

            Iterator<String> iterator = extras.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                String value = extras.get(key).toString();
                try {
                    if (key.equals("MESSAGE"))
                        msg = URLDecoder.decode(value, "utf-8");
                    if (key.equals("SENDER_CAR_NUM"))
                        SenderCarNo = URLDecoder.decode(value, "utf-8");
                    if (key.equals("SENDER_SEQ")) {
                        Userseq = String.valueOf(value);
                    }/*from  ww  w.  j  a va 2  s . c o m*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (!msg.equalsIgnoreCase("UPDATE_OK") && !msg.equalsIgnoreCase("")) {

                ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                List<ActivityManager.RunningTaskInfo> services = am.getRunningTasks(Integer.MAX_VALUE);

                boolean isRunning = false;

                if (services.get(0).topActivity.getPackageName().toString()
                        .equalsIgnoreCase(this.getPackageName().toString())) {
                    isRunning = true;
                }

                if (false == isRunning) {
                    Uri path = getSoundPath(msg);
                    NotiMessage(msg, path);
                } else {
                    mHandler.post(new DisplayToast(this, msg));
                }

                //                    Log.d("hts", "sendGCMIntent msg : " + msg + "\t Userseq : " + Userseq + "\t SenderCarNo : " + SenderCarNo);
                sendGCMIntent(GcmIntentService.this, msg, null, SenderCarNo, Userseq);
            }
        }
    }

    GCMBroadCastReceiver.completeWakefulIntent(intent);
}