Example usage for android.content Intent EXTRA_TEXT

List of usage examples for android.content Intent EXTRA_TEXT

Introduction

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

Prototype

String EXTRA_TEXT

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

Click Source Link

Document

A constant CharSequence that is associated with the Intent, used with #ACTION_SEND to supply the literal data to be sent.

Usage

From source file:ca.mudar.parkcatcher.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final boolean isLocal = intent.getBooleanExtra(Const.INTENT_EXTRA_SERVICE_LOCAL, false);
    final boolean isRemote = intent.getBooleanExtra(Const.INTENT_EXTRA_SERVICE_REMOTE, false);

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null) {
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    }//from  ww  w  .j av a 2s .  c om

    try {
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.
        if (isLocal) {
            syncLocal();
            ((ParkingApp) getApplicationContext()).setHasLoadedData(true);
        }
        if (isRemote) {
            syncRemote();
            ((ParkingApp) getApplicationContext()).setHasLoadedData(true);
        }

    } catch (HandlerException e) {
        e.printStackTrace();

        if (receiver != null) {
            /**
             * Pass back error to surface listener
             */
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    if (receiver != null) {
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
    }
}

From source file:org.androidtitlan.estoesgoogle.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE);

    try {/*from  ww  w . j  ava  2s  .c o m*/
        // Bulk of sync work, performed by executing several fetches from
        // local sources.

        // Load static local data
        mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler());
        mLocalExecutor.execute(R.xml.speakers, new LocalSpeakersHandler());
        mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler());
        mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
        mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler());

        // Save local parsed version
        prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.bangz.shotrecorder.RecordDetailActivity.java

private void setShareIntent() {

    if (mShareActionProvider != null) {

        final TextView viewNumber = (TextView) findViewById(R.id.txtNumber);
        String strnumber = viewNumber.getText().toString();

        final TextView viewTime = (TextView) findViewById(R.id.txtTime);
        String strTime = viewTime.getText().toString();

        final TextView viewDate = (TextView) findViewById(R.id.txtDate);
        String strDate = viewDate.getText().toString();

        final TextView viewdescription = (TextView) findViewById(R.id.txtDescription);
        String strDescription = viewdescription.getText().toString();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        String strcontent = String.format(getResources().getString(R.string.share_content), strDescription,
                strnumber, strTime, strDate);
        intent.putExtra(Intent.EXTRA_TEXT, strcontent);
        mShareActionProvider.setShareIntent(intent);
    }//from w  w w.jav  a2s.  c om

}

From source file:me.kartikarora.transfersh.adapters.FileGridAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    FileItemViewHolder holder = (FileItemViewHolder) view.getTag();
    int nameCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_NAME);
    int typeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_TYPE);
    int sizeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_SIZE);
    int urlCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_URL);
    final String name = cursor.getString(nameCol);
    final String type = cursor.getString(typeCol);
    final String size = cursor.getString(sizeCol);
    final String url = cursor.getString(urlCol);
    holder.fileNameTextView.setText(name);
    String ext = FilenameUtils.getExtension(name);
    int identifier = context.getResources().getIdentifier("t" + ext, "drawable", context.getPackageName());
    try {/*from   w w  w.jav  a2  s.c o  m*/
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), identifier, null));
    } catch (Resources.NotFoundException e) {
        e.printStackTrace();
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.tblank, null));
    }

    holder.fileInfoImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String message = "Name: " + name + "\n" + "File type: " + type + "\n" + "URL: " + url;
            new AlertDialog.Builder(activity).setMessage(message).setPositiveButton(android.R.string.ok, null)
                    .create().show();
        }
    });

    holder.fileShareImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tracker.send(
                    new HitBuilders.EventBuilder().setCategory("Action").setAction("Share : " + url).build());
            context.startActivity(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, url)
                    .setType("text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    holder.fileDownloadImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            checkForDownload(name, type, url, view);
        }
    });
}

From source file:com.phonegap.cordova.FileOpener.java

