android.support.v4.app.ShareCompat Java Examples

The following examples show how to use android.support.v4.app.ShareCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AboutActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
private void shareApp() {
        Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                .setType("text/plain")
                .setText(String.format(getString(R.string.app_share), getPackageName()))
                .getIntent();
        if (shareIntent.resolveActivity(getPackageManager()) != null) {
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.action_share)));
        }
        /*Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, String.format(getString(R.string.app_share), getPackageName()));
        sendIntent.setType("text/plain");


        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share)));
*/
        /*Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, String.format(getString(R.string.app_share), getPackageName()));
        sendIntent.setType("text/plain");
        startActivity(sendIntent);*/
    }
 
Example #2
Source File: MainActivity.java    From android-flat-button with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
        case R.id.action_github:
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(Config.GITHUB_URL));
            startActivity(browse);
            return true;
        case R.id.action_social:
            ShareCompat.IntentBuilder intentBuilder = ShareCompat.IntentBuilder.from(MainActivity.this);
            intentBuilder.setChooserTitle("Choose Share App")
                    .setType("text/plain")
                    .setSubject("Flat button for android")
                    .setText("A flat button library for android #AndroidFlat goo.gl/C6aLDi")
                    .startChooser();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #3
Source File: ItemActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
public void sharePhoto() {
    Uri uri = albumItem.getUri(this);

    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .addStream(uri)
            .setType(MediaType.getMimeType(this, uri))
            .getIntent();

    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    String title = getString(R.string.share_item, albumItem.getType(this));
    if (shareIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(Intent.createChooser(shareIntent, title));
    } else {
        String error = getString(R.string.share_error, albumItem.getType(this));
        Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
}
 
Example #4
Source File: CartActivity.java    From android-instant-apps-demo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cart);
    viewModel = ViewModelProviders.of(this).get(CartViewModel.class);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    toolbar = (Toolbar) findViewById(R.id.toolbar);

    setupToolbar();
    handleDeepLink();

    fab.setImageDrawable(VectorDrawableCompat.create(getResources(), R.drawable.ic_share_white_24dp, null));
    fab.setOnClickListener(view -> {
        String cartId = viewModel.getCartId().getValue();
        ShareCompat.IntentBuilder.from(this)
                .setText(String.format(Locale.US, "Check out my shopping cart now using Android Instant Apps! \n%s/cart/%s", ROOT_ENDPOINT, cartId))
                .setType("text/plain")
                .setChooserTitle(share_cart)
                .startChooser();
    });
}
 
Example #5
Source File: ShareDribbbleImageTask.java    From materialup with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onPostExecute(File result) {
        if (result == null) {
            return;
        }
        // glide cache uses an unfriendly & extension-less name,
        // massage it based on the original
//        result.renameTo(renamed);
        Uri uri = FileProvider.getUriForFile(activity,
                activity.getString(R.string.share_authority), result);
        ShareCompat.IntentBuilder.from(activity)
                .setText(getShareText())
                .setType(getImageMimeType(result.getName()))
                .setSubject(shot.title)
                .setStream(uri)
                .startChooser();
    }
 
Example #6
Source File: MoverRecycleFragment.java    From Mover with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem menuItem) {

    switch (menuItem.getItemId()){
        case R.id.share:
            Video video = ((WatchMeAdapterNew.WatchMeHolder) getRecycleView()
                    .findViewHolderForPosition(mSelectedVideoPosition)).getObject();

            ShareCompat.IntentBuilder.from(getActivity())
                    .setChooserTitle(R.string.abc_shareactionprovider_share_with)
                    .setType("text/plain")
                    .setText(getString(R.string.sharing_video_template, video.getTitle(), video.getLinkForShare()))
                    .startChooser();

            return true;

        default:
            return false;
    }
}
 
Example #7
Source File: ShareDribbbleImageTask.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(File result) {
    if (result == null) { return; }
    // glide cache uses an unfriendly & extension-less name,
    // massage it based on the original
    String fileName = shot.images.best();
    fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
    File renamed = new File(result.getParent(), fileName);
    result.renameTo(renamed);
    Uri uri = FileProvider.getUriForFile(activity, BuildConfig.FILES_AUTHORITY, renamed);
    ShareCompat.IntentBuilder.from(activity)
            .setText(getShareText())
            .setType(getImageMimeType(fileName))
            .setSubject(shot.title)
            .setStream(uri)
            .startChooser();
}
 
