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.openerp.addons.messages.MessageComposeActivty.java

/**
 * requesting for file browse for attachment in message
 * //  w ww  .  ja  v  a 2 s .c o  m
 * @param type
 */
private void requestForAttachmentIntent(ATTACHMENT_TYPE type) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(attachments_type.get(type));
    startActivityForResult(intent, PICKFILE_RESULT_CODE);
}

From source file:com.javielinux.utils.Utils.java

public static void sendLastCrash(Activity cnt) {
    try {/*from w ww  . jav  a2  s.  c o  m*/
        Intent gmail = new Intent(Intent.ACTION_VIEW);
        gmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
        gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) });
        gmail.setData(Uri.parse(cnt.getString(R.string.email_send_errors)));
        gmail.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash");
        gmail.setType("plain/text");
        gmail.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt));
        cnt.startActivity(gmail);
    } catch (ActivityNotFoundException e) {
        Intent msg = new Intent(Intent.ACTION_SEND);
        msg.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) });
        msg.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash");
        msg.setType("plain/text");
        msg.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt));
        cnt.startActivity(msg);
    }
}

From source file:com.code.android.vibevault.ShowDetailsScreen.java

/** Handle user's long-click selection.
*
*///  w  w  w. ja  v a 2  s .co m
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveSongObj selSong = (ArchiveSongObj) trackList.getAdapter().getItem(menuInfo.position);
        switch (item.getItemId()) {
        case (VibeVault.STREAM_CONTEXT_ID):
            // Start streaming.
            int track = pService.enqueue(selSong);
            pService.playSongFromPlaylist(track);
            break;
        case (VibeVault.DOWNLOAD_SONG):
            selSong.setDownloadShow(show);
            dService.addSong(selSong);
            break;
        case (VibeVault.ADD_SONG_TO_QUEUE):
            pService.enqueue(selSong);
            break;
        case (VibeVault.EMAIL_LINK):
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Great song on archive.org: " + selSong.toString());
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "Hey,\n\nI found a song you should listen to.  It's called " + selSong.toString()
                            + " and it's off of " + selSong.getShowTitle() + ".  You can get it here: "
                            + selSong.getLowBitRate() + "\n\nSent using VibeVault for Android.");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            break;
        default:
            return false;
        }
        return true;
    }
    return false;
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

final void addContact(String[] names, String[] nicknames, String pronunciation, String[] phoneNumbers,
        String[] phoneTypes, String[] emails, String[] emailTypes, String note, String instantMessenger,
        String address, String addressType, String org, String title, String[] urls, String birthday,
        String[] geo) {//from  w  w  w.j  a v a2  s  .c  o m

    // Only use the first name in the array, if present.
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, ContactsContract.Contacts.CONTENT_URI);
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    putExtra(intent, ContactsContract.Intents.Insert.NAME, names != null ? names[0] : null);

    putExtra(intent, ContactsContract.Intents.Insert.PHONETIC_NAME, pronunciation);

    int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length);
    for (int x = 0; x < phoneCount; x++) {
        putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]);
        if (phoneTypes != null && x < phoneTypes.length) {
            int type = toPhoneContractType(phoneTypes[x]);
            if (type >= 0) {
                intent.putExtra(Contents.PHONE_TYPE_KEYS[x], type);
            }
        }
    }

    int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length);
    for (int x = 0; x < emailCount; x++) {
        putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]);
        if (emailTypes != null && x < emailTypes.length) {
            int type = toEmailContractType(emailTypes[x]);
            if (type >= 0) {
                intent.putExtra(Contents.EMAIL_TYPE_KEYS[x], type);
            }
        }
    }

    // No field for URL, birthday; use notes
    StringBuilder aggregatedNotes = new StringBuilder();
    if (urls != null) {
        for (String url : urls) {
            if (url != null && url.length() > 0) {
                aggregatedNotes.append('\n').append(url);
            }
        }
    }
    for (String aNote : new String[] { birthday, note }) {
        if (aNote != null) {
            aggregatedNotes.append('\n').append(aNote);
        }
    }
    if (nicknames != null) {
        for (String nickname : nicknames) {
            if (nickname != null && nickname.length() > 0) {
                aggregatedNotes.append('\n').append(nickname);
            }
        }
    }
    if (geo != null) {
        aggregatedNotes.append('\n').append(geo[0]).append(',').append(geo[1]);
    }

    if (aggregatedNotes.length() > 0) {
        // Remove extra leading '\n'
        putExtra(intent, ContactsContract.Intents.Insert.NOTES, aggregatedNotes.substring(1));
    }

    putExtra(intent, ContactsContract.Intents.Insert.IM_HANDLE, instantMessenger);
    putExtra(intent, ContactsContract.Intents.Insert.POSTAL, address);
    if (addressType != null) {
        int type = toAddressContractType(addressType);
        if (type >= 0) {
            intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, type);
        }
    }
    putExtra(intent, ContactsContract.Intents.Insert.COMPANY, org);
    putExtra(intent, ContactsContract.Intents.Insert.JOB_TITLE, title);
    launchIntent(intent);
}