private void openFile(String url, String type) throws IOException {
    // Create URI
    Uri uri = Uri.parse(url);/*from   ww  w . j a v  a 2 s .  c  o m*/

    Intent intent = null;
    Log.v("FileOpener", "Type: " + type);

    if (type.equals("pdfshare")) {
        intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
        // intent.setDataAndType(uri, "application/pdf");
        intent.setType("application/pdf");
        intent.putExtra(Intent.EXTRA_SUBJECT, "AMR Report");
        intent.putExtra(Intent.EXTRA_TEXT, "");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else if (url.contains(".pdf")) {
        // PDF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/pdf");
    } else if (url.contains(".ppt") || url.contains(".pptx")) {
        // Powerpoint file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if (url.contains(".xls") || url.contains(".xlsx")) {
        // Excel file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if (url.contains(".rtf")) {
        // RTF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/rtf");
    } else if (url.contains(".wav")) {
        // WAV audio file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/x-wav");
    } else if (url.contains(".gif")) {
        // GIF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/gif");
    } else if (url.contains(".jpg") || url.contains(".jpeg")) {
        // JPG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/jpeg");
    } else if (url.contains(".png")) {
        // PNG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/png");
    } else if (url.contains(".txt")) {
        // Text file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "text/plain");
    } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4")
            || url.contains(".avi")) {
        // Video files
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else if (url.contains(".doc") || url.contains(".docx")) {
        // Word document
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/msword");
    }

    //if you want you can also define the intent type for any other file

    //additionally use else clause below, to manage other unknown extensions
    //in this case, Android will show all applications installed on the device
    //so you can choose which application to use

    else if (type.equals("none") || type.equals("*/*")) {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "*/*");
    } else {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, type);
    }

    //TRY Catch error
    try {
        this.cordova.getActivity().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        intent.setData(uri);
        this.cordova.getActivity().startActivity(intent);
    }
}

From source file:fr.openbike.android.service.SyncService.java

@SuppressWarnings("unchecked")
@Override//from  w w  w  .j ava2  s .  c  om
protected void onHandleIntent(Intent intent) {
    NetworkInfo activeNetwork = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    Bundle bundle = new Bundle();
    int status = STATUS_ERROR;
    if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        bundle = new Bundle();
        bundle.putString(Intent.EXTRA_TEXT, "No network connectivity");
        receiver.send(STATUS_ERROR, bundle);
        return;
    }
    String action = intent.getAction();
    try {
        if (ACTION_SYNC.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor.executeGet(
                    mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "") + "/v2/stations",
                    new RemoteStationsSyncHandler(
                            prefs.getLong(AbstractPreferencesActivity.STATIONS_VERSION, 0)),
                    this);
            if (result == null) {
                // Need stations update
                action = ACTION_UPDATE;
            } else {
                String message = (String) result;
                status = STATUS_SYNC_STATIONS_FINISHED;
                if (!"".equals(message)) {
                    bundle.putString(EXTRA_RESULT, message);
                }
                prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis())
                        .commit();
            }
        }
        if (ACTION_UPDATE.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_UPDATE_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor
                    .executeGet(mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "")
                            + "/v2/stations/list", new RemoteStationsUpdateHandler(), this);
            status = STATUS_UPDATE_STATIONS_FINISHED;
            if (result != null) {
                bundle.putString(EXTRA_RESULT, (String) result);
            }
            prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis()).commit();
        }
        if (ACTION_CHOOSE_NETWORK.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_NETWORKS, Bundle.EMPTY);
                bundle = new Bundle();
                bundle.putParcelableArrayList(EXTRA_RESULT, (ArrayList<Network>) mRemoteExecutor
                        .executeGet(NETWORKS_URL, new RemoteNetworksHandler(), this));
                status = STATUS_SYNC_NETWORKS_FINISHED;
            }
        }
        if (receiver != null) {
            receiver.send(status, bundle);
        }
    } catch (HandlerException e) {
        if (receiver != null) {
            // Pass back error to surface listener
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    } catch (Exception e) {
        if (receiver != null) {
            // Pass back error to surface listener
            e.printStackTrace();
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, "Une erreur est survenue. Veuillez ressayer.");
            receiver.send(STATUS_ERROR, bundle);
        }
    }
}

From source file:activeng.pt.activenglab.BluetoothChatService.java

/**
 * Set the current state of the chat connection
 *
 * @param state An integer defining the current connection state
 *///from   ww  w. ja va2  s.co m