Example #8
Source File: MainPresenter.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
@Override public void onShareUserBackup(@NonNull MainView mainView, @NonNull FirebaseUser currentUser) {
    String packageName = mainView.getApplicationContext().getPackageName();
    Uri deepLinkBuilder = new Uri.Builder()
            .scheme("http")
            .authority(BuildConfig.FA_HOST)
            .appendQueryParameter(BuildConfig.SHARED_URI, currentUser.getUid())
            .build();
    Uri.Builder builder = new Uri.Builder()
            .scheme("https")
            .authority(mainView.getResources().getString(R.string.link_ref) + ".app.goo.gl")
            .path("/")
            .appendQueryParameter("link", Uri.parse(deepLinkBuilder.toString()).toString())
            .appendQueryParameter("apn", packageName);
    ShareCompat.IntentBuilder.from(mainView)
            .setType("message/*")
            .setSubject(mainView.getString(R.string.sharing_backup))
            .setChooserTitle(mainView.getString(R.string.share_my_backup))
            .setHtmlText("<a href='" + Uri.decode(builder.toString()) + "'>" + mainView.getString(R.string.click_here_html) +
                    "</a><br/><b>~" + mainView.getString(R.string.app_name) + "</b>").startChooser();
}
 
Example #9
Source File: ActivityHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
public static void shareUrl(@NonNull Context context, @NonNull String url) {
    Activity activity = getActivity(context);
    if (activity == null) throw new IllegalArgumentException("Context given is not an instance of activity " + context.getClass().getName());
    try {
        ShareCompat.IntentBuilder.from(activity)
                .setChooserTitle(context.getString(R.string.share))
                .setType("text/plain")
                .setText(url)
                .startChooser();
    } catch (ActivityNotFoundException e) {
        AlertUtils.showToastShortMessage(context, e.getMessage());
    }
}
 
Example #10
Source File: Utils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void openFeedback(Activity activity){
    ShareCompat.IntentBuilder
            .from(activity)
            .setEmailTo(new String[]{"[email protected]"})
            .setSubject("FireFiles Feedback" + getSuffix())
            .setType("text/email")
            .setChooserTitle("Send Feedback")
            .startChooser();
}
 
Example #11
Source File: Utils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void openFeedback(Activity activity){
    ShareCompat.IntentBuilder
            .from(activity)
            .setEmailTo(new String[]{"[email protected]"})
            .setSubject("FireFiles Feedback" + getSuffix())
            .setType("text/email")
            .setChooserTitle("Send Feedback")
            .startChooser();
}
 
Example #12
Source File: MainActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
private void share() {
        ShareCompat.IntentBuilder.from(this)
                .setText(getString(R.string.share_text))
                .setType("text/plain")
                .setSubject(getString(R.string.share_subject))
//                .setStream(Uri.parse("android.resource://drawable/image_name"))
                .startChooser();
    }
 
Example #13
Source File: AboutDialog.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void handleShareAction() {
    ShareCompat.IntentBuilder.from(getActivity())
            .setChooserTitle(R.string.text_share_chooser_title)
            .setSubject(getString(R.string.text_share_subject))
            .setText(getString(R.string.text_share_text) + " " + APP_IN_GOOGLE_PLAY)
            .setType("text/plain")
            .startChooser();

    Tracker.getInstance()
            .logEvent(TrackCons.About.CLICK_SHARE);
}
 
Example #14
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. We set the
 * type of content that we are sharing (just regular text), the text itself, and we return the
 * newly created Intent.
 *
 * @return The Intent to use to start our share.
 */
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecast + FORECAST_SHARE_HASHTAG)
            .getIntent();
    return shareIntent;
}
 
Example #15
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the ShareCompat Intent builder to create our Forecast intent for sharing.  All we need
 * to do is set the type, text and the NEW_DOCUMENT flag so it treats our share as a new task.
 * See: http://developer.android.com/guide/components/tasks-and-back-stack.html for more info.
 *
 * @return the Intent to use to share our weather forecast
 */
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecastSummary + FORECAST_SHARE_HASHTAG)
            .getIntent();
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    return shareIntent;
}
 
