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:pffy.mobile.flax.FlaxActivity.java

private boolean sendDetailsByIntent() {

    if (this.mExportFacts.equals("") || this.mExportFacts == null) {
        // do not send empty files
        return false;
    }/*from w w w. j av  a  2 s. co  m*/

    // boilerplate intent code
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, this.mExportFacts);
    sendIntent.setType(HTTP.PLAIN_TEXT_TYPE);
    startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.msg_shareto)));

    return true;
}

From source file:com.digipom.manteresting.android.fragment.NailFragment.java

private boolean handleMenuItemSelected(int listItemPosition, int itemId) {
    listItemPosition -= listView.getHeaderViewsCount();

    if (listItemPosition >= 0 && listItemPosition < nailAdapter.getCount()) {
        switch (itemId) {
        case R.id.share:
            try {
                final Cursor cursor = (Cursor) nailAdapter.getItem(listItemPosition);

                if (cursor != null && !cursor.isClosed()) {
                    final int nailId = cursor.getInt(cursor.getColumnIndex(Nails.NAIL_ID));
                    final JSONObject nailJson = new JSONObject(
                            cursor.getString(cursor.getColumnIndex(Nails.NAIL_JSON)));

                    final Uri uri = MANTERESTING_SERVER.buildUpon().appendPath("nail")
                            .appendPath(String.valueOf(nailId)).build();
                    String description = nailJson.getString("description");

                    if (description.length() > 100) {
                        description = description.substring(0, 97) + '';
                    }/*from  w w w . ja  va  2  s  . c o  m*/

                    final String user = nailJson.getJSONObject("user").getString("username");
                    final String category = nailJson.getJSONObject("workbench").getJSONObject("category")
                            .getString("title");

                    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, description + ' ' + uri.toString());
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
                            String.format(getResources().getString(R.string.shareSubject), user, category));
                    try {
                        startActivity(Intent.createChooser(shareIntent, getText(R.string.share)));
                    } catch (ActivityNotFoundException e) {
                        new AlertDialog.Builder(getActivity()).setMessage(R.string.noShareApp).show();
                    }
                }
            } catch (Exception e) {
                if (LoggerConfig.canLog(Log.WARN)) {
                    Log.w(TAG, "Could not share nail at position " + listItemPosition + " with id " + itemId);
                }
            }

            return true;
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.intel.xdk.contacts.Contacts.java

public void editContact(String contactId) {
    if (busy == true) {
        String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.busy',true,true);e.success=false;e.message='busy';document.dispatchEvent(e);";
        injectJS(js);/*  w  w  w.  j a  v  a  2s .  c  o  m*/
        return;
    }

    try {
        //Determine if Contact ID exists
        Uri res = null;
        Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, contactId);

        try {
            res = ContactsContract.Contacts.lookupContact(activity.getContentResolver(), lookupUri);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (res != null) {
            busy = true;
            Intent intent = new Intent(Intent.ACTION_EDIT);
            contactBeingEdited = contactId;
            intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
            intent.setData(res);
            //launch activity
            cordova.setActivityResultCallback(this);
            activity.startActivityForResult(intent, CONTACT_EDIT_RESULT);
            //activity.setLaunchedChildActivity(true); 
        } else {
            contactBeingEdited = "";
            String errjs1 = String.format(
                    "var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.edit',true,true);e.success=false;e.error='contact not found';e.contactid='%s';document.dispatchEvent(e);",
                    contactId);
            injectJS("javascript: " + errjs1);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.TwitterFragment.java

private Intent createShareIntent(String mText) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mText);

    return shareIntent;
}

From source file:com.poinsart.votar.VotarMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    System.loadLibrary("VotAR");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    assetMgr = this.getAssets();

    imageView = (ImageView) findViewById(R.id.imageView);
    bar[0] = (ProgressBar) findViewById(R.id.bar_a);
    bar[1] = (ProgressBar) findViewById(R.id.bar_b);
    bar[2] = (ProgressBar) findViewById(R.id.bar_c);
    bar[3] = (ProgressBar) findViewById(R.id.bar_d);

    barLabel[0] = (TextView) findViewById(R.id.label_a);
    barLabel[1] = (TextView) findViewById(R.id.label_b);
    barLabel[2] = (TextView) findViewById(R.id.label_c);
    barLabel[3] = (TextView) findViewById(R.id.label_d);

    wifiLabel = (TextView) findViewById(R.id.label_wifi);

    mainLayout = ((LinearLayout) findViewById(R.id.mainLayout));
    controlLayout = ((LinearLayout) findViewById(R.id.controlLayout));
    imageLayout = ((LinearLayout) findViewById(R.id.imageLayout));

    adjustLayoutForOrientation(getResources().getConfiguration().orientation);

    findViewById(R.id.buttonCamera).setOnClickListener(new View.OnClickListener() {
        @Override/*w  w  w .  j a v a2  s .  c o  m*/
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            cameraFileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraFileUri); // set the image file name

            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
    findViewById(R.id.buttonGallery).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST);
        }
    });
    votarwebserver = new VotarWebServer(51285, this);
    try {
        votarwebserver.start();
    } catch (IOException e) {
        Log.w("Votar MainAct", "The webserver could not be started, remote display wont be available");
    }
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