private synchronized void setState(int state) {
    Log.d(TAG, "setState() " + mState + " -> " + state);
    mState = state;

    // Give the new state to the Handler so the UI Activity can update
    // mHandler.obtainMessage(Constants.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();

    Intent intent = new Intent(Constants.MESSAGE_BT_STATE_CHANGE).putExtra(Intent.EXTRA_TEXT, state);
    //mContext.sendBroadcast(intent);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mContext);
    manager.sendBroadcast(intent);
}

From source file:com.callrecorder.android.RecordingsAdapter.java

private void sendMail(String fileName) {
    DocumentFile file = FileHelper.getStorageFile(context).findFile(fileName);
    Uri uri = FileHelper.getContentUri(context, file.getUri());

    Intent sendIntent = new Intent(Intent.ACTION_SEND)
            .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_subject))
            .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.mail_body))
            .putExtra(Intent.EXTRA_STREAM, uri).setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .setType("audio/3gpp");

    context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.send_mail)));
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/** Called when the activity is first started. */
@Override//from w w  w .  j  a v  a  2 s .c  o m
public void onCreate(Bundle bundle) {
    Log.d(LOG_TAG, "entering onCreate()");
    SettingsActivity.setTheme(this);
    super.onCreate(bundle);
    setContentView(R.layout.main);

    try {
        busNet = BusNetwork.getInstance(this);
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        return;
    }

    // get the button
    // set handler to launch a processing dialog
    ImageButton updateButton = (ImageButton) findViewById(R.id.update_button);
    updateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            BusLine selectedLine = lineAdapter.getItem(lineSpinner.getSelectedItemPosition());
            BusStop selectedStop = stopAdapter.getItem(stopSpinner.getSelectedItemPosition());
            getBusTimings(selectedLine, selectedStop);
        }
    });

    ImageButton feedbackButton = (ImageButton) findViewById(R.id.feedback_button);
    feedbackButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822"); // use from live device
            i.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FEEDBACK_EMAIL_ADDRESS });
            i.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_EMAIL_SUBJECT);
            i.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_hello));
            startActivity(Intent.createChooser(i, getString(R.string.select_email_app)));
        }
    });

    ImageButton phebusinfoButton = (ImageButton) findViewById(R.id.phebusinfo_button);
    phebusinfoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog alertDialog = new AlertDialog.Builder(NextBusMain.this).create();
            WebView wv = new WebView(NextBusMain.this);
            new PhebusNewsLoader(wv, NextBusMain.this).execute();
            alertDialog.setView(wv);
            alertDialog.show();
        }
    });

    lineSpinner = (Spinner) findViewById(R.id.line_spinner);
    lineAdapter = new ArrayAdapter<BusLine>(this, android.R.layout.simple_spinner_item, busNet.getLines());
    lineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    lineSpinner.setAdapter(lineAdapter);

    stopSpinner = (Spinner) findViewById(R.id.stop_spinner);
    stopAdapter = new ArrayAdapter<BusStop>(this, android.R.layout.simple_spinner_item);
    stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    stopSpinner.setAdapter(stopAdapter);

    ImageButton favoriteButton = (ImageButton) findViewById(R.id.favorites_button);
    favoriteButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            new FavoriteDialog(NextBusMain.this, new OnFavoriteSelectedListener() {
                @Override
                public void favoriteSelected(Favorite fav) {
                    BusLine bl = busNet.getLineByName(fav.getLine());
                    BusStop bs = bl.getFirstStopWithSimilarName(fav.getStop());
                    if (bl == null || bs == null) {
                        Log.e(LOG_TAG, "Favorite not found!");
                        return;
                    }
                    updateSpinners(bl, bs);
                    getBusTimings(bl, bs);
                }
            }, lineSpinner.getSelectedItem().toString(), stopSpinner.getSelectedItem().toString());
        }
    });
}

From source file:com.autburst.picture.FinishedUploadActivity.java

private void sendLink() {
    String url = createVideoUrl();
    if (url == null) {
        return;//w w w .java 2 s .com
    }
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    Resources res = getResources();
    i.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.downloadlink));
    i.putExtra(Intent.EXTRA_TEXT, url);
    startActivity(Intent.createChooser(i, res.getString(R.string.sendlink)));
}