From source file:com.code.android.vibevault.ShowDetailsScreen.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.nowPlaying: //Open playlist activity
        Intent i = new Intent(ShowDetailsScreen.this, NowPlayingScreen.class);

        startActivity(i);/*from  ww w.  j av a2s .c  om*/
        break;
    case R.id.recentShows:
        Intent rs = new Intent(ShowDetailsScreen.this, RecentShowsScreen.class);

        startActivity(rs);
        break;
    case R.id.scrollableDialog:
        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        ad.setTitle("Help!");
        View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null);
        ((TextView) v.findViewById(R.id.DialogText)).setText(R.string.show_details_screen_help);
        ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int arg1) {
            }
        });
        ad.setView(v);
        ad.show();
        break;
    case R.id.emailLink:
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "Great show on archive.org: " + show.getArtistAndTitle());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                "Hey,\n\nYou should listen to " + show.getArtistAndTitle() + ".  You can find it here: "
                        + show.getShowURL() + "\n\nSent using VibeVault for Android.");
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        break;
    case R.id.downloadShow:
        for (int j = 0; j < downloadLinks.size(); j++) {
            downloadLinks.get(j).setDownloadShow(show);
            dService.addSong(downloadLinks.get(j));
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:com.fsa.en.dron.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    RateThisApp.Config config = new RateThisApp.Config(5, 10);
    config.setTitle(R.string.my_own_title);
    config.setMessage(R.string.my_own_message);
    config.setYesButtonText(R.string.my_own_rate);
    config.setNoButtonText(R.string.my_own_thanks);
    config.setCancelButtonText(R.string.my_own_cancel);
    RateThisApp.init(config);//from  w  ww.j  ava 2s .  c om
    RateThisApp.setCallback(new RateThisApp.Callback() {
        @Override
        public void onYesClicked() {
            final String appPackageName = getPackageName(); // getPackageName() from Context or Activity  object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }

        @Override
        public void onNoClicked() {
            TastyToast.makeText(getApplicationContext(), "Vuelve pronto!", TastyToast.LENGTH_LONG,
                    TastyToast.INFO);
        }

        @Override
        public void onCancelClicked() {
            TastyToast.makeText(getApplicationContext(), "Prometo tomar mejores fotografias!",
                    TastyToast.LENGTH_LONG, TastyToast.ERROR);
        }
    });
    button = (Button) findViewById(R.id.button);
    button.setVisibility(View.INVISIBLE);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkConnection();
        }
    });
    BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
    bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
    bottomNavigationBar.setBarBackgroundColor(R.color.material_light_blue_800);
    bottomNavigationBar.setActiveColor(R.color.material_grey_900);
    bottomNavigationBar.setInActiveColor(R.color.material_blue_grey_200);
    bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.compose, "Mensaje"))
            .addItem(new BottomNavigationItem(R.drawable.sociales, "Sociales"))
            .addItem(new BottomNavigationItem(R.drawable.share, "Cuntale a un amigo")).initialise();
    bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
        @Override
        public void onTabSelected(int position) {
            switch (position) {
            case 0:
                Intent email = new Intent(Intent.ACTION_SEND);
                email.putExtra(Intent.EXTRA_EMAIL, new String[] { "marceloespinoza00@gmail.com" });
                email.putExtra(Intent.EXTRA_SUBJECT, "Formosa en dron");
                email.putExtra(Intent.EXTRA_TEXT, "Dej tu mensaje");
                email.setType("message/rfc822");
                startActivity(Intent.createChooser(email, "Elige un cliente :"));
                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Formosa en dron");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        "https://play.google.com/store/apps/details?id=com.fsa.en.dron");
                startActivity(Intent.createChooser(sharingIntent, "Compartir via"));
                break;

            }

        }

        @Override
        public void onTabUnselected(int position) {

        }

        @Override
        public void onTabReselected(int position) {
            switch (position) {
            case 0:

                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                break;

            }
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    LayoutInflater inflator = LayoutInflater.from(this);
    View v = inflator.inflate(R.layout.toolbar_title, null);
    Typeface budget = Typeface.createFromAsset(getAssets(), "fonts/Budget.otf");
    Typeface typographica = Typeface.createFromAsset(getAssets(), "fonts/TypoGraphica.otf");
    TextView mToolbarCustomTitle = (TextView) v.findViewById(R.id.title);
    TextView mToolbarCustomSubTitle = (TextView) v.findViewById(R.id.subtitle);
    mToolbarCustomTitle.setText("Formosa");
    mToolbarCustomSubTitle.setText("en dron");
    mToolbarCustomTitle.setTypeface(typographica);
    mToolbarCustomSubTitle.setTypeface(budget);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.recargar) {
                checkConnection();
            }
            if (id == R.id.info) {
                showDialog();
            }
            return false;
        }
    });
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(),
            recyclerView, new GalleryAdapter.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("images", images);
                    bundle.putInt("position", position);

                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
                    newFragment.setArguments(bundle);
                    newFragment.show(ft, "slideshow");
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));
    pDialog = new ProgressDialog(this);
    images = new ArrayList<>();
    mAdapter = new GalleryAdapter(getApplicationContext(), images);
    RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

}

