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:Main.java

public static void showMessageDialogWithNewIntent(final Activity curentActivity, Context context,
        String message, final Class newActivity, final String extras) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {

                    Intent i = new Intent(curentActivity, newActivity);
                    if (extras != null) {
                        Log.i("LOGINSIGNUP", "=extras!=null in showMessageDialog");
                        i.putExtra("OAuthError", true);
                    }/*  w w  w .j  a v  a2  s . co m*/
                    Log.i("LOGINSIGNUP", "==after if in showMessageDialog");

                    curentActivity.startActivity(i);
                    //                  curentActivity.finish();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:Main.java

public static void forwardBySms(Context context, String body) {
    if (body != null) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setType("vnd.android-dir/mms-sms");
        // intent.putExtra("forwarded_message",true);
        // comment this may improve performance for forwarding sms
        intent.putExtra("sms_body", body);
        context.startActivity(intent);//from  w  w w .  j  a  v a  2 s  .c o m
    }
}

From source file:com.liferay.alerts.activity.CommentsActivity.java

public static void addComment(Context context, Alert alert) {
    Intent intent = new Intent(ACTION_ADD_COMMENT);
    intent.putExtra(EXTRA_ALERT, alert);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}

From source file:Main.java

public static void jumpPostToActivity(final Context context, final Class<? extends Activity> targetClass,
        final int second, final String... datas) {
    (new AsyncTask<String, Integer, Boolean>() {
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep((long) (second * 1000));
            } catch (Exception var3) {
                ;//from www.j  a  va 2 s.c  om
            }
            return null;
        }

        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Intent datatIntent = new Intent(context, targetClass);
            if (datas != null) {
                for (int i = 0; i < datas.length; ++i) {
                    datatIntent.putExtra("data" + i, datas[i]);
                }
            }

            context.startActivity(datatIntent);
        }
    }).execute(new String[] { "" });
}

From source file:com.app.common.util.IntentUtils.java

public static void startEmailActivity(Context context, String to, String subject, String body) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");

    if (!TextUtils.isEmpty(to)) {
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    }/*w  ww.j  a v a2  s . c om*/
    if (!TextUtils.isEmpty(subject)) {
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    }
    if (!TextUtils.isEmpty(body)) {
        intent.putExtra(Intent.EXTRA_TEXT, body);
    }

    final PackageManager pm = (PackageManager) context.getPackageManager();
    try {
        if (pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) {
            intent.setType("text/plain");
        }
    } catch (Exception e) {
        Log.w("Exception encountered while looking for email intent receiver.", e);
    }

    context.startActivity(intent);
}

From source file:Main.java

public static void showEmailDialog(final Context context, final String subject) {
    new AlertDialog.Builder(context).setTitle("Email Us").setMessage(
            "Please send email with As many details as possible. We will look into it as soon as possible. \n\nPlease DO NOT change subject and email address. Continue to Email?")
            .setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override/* w w w.j a  v a 2 s .  co  m*/
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/html");
                    //                        intent.putExtra(Intent.EXTRA_EMAIL, R.string.app_email);
                    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    intent.putExtra(Intent.EXTRA_TEXT, "");

                    context.startActivity(Intent.createChooser(intent, "Send Email"));
                }
            }).setIcon(android.R.drawable.ic_dialog_info).show();
}

From source file:Main.java

/**
 * Easily create email intent/*from  w  w  w. j  a  v  a 2 s .c  om*/
 * 
 * @param recipientsList
 * @param ccList
 * @param subject
 * @param htmlBody
 * @return email intent chooser
 */
public static Intent createEmailIntent(List<String> recipientsList, List<String> ccList, String subject,
        CharSequence htmlBody) {
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    // emailIntent.setData(Uri.parse("mailto:"));

    if (recipientsList != null) {
        for (String email : recipientsList) {
            emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        }
    }
    if (ccList != null) {
        for (String email : ccList) {
            emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        }
    }
    if (subject != null)
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (htmlBody != null)
        emailIntent.putExtra(Intent.EXTRA_TEXT, htmlBody);

    return emailIntent;
}

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*w  w w . ja  v  a  2 s .  c  om*/
public static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:com.liferay.alerts.activity.CommentsActivity.java

public static void updateCommentsList(Context context, ArrayList<Alert> alerts) {

    Intent intent = new Intent(ACTION_UPDATE_COMMENTS_LIST);
    intent.putExtra(EXTRA_ALERTS, alerts);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}

From source file:mohammad.adib.oy.OyUtils.java

public static void sendInvite(Context context) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT,
            "Oy! Wanna fraandship?\nSend me an Oy: " + ParseUser.getCurrentUser().getUsername().toUpperCase());
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);//w w w . j av a2  s. c o  m
}