Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

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

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java

/**
 * Opens a contact detial pare depending on contact type.
 *
 * @param position contact position//from ww  w.  j  a  v  a  2  s  .c o m
 */
private void listViewItemClick(int position) {
    try {//ErrorLogging

        int type = neededContacts.get(position).getType();
        switch (type) {
        case 0: {
        }
            break;
        case 1: {
            final String phoneNumber = neededContacts.get(position).getDescription();

            new CallDialog(this, phoneNumber, new CallDialog.ActionListener() {
                @Override
                public void onCall(DialogInterface dialog) {
                    dialog.dismiss();
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + phoneNumber));
                    startActivity(callIntent);
                    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
                }

                @Override
                public void onAddContact(DialogInterface dialog) {
                    createNewContact(person.getName(), person.getPhone(), person.getEmail());
                    dialog.dismiss();
                }

                @Override
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                }
            }).show();
        }
            break;
        case 2: {
            String email = neededContacts.get(position).getDescription();
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/html");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { email });
            startActivity(emailIntent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        case 3: {
            String url = neededContacts.get(position).getDescription();

            if (!url.startsWith("http://") && !url.startsWith("https://")) {
                url = "http://" + url;
            }

            Intent intent = new Intent(this, ContactsWebActivity.class);
            intent.putExtra("link", url);
            startActivity(intent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        case 4: {
            Intent intent = new Intent(this, NativeMapActivity.class);
            intent.putExtra("person", person);
            startActivity(intent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        }

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

@Rpc(description = "Launches an activity that sends an e-mail message to a given recipient.")
public void sendEmail(
        @RpcParameter(name = "to", description = "A comma separated list of recipients.") final String to,
        @RpcParameter(name = "subject") final String subject, @RpcParameter(name = "body") final String body,
        @RpcParameter(name = "attachmentUri") @RpcOptional final String attachmentUri) {
    final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("plain/text");
    intent.putExtra(android.content.Intent.EXTRA_EMAIL, to.split(","));
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    if (attachmentUri != null) {
        intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(attachmentUri));
    }/* ww w .j a  v  a  2 s.c  o  m*/
    startActivity(intent);
}

From source file:com.anjalimacwan.fragment.NoteViewFragment.java

public void dispatchKeyShortcutEvent(int keyCode) {
    switch (keyCode) {

    // CTRL+E: Edit
    case KeyEvent.KEYCODE_E:
        Bundle bundle = new Bundle();
        bundle.putString("filename", filename);

        Fragment fragment = new NoteEditFragment();
        fragment.setArguments(bundle);//from  ww  w .  j a  v  a2  s . c o  m

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                .commit();
        break;

    // CTRL+D: Delete
    case KeyEvent.KEYCODE_D:
        // Show delete dialog
        listener.showDeleteDialog();
        break;

    // CTRL+H: Share
    case KeyEvent.KEYCODE_H:
        // Send a share intent
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad);
        shareIntent.setType("text/plain");

        // Verify that the intent will resolve to an activity, and send
        if (shareIntent.resolveActivity(getActivity().getPackageManager()) != null)
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

        break;
    }
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

public void getImage() {
    Intent intent = new Intent();
    String title = GET_PICTURE;//  ww  w  .  j a v  a2 s  . c  o m
    if (mMediaType == PICTURE) {
        intent.setType("image/*");
    } else if (mMediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (mMediaType == ALLMEDIA) {
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // ??
    mExtensionContext.getSystemContext().startActivityForResult(this,
            Intent.createChooser(intent, new String(title)), PHOTO_REQUEST_CODE);
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

private void Sendmail() {
    TextView title = (TextView) findViewById(R.id.title);
    String emailSubject = title.getText().toString();

    // track the Send mail action
    if (getAnalyticsPref()) {
        EasyTracker.getTracker().sendEvent(SHARING_ACTION, "Send Mail", emailSubject, 0l);
    }/*from   w  w  w .j  a  v  a 2  s.  com*/
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/html");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "NewSum app : " + emailSubject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(sText));
    startActivity(Intent.createChooser(emailIntent, "Email:"));

}

From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Override default Android "up" behavior to instead mimic the back button
        getActivity().onBackPressed();//from  ww  w . ja  v  a2  s . c  o  m
        return true;

    // Edit button
    case R.id.action_edit:
        Bundle bundle = new Bundle();
        bundle.putString("filename", filename);

        Fragment fragment = new NoteEditFragment();
        fragment.setArguments(bundle);

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                .commit();

        return true;

    // Delete button
    case R.id.action_delete:
        listener.showDeleteDialog();
        return true;

    // Share menu item
    case R.id.action_share:
        // Send a share intent
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad);
        intent.setType("text/plain");

        // Verify that the intent will resolve to an activity, and send
        if (intent.resolveActivity(getActivity().getPackageManager()) != null)
            startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));

        return true;

    // Export menu item
    case R.id.action_export:
        listener.exportNote(filename);
        return true;

    // Print menu item
    case R.id.action_print:
        listener.printNote(contentsOnLoad);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

/**
 * ??Email//from  w ww.j ava 2s  .  c o  m
 *
 * @param addr
 *            ?
 * @param body
 *            ?
 * @param subject
 *            ?
 * @return ?
 */
private void sendEmail(String addr, String body, String subject) {
    String aEmailList[] = { addr };
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    mContext.startActivity(emailIntent);
    mCallbackContext.success();
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        getActivity().finish();/*w w  w  .j  a va  2  s . c o m*/
        return true;
    }

    case R.id.AddLog: {
        try {
            addMessageDialog = new Dialog(getActivity());
            addMessageDialog.setContentView(R.layout.add_message);
            addMessageDialog.setTitle("Add Message to Event Log");
            ((Button) addMessageDialog.findViewById(R.id.SaveButton))
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AddLogMessage(((EditText) addMessageDialog.findViewById(R.id.LogMessage)).getText()
                                    .toString());
                            addMessageDialog.dismiss();
                        }
                    });

            addMessageDialog.show();
            return true;
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragmentUpdate", "AddLog", e);
            return false;
        }
    }

    case R.id.escalate: {
        try {
            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

            // Add data to the intent, the receiving app will decide what to do with it.
            intent.putExtra(Intent.EXTRA_SUBJECT, "Escalation of Zenoss Event on " + Title.getText());
            String EventDetails = Summary.getText() + "\r\r\n" + LastTime.getText() + "\r\r\n" + "Count: "
                    + EventCount.getText();

            intent.putExtra(Intent.EXTRA_TEXT, EventDetails);

            startActivity(Intent.createChooser(intent, "How would you like to escalate this event?"));
            return true;
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragmentUpdate", "escalate", e);
            return false;
        }
    }

    default: {
        return false;
    }
    }
}