public void shareText(String txt) {
    Intent sendintent = new Intent(Intent.ACTION_SEND);
    sendintent.setAction(Intent.ACTION_SEND);
    sendintent.putExtra(Intent.EXTRA_TEXT, txt);
    sendintent.setType("text/plain");
    startActivity(Intent.createChooser(sendintent, "Share Url to..."));
}

From source file:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountCar.java

/**
 * Displaying the car information in the layout.
 * @param res/* w  w  w. j a v a 2s  .co  m*/
 */
public void showMain(CarResponse res, PreferenceResponse prefResInit) {
    // Initializing the views
    setContentView(R.layout.my_account_car);
    this.imageView = (ImageView) this.findViewById(R.id.cameraView);
    carName = (EditText) this.findViewById(R.id.carName);
    bar = (RatingBar) this.findViewById(R.id.ratingBar1);
    seatsText = (EditText) this.findViewById(R.id.myAccountCarSeats);

    // Setting the number of seats available
    prefRes = prefResInit;
    seatsAvailable = prefRes.getPreferences().getSeatsAvailable();
    if (seatsAvailable > 0) {
        seatsText.setText(seatsAvailable.toString());
    } else {
        seatsText.setText("");
    }

    // If the user does have a car registered
    if (user.getCarId() != 0) {
        // Setting the car name
        carNameString = res.getCar().getCarName();
        // Setting the car ID
        id = res.getCar().getCarId();
        // Setting the comfort
        comfort = (float) res.getCar().getComfort();
        // Getting the car image
        byteArray = res.getCar().getPhoto();

        /*Values of the car from database*/

        // Display these values to the user
        carName.setText(carNameString);
        bar.setRating(comfort);

        String empty = "No car type set";
        byteArrayx = empty.getBytes();
        // If a new image is set, display it
        if (byteArray.length > 15) {
            if (!(res.getCar().getPhotoAsBase64().equals(Base64.encode(byteArrayx, Base64.URL_SAFE)))) {
                btm = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
                imageView.setImageBitmap(btm);
            }
        }
        // Indicates that the car is initialized
        isCarInitialized = true;
    }
    //if user does not yet have a car registated
    else {
        carNameString = "";
        id = -1;
        comfort = 0.0f;
        String empty = "No car type set";
        byteArray = empty.getBytes();
    }

    // Setting the button for taking a car picture
    Button photoButton = (Button) this.findViewById(R.id.cameraButton);
    photoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            carChanged = true;
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, "tempName");
            cameraIntent.putExtra("return-data", true);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
    // Setting the button for getting a car picture from the phone
    Button getimageButton = (Button) this.findViewById(R.id.getimageButton);
    getimageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            carChanged = true;
            Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, ALBUM_REQUEST);
        }
    });
}

