Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

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

Prototype

String ACTION_SEND

To view the source code for android.content Intent ACTION_SEND.

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:com.bellman.bible.android.control.page.PageControl.java

/** send the current verse via social applications installed on user's device
 *//*w w w  .  j av  a2 s  . c o m*/
public void shareVerse(VerseRange verseRange) {
    try {
        Book book = getCurrentPageManager().getCurrentPage().getCurrentDocument();

        String text = verseRange.getName() + "\n"
                + SwordContentFacade.getInstance().getCanonicalText(book, verseRange);

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");

        sendIntent.putExtra(Intent.EXTRA_TEXT, text);
        // subject is used when user chooses to send verse via e-mail
        sendIntent.putExtra(Intent.EXTRA_SUBJECT,
                CurrentActivityHolder.getInstance().getApplication().getText(R.string.share_verse_subject));

        Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity();
        activity.startActivity(Intent.createChooser(sendIntent, activity.getString(R.string.share_verse)));

    } catch (Exception e) {
        Log.e(TAG, "Error sharing verse", e);
        Dialogs.getInstance().showErrorMsg("Error sharing verse");
    }
}

From source file:net.gromgull.android.bibsonomyposter.BibsonomyPosterActivity.java

/** Called with the activity is first created. */
@Override/*  w w  w.  ja  v a2s.  co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    load();

    Intent intent = getIntent();
    String action = intent.getAction();
    if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
        final String uri = intent.getStringExtra(Intent.EXTRA_TEXT);
        final String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);

        final Context context = getApplicationContext();

        new AsyncTask<Void, Integer, Boolean>() {

            @Override
            protected Boolean doInBackground(Void... v) {
                try {
                    bookmark(uri, title);
                    return true;
                } catch (Exception e) {
                    Log.w(LOGTAG, "Could not bookmark: " + title + " / " + uri, e);
                    return false;
                }
            }

            protected void onPostExecute(Boolean result) {
                if (result) {
                    Toast toast = Toast.makeText(context, "Bookmarked " + title, Toast.LENGTH_SHORT);
                    toast.show();
                } else {
                    Toast toast = Toast.makeText(context, "Error bookmarking " + title, Toast.LENGTH_SHORT);
                    toast.show();
                }
            }

        }.execute();

        finish();
        return;
    }

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.bibsonomyposter_activity);

    if (username != null)
        ((EditText) findViewById(R.id.username)).setText(username);
    if (apikey != null)
        ((EditText) findViewById(R.id.apikey)).setText(apikey);

    // Hook up button presses to the appropriate event handler.
    ((Button) findViewById(R.id.save)).setOnClickListener(mSaveListener);

}

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

/**
 * Displays an application chooser and shares the specified file using the selected application
 *
 * @param context a context reference//from   w  w w  .j a  v  a  2  s  .c o  m
 * @param windowTitle the title for the application chooser's window
 * @param fileToShare the file to be shared
 * @param mimeTypeForFile the MIME type for the file to be shared (e.g. `image/jpeg`)
 * @param subjectTextToShare the message title or subject for the file, if supported by the target application
 */
public static void shareFile(final Context context, final String windowTitle, final File fileToShare,
        final String mimeTypeForFile, final String subjectTextToShare) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeTypeForFile);
    intent.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

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 .ja  v  a 2s  . c  om*/
}

From source file:jahirfiquitiva.iconshowcase.services.MuzeiArtSourceService.java

@Override
public void onCustomCommand(int id) {
    super.onCustomCommand(id);
    if (id == COMMAND_ID_SHARE) {
        Artwork currentArtwork = getCurrentArtwork();
        Intent shareWall = new Intent(Intent.ACTION_SEND);
        shareWall.setType("text/plain");
        String wallName = currentArtwork.getTitle();
        String authorName = currentArtwork.getByline();
        String storeUrl = MARKET_URL + getPackageName();
        String iconPackName = getString(R.string.app_name);
        shareWall.putExtra(Intent.EXTRA_TEXT,
                getString(R.string.share_text, wallName, authorName, iconPackName, storeUrl));
        shareWall = Intent.createChooser(shareWall, getString(R.string.share_title));
        shareWall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareWall);//from ww  w  .java2 s. c o m
    }
}