Example #16
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. We set the
 * type of content that we are sharing (just regular text), the text itself, and we return the
 * newly created Intent.
 *
 * @return The Intent to use to start our share.
 */
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecast + FORECAST_SHARE_HASHTAG)
            .getIntent();
    return shareIntent;
}
 
Example #17
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. We set the
 * type of content that we are sharing (just regular text), the text itself, and we return the
 * newly created Intent.
 *
 * @return The Intent to use to start our share.
 */
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecast + FORECAST_SHARE_HASHTAG)
            .getIntent();
    return shareIntent;
}
 
Example #18
Source File: Utils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void openFeedback(Activity activity){
    ShareCompat.IntentBuilder
            .from(activity)
            .setEmailTo(new String[]{"[email protected]"})
            .setSubject("FireFiles Feedback" + getSuffix())
            .setType("text/email")
            .setChooserTitle("Send Feedback")
            .startChooser();
}
 
Example #19
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
public void shareText(View view) {
    String txt = mShareTextEditText.getText().toString();
    String mimeType = "text/plain";
    ShareCompat.IntentBuilder
            .from(this)
            .setType(mimeType)
            .setChooserTitle("Share this text with: ")
            .setText(txt)
            .startChooser();
}
 
Example #20
Source File: CrashActivity.java    From PlayMusicExporter with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.action_restart) {
        // Close this window
        finish();

        // Restart the app
        startActivity(mLaunchIntent);
    } else if (id == R.id.action_email) {
        // Send email
        ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(this);
        builder.setType("message/rfc822");
        builder.addEmailTo(mMetaDataEmail);
        builder.setSubject("Crash log for " + mAppName);
        builder.setChooserTitle(R.string.crashhandler_choose_email_title);
        builder.setText(mCrashLog);
        builder.startChooser();
    } else if (id == R.id.action_support) {
        // Open Homepage
        Intent intentUrl = new Intent(Intent.ACTION_VIEW, Uri.parse(mMetaDataSupportURL));
        startActivity(intentUrl);

    } else if (id == R.id.action_close_dialog) {
        // Close this window
        finish();
    } else { // Other
        return super.onOptionsItemSelected(item);
    }


    // One of our items was selected
    return true;
}
 
Example #21
Source File: ShareActivity.java    From Shaarlier with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load data passed through the intent
 */
private void readIntent(@NonNull Intent intent) {
    ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this);
    String defaultUrl = extractUrl(reader.getText().toString());
    String defaultTitle = extractTitle(reader.getSubject());
    String defaultDescription = intent.getStringExtra("description") != null ? intent.getStringExtra("description") : "";
    String defaultTags = intent.getStringExtra("tags") != null ? intent.getStringExtra("tags") : "";

    if (!userPrefs.isAutoTitle()) {
        defaultTitle = "";
    }
    if (!userPrefs.isAutoDescription()) {
        defaultDescription = "";
    }
    defaults = new Link(
            defaultUrl,
            defaultTitle,
            defaultDescription,
            defaultTags,
            userPrefs.isPrivateShare(),
            selectedAccount,
            userPrefs.isTweet(),
            userPrefs.isToot(),
            null,
            null
    );
}
 
Example #22
Source File: ExportGeoJSONTask.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void share(File path) {
    if (path == null || !path.exists()) {
        Toast.makeText(mActivity, R.string.error_create_feature, Toast.LENGTH_SHORT).show();
        return;
    }

    Intent shareIntent = new Intent();
    String type = "application/json,application/vnd.geo+json,application/zip";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        String authority = mActivity.getPackageName() + AUTHORITY;
        Uri uri = FileProvider.getUriForFile(mActivity, authority, path);
        shareIntent = ShareCompat.IntentBuilder.from(mActivity)
                                               .setStream(uri)
                                               .setType(type)
                                               .getIntent()
                                               .setAction(Intent.ACTION_SEND)
                                               .setDataAndType(uri, type)
                                               .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else {
        shareIntent = Intent.createChooser(shareIntent, mActivity.getString(R.string.menu_share));
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(path));
        shareIntent.setType(type);
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    //        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, urisArray); // multiple data
    try {
        mActivity.startActivity(shareIntent);
    } catch (ActivityNotFoundException e) {
        notFound(mActivity);
    }
}
 
