Example usage for android.content Intent putExtra

List of usage examples for android.content Intent putExtra

Introduction

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

Prototype

@Deprecated
@UnsupportedAppUsage
public @NonNull Intent putExtra(String name, IBinder value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:com.keylesspalace.tusky.util.NotificationMaker.java

public static void make(final Context context, final int notifyId, Notification body) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);

    if (!filterNotification(preferences, body)) {
        return;//from   ww w . j  av a2s  .co  m
    }

    String rawCurrentNotifications = notificationPreferences.getString("current", "[]");
    JSONArray currentNotifications;

    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }

    boolean alreadyContains = false;

    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.account.getDisplayName())) {
                alreadyContains = true;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (!alreadyContains) {
        currentNotifications.put(body.account.getDisplayName());
    }

    notificationPreferences.edit().putString("current", currentNotifications.toString()).commit();

    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.putExtra("tab_position", 1);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class);
    PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notify).setContentIntent(resultPendingIntent)
            .setDeleteIntent(deletePendingIntent).setDefaults(0); // So it doesn't ring twice, notify only in Target callback

    if (currentNotifications.length() == 1) {
        builder.setContentTitle(titleForType(context, body))
                .setContentText(truncateWithEllipses(bodyForType(body), 40));

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

                setupPreferences(preferences, builder);

                ((NotificationManager) (context.getSystemService(Context.NOTIFICATION_SERVICE)))
                        .notify(notifyId, builder.build());
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

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

        Picasso.with(context).load(body.account.avatar).placeholder(R.drawable.avatar_default)
                .transform(new RoundedTransformation(7, 0)).into(mTarget);
    } else {
        setupPreferences(preferences, builder);
        try {
            builder.setContentTitle(String.format(context.getString(R.string.notification_title_summary),
                    currentNotifications.length()))
                    .setContentText(truncateWithEllipses(joinNames(context, currentNotifications), 40));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE);
        builder.setCategory(android.app.Notification.CATEGORY_SOCIAL);
    }

    ((NotificationManager) (context.getSystemService(Context.NOTIFICATION_SERVICE))).notify(notifyId,
            builder.build());
}

From source file:eu.andlabs.studiolounge.gcp.GCPService.java

public static Lounge bind(Context ctx) {
    Log.d("GCP-Service", "binding GCP Service");
    String name = LoginManager.getInstance(ctx).getUserId().getPlayername();
    Lounge lounge = new Lounge(ctx);
    Intent intent = new Intent(ctx, GCPService.class);
    intent.putExtra("packageName", ctx.getPackageName());
    intent.putExtra("messenger", lounge.mMessenger);
    intent.putExtra("name", name);
    ctx.startService(intent);/*from   w  w w  .  ja v a  2 s .com*/
    ctx.bindService(intent, lounge, Context.BIND_AUTO_CREATE);
    return lounge;
}

From source file:io.openkit.OKAchievement.java

public static Intent getAchievementsIntent(Context ctx) {
    Intent achievementsIntent = new Intent(ctx, OKLeaderboardsActivity.class);
    achievementsIntent.putExtra(OK_ACHIEVEMENT_KEY, true);
    return achievementsIntent;
}

From source file:eu.inmite.apps.smsjizdenka.service.UpdateService.java