From source file:mp.paschalis.EditBookActivity.java

/**
 * Creates a sharing {@link Intent}.//from  w  ww  .ja va2 s  .  c  om
 *
 * @return The sharing intent.
 */
private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    String root = Environment.getExternalStorageDirectory() + ".SmartLib/Images";
    new File(root).mkdirs();

    File file = new File(root, app.selectedBook.isbn);

    try {
        FileOutputStream os = new FileOutputStream(file);
        bitmapBookCover.compress(CompressFormat.PNG, 80, os);
        os.flush();
        os.close();

        Uri uri = Uri.fromFile(file);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    } catch (Exception e) {
        Log.e(TAG, e.getStackTrace().toString());
    }

    String bookInfo = "\n\n\n\nMy " + getString(R.string.bookInfo) + ":\n" + getString(R.string.title)
            + ": \t\t\t\t" + app.selectedBook.title + "\n" + getString(R.string.author) + ": \t\t\t"
            + app.selectedBook.authors + "\n" + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn
            + "\n" + getString(R.string.published_) + " \t" + app.selectedBook.publishedYear + "\n"
            + getString(R.string.pages_) + " \t\t\t" + app.selectedBook.pageCount + "\n"
            + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn + "\n"
            + getString(R.string.status) + ": \t\t\t"
            + App.getBookStatusString(app.selectedBook.status, EditBookActivity.this) + "\n\n"
            + "http://books.google.com/books?vid=isbn" + app.selectedBook.isbn;

    shareIntent.putExtra(Intent.EXTRA_TEXT, bookInfo);

    return shareIntent;
}