Example #23
Source File: InstallHistoryActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.menu_share:
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Repos:\n");
            for (Repo repo : RepoProvider.Helper.all(this)) {
                if (repo.inuse) {
                    stringBuilder.append("* ");
                    stringBuilder.append(repo.address);
                    stringBuilder.append('\n');
                }
            }
            ShareCompat.IntentBuilder intentBuilder = ShareCompat.IntentBuilder.from(this)
                    .setStream(InstallHistoryService.LOG_URI)
                    .setSubject(getString(R.string.send_history_csv, getString(R.string.app_name)))
                    .setChooserTitle(R.string.send_install_history)
                    .setText(stringBuilder.toString())
                    .setType("text/plain");
            Intent intent = intentBuilder.getIntent();
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(intent);
            break;
        case R.id.menu_delete:
            getContentResolver().delete(InstallHistoryService.LOG_URI, null, null);
            TextView textView = findViewById(R.id.text);
            textView.setText("");
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #24
Source File: InstalledAppsActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.menu_share:
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("packageName,versionCode,versionName\n");
            for (int i = 0; i < adapter.getItemCount(); i++) {
                App app = adapter.getItem(i);
                if (app != null) {
                    stringBuilder.append(app.packageName).append(',')
                            .append(app.installedVersionCode).append(',')
                            .append(app.installedVersionName).append('\n');
                }
            }
            ShareCompat.IntentBuilder intentBuilder = ShareCompat.IntentBuilder.from(this)
                    .setSubject(getString(R.string.send_installed_apps))
                    .setChooserTitle(R.string.send_installed_apps)
                    .setText(stringBuilder.toString())
                    .setType("text/csv");
            startActivity(intentBuilder.getIntent());
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #25
Source File: SharingSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    ShareCompat.IntentBuilder b = ShareCompat.IntentBuilder.from(this);
    b.setType("text/plain").setText("Share from menu");
    MenuItem item = menu.add("Share");
    ShareCompat.configureMenuItem(item, b);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    return true;
}
 
Example #26
Source File: IntentUtils.java    From issue-reporter-android with MIT License 5 votes vote down vote up
public static void sendMail(Activity activity, ReportMail reportMail, Uri fileUri) {
    Intent intent = ShareCompat.IntentBuilder.from(activity)
            .addEmailTo(reportMail.getEmail())
            .setSubject(reportMail.getSubject())
            .setText(reportMail.getBody())
            .setType("text/plain")
            .setStream(fileUri)
            .getIntent()
            .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                    | Intent.FLAG_GRANT_READ_URI_PERMISSION);

    activity.startActivity(intent);
}
 
Example #27
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecast + FORECAST_SHARE_HASHTAG)
            .getIntent();
    return shareIntent;
}
 
Example #28
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void shareFile(Activity context, File f) {
    try {
        Uri uri = Uri.fromFile(f);
        ShareCompat.IntentBuilder.from(context)
                .setStream(uri)
                .setType(URLConnection.guessContentTypeFromName(f.getName()))
                .startChooser();
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
Example #29
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
public void shareText(View view) {
    String txt = mShareTextEditText.getText().toString();
    String mimeType = "text/plain";
    ShareCompat.IntentBuilder
            .from(this)
            .setType(mimeType)
            .setChooserTitle("Share this text with: ")
            .setText(txt)
            .startChooser();
}
 
Example #30
Source File: SqliteManagerUtils.java    From SqliteManager with Apache License 2.0 5 votes vote down vote up
private static void createTempFileAndShare(AppCompatActivity context, String fileShareAuthority, String csvString, String csvFileName, String type) {
        try {
            File fileDir = new File(context.getFilesDir(), "sqliteManager");
            fileDir.mkdir();
            File file = new File(fileDir, csvFileName);
            file.createNewFile();

            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(csvString.getBytes());
            fileOutputStream.close();

            // generate URI, defined authority as the application ID in the Manifest
            Uri uriToCSVFIle = FileProvider.getUriForFile(context, fileShareAuthority, file);

            Intent shareIntent =
                    ShareCompat.IntentBuilder
                            .from(context)
                            .setStream(uriToCSVFIle)
                            .setType(type)
                            .getIntent();

            // Provide read access
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            // validate that the device can open your File!
            PackageManager pm = context.getPackageManager();
            if (shareIntent.resolveActivity(pm) != null) {
                context.startActivity(shareIntent);
            }
        } catch (Exception e) {
//                    e.printStackTrace();
        }
    }