From source file:com.anjalimacwan.activity.NoteEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note_edit);

    // Apply theme
    SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
    String theme = pref.getString("theme", "light-sans");

    LinearLayout noteViewEdit = (LinearLayout) findViewById(R.id.noteViewEdit);

    if (theme.contains("light"))
        noteViewEdit.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background));

    if (theme.contains("dark"))
        noteViewEdit.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));

    // Set action bar elevation
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getSupportActionBar().setElevation(getResources().getDimensionPixelSize(R.dimen.action_bar_elevation));

    if (!(getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment)) {
        // Handle intents
        Intent intent = getIntent();/*w ww  . ja va  2 s  .  c  o m*/
        String action = intent.getAction();
        String type = intent.getType();

        // Intent sent through an external application
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                external = intent.getStringExtra(Intent.EXTRA_TEXT);
                if (external != null) {
                    newNote();
                } else {
                    showToast(R.string.loading_external_file);
                    finish();
                }
            } else {
                showToast(R.string.loading_external_file);
                finish();
            }

            // Intent sent through Google Now "note to self"
        } else if ("com.google.android.gm.action.AUTO_SEND".equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                external = intent.getStringExtra(Intent.EXTRA_TEXT);
                if (external != null) {
                    try {
                        // Write note to disk
                        FileOutputStream output = openFileOutput(String.valueOf(System.currentTimeMillis()),
                                Context.MODE_PRIVATE);
                        output.write(external.getBytes());
                        output.close();

                        // Show toast notification and finish
                        showToast(R.string.note_saved);
                        finish();
                    } catch (IOException e) {
                        // Show error message as toast if file fails to save
                        showToast(R.string.failed_to_save);
                        finish();
                    }
                }
            }
        } else
            newNote();
    }
}

From source file:com.camera.simplewebcam.push.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();//w  w  w.j  a  va  2 s.c om
    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
        /*
         * 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.e(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.e(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)) {
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            Log.i(TAG, "Received: " + extras.getString("text"));

            Intent sendIntent = new Intent(getApplicationContext(), Main.class);
            sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, extras.getString("text"));
            startActivity(sendIntent);
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.bakhtiyor.android.tumblr.TumblrService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Bundle extras = intent.getExtras();/*from  w w  w. j av  a 2s .  c  o m*/
    if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)) {
        if (extras.containsKey(KEY_EMAIL) && extras.containsKey(KEY_PASSWORD) && extras.containsKey(KEY_CAPTION)
                && extras.containsKey(KEY_IS_PRIVATE) && extras.containsKey(KEY_FILENAME)) {
            String email = extras.getString(KEY_EMAIL);
            String password = extras.getString(KEY_PASSWORD);
            String caption = extras.getString(KEY_CAPTION);
            boolean isPrivate = extras.getBoolean(KEY_IS_PRIVATE);
            String filename = extras.getString(KEY_FILENAME);
            uploadPhoto(email, password, caption, isPrivate, filename);
        }
    }
    stopSelf(startId);
}

From source file:com.pureexe.calinoius.environment.camera.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    dataManager = new DataManager(getActivity());

    try {//  w  w w .java  2  s  .  c  om
        // Use Try catch Exception to avoid force close with CM's Privacy Guard
        Cursor c = getActivity().getApplication().getContentResolver()
                .query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
        c.moveToFirst();
        dataManager.setString("Researcher", c.getString(c.getColumnIndex("display_name")));
    } catch (Exception e) {
        dataManager.setString("Researcher", "Unknown");
    }
    GridView gridview = (GridView) rootView.findViewById(R.id.gridView1);
    gridview.setAdapter(new HomePageAdapter(getActivity()));
    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            if (position == 0) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "UserFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 1) {
                Intent intent = new Intent(getActivity(), EnvironmentCameraActivity.class);
                startActivity(intent);
            }
            if (position == 2) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "EXIFreadFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 3) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "SettingPreferenceFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 4) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "HelpFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 5) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "AboutFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
        }
    });

    return rootView;
}