From source file:com.example.cake.mqtttest.registerActivity.java

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

    Button bt_regis = (Button) findViewById(R.id.bt_cancel);
    bt_regis.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w .j  ava2 s.c om*/
        public void onClick(View view) {

            Intent i_regis = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(i_regis);
        }
    });

    TextView cImage = (TextView) findViewById(R.id.choose_image_from);
    cImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, SELECT_PHOTO);
        }
    });

    Eid = (EditText) findViewById(R.id.edit_id);
    EfirstName = (EditText) findViewById(R.id.edit_first_name);
    ElastName = (EditText) findViewById(R.id.edit_lastname);
    Eemail = (EditText) findViewById(R.id.edit_email);
    EphoneNumber = (EditText) findViewById(R.id.edit_mobile_number);
    Epassword = (EditText) findViewById(R.id.edit_pass);
    // EidNumber = (EditText) findViewById(R.id.edit_id);
    EcarModel = (EditText) findViewById(R.id.edit_car_model);
    ElicensePlateNumber = (EditText) findViewById(R.id.edit_license_plate);

    Button bt_reg = (Button) findViewById(R.id.bt_regis);
    bt_reg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String[] ll = new String[9];
            ll[0] = "id" + Eid.getText().toString();
            ll[1] = EfirstName.getText().toString();
            ll[2] = ElastName.getText().toString();
            ll[3] = Eemail.getText().toString();
            ll[4] = EphoneNumber.getText().toString();
            ll[5] = Epassword.getText().toString();
            ll[6] = Eid.getText().toString();
            ll[7] = EcarModel.getText().toString();
            ll[8] = ElicensePlateNumber.getText().toString();

            if (!ll[0].isEmpty() && !ll[1].isEmpty() && !ll[2].isEmpty() && !ll[3].isEmpty() && !ll[4].isEmpty()
                    && !ll[5].isEmpty() && !ll[6].isEmpty() && !ll[7].isEmpty() && !ll[8].isEmpty()) {
                sendRegisterRequest loginRequest = new sendRegisterRequest();
                loginRequest.delegate = registerActivity.this;
                loginRequest.execute(ll);

                String filename = Eid.getText().toString() + ".png";
                String[] lll = { filename, encoded };
                sendImageRequest imRequest = new sendImageRequest();
                imRequest.delegate = registerActivity.this;
                imRequest.execute(lll);

            } else {
                new AlertDialog.Builder(registerActivity.this).setCancelable(false).setTitle("Incomplete data")
                        .setMessage("Please fill all the fields.")
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        }).show();

            }

        }
    });

}

From source file:com.wikonos.fingerprint.activities.MainActivity.java

/**
 * Create dialog list of logs/*from   ww  w  .jav  a 2s.com*/
 * 
 * @return
 */