public static void call(Context context, boolean force) {
    final Intent i = new Intent(context, UpdateService.class);
    i.putExtra("force", force);
    context.startService(i);//from w w  w. j a  va 2  s  .  c om
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending plain text and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param messageText the body text for the message to be shared
 * @param messageTitle the title/subject for the message to be shared, if supported by the target app
 */// www  .  ja  v a2 s  .  com
public static void shareText(Context context, String windowTitle, String messageText, String messageTitle) {
    Intent intentInvite = new Intent(Intent.ACTION_SEND);
    intentInvite.setType(HTTP.PLAIN_TEXT_TYPE);
    intentInvite.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intentInvite.putExtra(Intent.EXTRA_TEXT, messageText);
    context.startActivity(Intent.createChooser(intentInvite, windowTitle));
}

From source file:eu.inmite.apps.smsjizdenka.service.UpdateService.java

public static void call(Context context, int serverVersion, String message) {
    final Intent i = new Intent(context, UpdateService.class);
    i.putExtra("serverVersion", serverVersion);
    i.putExtra("message", message);
    context.startService(i);//from  w ww  . j  a  v  a 2  s . c  om
}

From source file:gxu.software_engineering.market.android.util.ServiceHelper.java

public static void pre(Intent intent) {
    int target = intent.getIntExtra(C.TARGET_ENTITY, -1);
    long uid = Long.MIN_VALUE;
    long cid = Long.MIN_VALUE;
    switch (target) {
    case CATEGORIES:
        intent.putExtra(C.HTTP_URI, C.DOMAIN + "/categories");
        break;//w  w w  .jav  a 2  s .c  o  m
    case LASTEST_USERS:
        intent.putExtra(C.HTTP_URI, C.DOMAIN + "/users?type=1&count=50");
        break;
    case LASTEST_ITEMS:
        intent.putExtra(C.HTTP_URI, C.DOMAIN + "/items?type=1&count=50");
        break;
    case HOTTEST_ITEMS:
        intent.putExtra(C.HTTP_URI, C.DOMAIN + "/items?type=6&count=20");
        break;
    case USER_ITEMS:
        uid = intent.getLongExtra(C.UID, -1);
        intent.putExtra(C.HTTP_URI, C.DOMAIN
                + String.format("/items?type=4&count=%d&uid=%d&deal=0&last_id=0", C.DEFAULT_LIST_SIZE, uid));
        break;
    case CATEGORY_ITEMS:
        cid = intent.getLongExtra(C.CID, -1);
        intent.putExtra(C.HTTP_URI,
                C.DOMAIN + String.format("/items?type=5&count=%d&cid=%d&last_id=0", C.DEFAULT_LIST_SIZE, cid));
        break;
    case USER_CLOSED_ITEMS:
        uid = intent.getLongExtra(C.UID, -1);
        intent.putExtra(C.HTTP_URI,
                C.DOMAIN + String.format("/items?type=7&count=%d&uid=%d&last_id=0", C.DEFAULT_LIST_SIZE, uid));
        break;
    case USER_DEAL_ITEMS:
        uid = intent.getLongExtra(C.UID, uid);
        intent.putExtra(C.HTTP_URI,
                C.DOMAIN + String.format("/items?type=4&count=%d&uid=%d&deal=1", C.DEFAULT_LIST_SIZE, uid));
        break;
    default:
        throw new IllegalArgumentException("sorry, 404 for the target[" + target + "]");
    }
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void gotoUser(android.support.v4.app.Fragment fragment, JSONParcelable imageData) {
    try {/*  w  w  w .  j a va2 s  .  c o  m*/
        Intent intent = new Intent();
        intent.putExtra("username", imageData.getJSONObject().getString("account_url"));
        intent.setAction(ImgurHoloActivity.ACCOUNT_INTENT);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        fragment.startActivity(intent);
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
}

From source file:Main.java

/**
 * Share the crisis with your friend and/or the world.
 *///w ww. ja v  a  2  s. co m
public static Intent shareCrisis(String crisisID, String shortTitle) {
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    StringBuffer shareContent = new StringBuffer();
    shareContent.append(shortTitle);
    shareContent.append(" - ");
    shareContent.append("http://www.sigimera.org/crises/");
    shareContent.append(crisisID);

    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareContent.toString());
    return shareIntent;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java

private static HttpResp<Void> sendCommandWithMedia(final Context ctx, CommandObject cmd)
        throws KurentoCommandException, TransportException, InvalidDataException, NotFoundException {
    String contentPath = cmd.getMedia();

    File content = new File(contentPath);
    String mimeType;/*  ww w. j  a v  a2  s  .  c om*/
    if (content.exists() && content.isFile()) {
        if (contentPath.contains(ConstantKeys.EXTENSION_JPG)) {
            mimeType = ConstantKeys.TYPE_IMAGE;
        } else {
            mimeType = ConstantKeys.TYPE_VIDEO;
        }
    } else {
        String error = contentPath + " does not exists or is not a file";
        log.error(error);
        throw new KurentoCommandException(error);
    }

    CustomMultiPartEntity mpEntity;
    final String json = cmd.getJson();
    String charset = HTTP.UTF_8;
    long contentSize = 0;
    try {
        contentSize = content.length();
        /* Aprox. total size */
        final long totalSize = content.length() + json.getBytes("UTF-16BE").length;
        mpEntity = new CustomMultiPartEntity(new CustomMultiPartEntity.ProgressListener() {

            private int i;

            @Override
            public void transferred(long num) {
                int totalpercent = Math.min(100, (int) ((num * 100) / totalSize));

                if (totalpercent > (1 + PERCENT_INC * i) || totalpercent >= 100) {
                    Intent intent = new Intent();
                    intent.setAction(ConstantKeys.BROADCAST_PROGRESSBAR);
                    intent.putExtra(ConstantKeys.JSON, json);
                    intent.putExtra(ConstantKeys.TOTAL, totalpercent);
                    ctx.sendBroadcast(intent);
                    i++;
                }
            }
        });

        mpEntity.addPart(COMMAND_PART_NAME,
                new StringBody(json, HttpManager.CONTENT_TYPE_APPLICATION_JSON, Charset.forName(charset)));

        FormBodyPart fbp = new FormBodyPart(CONTENT_PART_NAME, new FileBody(content, mimeType));
        fbp.addField(HTTP.CONTENT_LEN, String.valueOf(contentSize));
        mpEntity.addPart(fbp);

    } catch (UnsupportedEncodingException e) {
        String msg = "Cannot use " + charset + "as entity";
        log.error(msg, e);
        throw new TransportException(msg);
    }

    return HttpManager.sendPostVoid(ctx, ctx.getString(R.string.url_command), mpEntity);
}