From source file:com.wikitude.virtualhome.AugmentedActivity.java

public void shareSnapShot() {

    Log.e(this.getClass().getName(), " VIRTUALHOME: calling captureSnapShot method");

    architectView.captureScreen(ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW,
            new ArchitectView.CaptureScreenCallback() {

                @Override/*from  w w w .j ava 2 s .  c  o  m*/
                public void onScreenCaptured(final Bitmap screenCapture) {

                    // store screenCapture into external cache directory
                    final File screenCaptureFile = new File(
                            Environment.getExternalStorageDirectory().toString(),
                            "screenCapture_" + System.currentTimeMillis() + ".jpg");

                    // 1. Save bitmap to file & compress to jpeg. You may use PNG too
                    try {
                        final FileOutputStream out = new FileOutputStream(screenCaptureFile);
                        screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out);
                        out.flush();
                        out.close();

                        // 2. create send intent
                        final Intent share = new Intent(Intent.ACTION_SEND);
                        share.setType("image/jpg");
                        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile));

                        // 3. launch intent-chooser
                        final String chooserTitle = "Share Snapshot";
                        startActivity(Intent.createChooser(share, chooserTitle));

                    } catch (final Exception e) {
                        // should not occur when all permissions are set
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Log.e(this.getClass().getName(), " VIRTUALHOME: Share Snapshot failed ");
                                // show toast message in case something went wrong
                                //Toast.makeText(this, " Unexpected error", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
            });
}

From source file:com.dwdesign.tweetings.fragment.ConversationFragment.java

public void linkGenerationComplete(String url) {
    if (isShare == false) {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
        bundle.putString(INTENT_KEY_TEXT, url);
        intent.putExtras(bundle);//w  w  w  .  j a  v  a  2s  .c o  m
        startActivity(intent);
    } else {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, url);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
    }
}

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

/**
 * ??Email/*from   w  ww  .  java 2  s . co m*/
 * @param addr        ?
 * @param body        ?
 * @param subject     ?
 * @return     ?
 */
private XExtensionResult 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);
    getContext().startActivity(emailIntent);
    return new XExtensionResult(XExtensionResult.Status.OK, "");
}