public AlertDialog getDialogReviewLogs() {
    /**
     * List of logs
     */
    File folder = new File(LogWriter.APPEND_PATH);
    final String[] files = folder.list(new FilenameFilter() {
        public boolean accept(File dir, String filename) {
            if (filename.contains(".log") && !filename.equals(LogWriter.DEFAULT_NAME)
                    && !filename.equals(LogWriterSensors.DEFAULT_NAME)
                    && !filename.equals(ErrorLog.DEFAULT_NAME))
                return true;
            else
                return false;
        }
    });

    Arrays.sort(files);
    ArrayUtils.reverse(files);

    String[] files_with_status = new String[files.length];
    String[] sent_mode = { "", "(s) ", "(e) ", "(s+e) " };
    for (int i = 0; i < files.length; ++i) {
        //0 -- not sent
        //1 -- server
        //2 -- email
        files_with_status[i] = sent_mode[getSentFlags(files[i], this)] + files[i];
    }

    if (files != null && files.length > 0) {

        final boolean[] selected = new boolean[files.length];

        final AlertDialog ald = new AlertDialog.Builder(MainActivity.this)
                .setMultiChoiceItems(files_with_status, selected,
                        new DialogInterface.OnMultiChoiceClickListener() {
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                selected[which] = isChecked;
                            }
                        })
                .setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        // removeDialog(DIALOG_ID_REVIEW);
                    }
                })
                /**
                * Delete log
                */
                .setNegativeButton("Delete", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        //Show delete confirm
                        standardConfirmDialog("Delete Logs", "Are you sure you want to delete selected logs?",
                                new OnClickListener() {
                                    //Confrim Delete
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                        int deleteCount = 0;
                                        boolean flagSelected = false;
                                        for (int i = 0; i < selected.length; i++) {
                                            if (selected[i]) {
                                                flagSelected = true;
                                                LogWriter.delete(files[i]);
                                                LogWriter.delete(files[i].replace(".log", ".dev"));
                                                deleteCount++;
                                            }
                                        }

                                        reviewLogsCheckItems(flagSelected);

                                        removeDialog(DIALOG_ID_REVIEW);

                                        Toast.makeText(getApplicationContext(), deleteCount + " logs deleted.",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }, new OnClickListener() {
                                    //Cancel Delete
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        //Do nothing
                                        dialog.dismiss();
                                        Toast.makeText(getApplicationContext(), "Delete cancelled.",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }, false);
                    }
                })
                /**
                * Send to server functional
                **/
                .setNeutralButton("Send to Server", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (isOnline()) {
                            ArrayList<String> filesList = new ArrayList<String>();

                            for (int i = 0; i < selected.length; i++)
                                if (selected[i]) {

                                    filesList.add(LogWriter.APPEND_PATH + files[i]);
                                    //Move to httplogsender
                                    //setSentFlags(files[i], 1, MainActivity.this);   //Mark file as sent
                                }

                            if (reviewLogsCheckItems(filesList.size() > 0 ? true : false)) {
                                DataPersistence d = new DataPersistence(getApplicationContext());
                                new HttpLogSender(MainActivity.this,
                                        d.getServerName() + getString(R.string.submit_log_url), filesList)
                                                .setToken(getToken()).execute();
                            }

                            // removeDialog(DIALOG_ID_REVIEW);
                        } else {
                            standardAlertDialog(getString(R.string.msg_alert),
                                    getString(R.string.msg_no_internet), null);
                        }
                    }
                })
                /**
                * Email
                **/
                .setPositiveButton("eMail", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        boolean flagSelected = false;
                        // convert from paths to Android friendly
                        // Parcelable Uri's
                        ArrayList<Uri> uris = new ArrayList<Uri>();
                        for (int i = 0; i < selected.length; i++)
                            if (selected[i]) {
                                flagSelected = true;
                                /** wifi **/
                                File fileIn = new File(LogWriter.APPEND_PATH + files[i]);
                                Uri u = Uri.fromFile(fileIn);
                                uris.add(u);

                                /** sensors **/
                                File fileInSensors = new File(
                                        LogWriter.APPEND_PATH + files[i].replace(".log", ".dev"));
                                Uri uSens = Uri.fromFile(fileInSensors);
                                uris.add(uSens);

                                setSentFlags(files[i], 2, MainActivity.this); //Mark file as emailed
                            }

                        if (reviewLogsCheckItems(flagSelected)) {
                            /**
                             * Run sending email activity
                             */
                            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                            emailIntent.setType("plain/text");
                            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                                    "Wifi Searcher Scan Log");
                            emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                        }

                        // removeDialog(DIALOG_ID_REVIEW);
                    }
                }).create();

        ald.getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

                AlertDialog segmentNameAlert = segmentNameDailog("Rename Segment", ald.getContext(),
                        files[position], null, view, files, position);
                segmentNameAlert.setCanceledOnTouchOutside(false);
                segmentNameAlert.show();
                return false;
            }
        });
        return ald;
    } else {
        return standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_log_nocount),
                new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(DIALOG_ID_REVIEW);
                    }
                });
    }
}