當前位置: 首頁>>代碼示例>>Java>>正文


Java ShareCompat類代碼示例

本文整理匯總了Java中android.support.v4.app.ShareCompat的典型用法代碼示例。如果您正苦於以下問題:Java ShareCompat類的具體用法?Java ShareCompat怎麽用?Java ShareCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ShareCompat類屬於android.support.v4.app包,在下文中一共展示了ShareCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendFeedbackSharingIntent

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
private void sendFeedbackSharingIntent(){
    Intent shareIntent= ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            //.setType("application/txt") with this flag filters much better, but not as good as sendFeedBabck
            .addEmailTo(getString(R.string.mailto))
            .setSubject(getString(R.string.subject))
            .setText(Constants.EMPTY_STRING)
            .setChooserTitle(R.string.sendchooser_text)
            .createChooserIntent()
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    if (shareIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(shareIntent);
    }
}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:17,代碼來源:MainActivity.java

示例2: shareText

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
private void shareText(String text) {
        String mimeType = "text/plain";
        String title = "learning how to share";
        String textToShare = text;

        ShareCompat.IntentBuilder.from(this)
                .setChooserTitle(title)
                .setType(mimeType)
                .setText(textToShare)
                .startChooser();

//        Intent intent = new Intent();
//        intent.setAction(Intent.ACTION_SEND);
//        intent.putExtra(Intent.EXTRA_TEXT, textToShare);
//        intent.setType(mimeType);
//        startActivity(Intent.createChooser(intent, title));
//        new ShareCompat.IntentBuilder()
    }
 
開發者ID:soryncrash13,項目名稱:Small-Android-apps,代碼行數:19,代碼來源:MainActivity.java

示例3: getCallingApplication

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@Nullable
private String getCallingApplication(ShareCompat.IntentReader intentReader) {
    String callingPackage = intentReader.getCallingPackage();
    if (TextUtils.isEmpty(callingPackage)) {
        Uri referrer = ActivityCompat.getReferrer(this);
        if (referrer != null) {
            callingPackage = referrer.getHost();
        }
    }
    CharSequence label = null;
    if (!TextUtils.isEmpty(callingPackage)) {
        PackageManager pm = getPackageManager();
        try {
            label = pm.getApplicationLabel(pm.getApplicationInfo(callingPackage, 0));
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Could not retrieve label for package " + callingPackage, e);
        }
    }
    return label != null ? label.toString() : null;
}
 
開發者ID:romannurik,項目名稱:muzei,代碼行數:21,代碼來源:GalleryAddPhotosActivity.java

示例4: onOptionsItemSelected

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.meme_share:
            ShareCompat.IntentBuilder
                    .from(this)
                    .setChooserTitle("Share your meme")
                    .setStream(Uri.fromFile(new File(meme.getUri().getPath())))
                    .setType(mimeType)
                    .startChooser();
            break;
        case android.R.id.home:
            onBackPressed();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
開發者ID:daergoth,項目名稱:dankbank,代碼行數:19,代碼來源:MemeActivity.java

示例5: onClick

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@Override
public void onClick(View widget) {
	if (SobotOption.hyperlinkListener != null){
		SobotOption.hyperlinkListener.onEmailClick(email);
		return;
	}
	try {
		ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder
				.from((Activity)widget.getContext());
		builder.setType("message/rfc822");
		builder.addEmailTo(email);
		builder.setSubject("");
		builder.setChooserTitle("");
		builder.startChooser();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:19,代碼來源:EmailSpan.java

示例6: handleShareIntent

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
private void handleShareIntent(final ShareCompat.IntentReader reader) {
    Analytics.event(Analytics.SHARE_VIA_ROBIRD);
    if (reader.getStreamCount() > 0) {
        final int count = reader.getStreamCount() > 4 ? 4 : reader.getStreamCount();
        ComposeFragment
                .share(new ArrayList<Uri>() {
                    {
                        for (int i = 0; i < count; ++i)
                            add(reader.getStream(i));
                    }
                })
                .show(getSupportFragmentManager(), ComposeFragment.TAG_SHARE);
    } else {
        final StringBuilder shareBuilder = new StringBuilder();

        if (!TextUtils.isEmpty(reader.getSubject()))
            shareBuilder.append(reader.getSubject()).append(" ");

        shareBuilder.append(reader.getText());

        ComposeFragment
                .share(shareBuilder.toString())
                .show(getSupportFragmentManager(), ComposeFragment.TAG_SHARE);
    }
}
 
開發者ID:mecid,項目名稱:robird-reborn,代碼行數:26,代碼來源:HomeActivity.java

示例7: sharePhoto

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
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();
    }
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:18,代碼來源:ItemActivity.java

示例8: onCreate

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@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();
    });
}
 
開發者ID:willowtreeapps,項目名稱:android-instant-apps-demo,代碼行數:23,代碼來源:CartActivity.java

示例9: onPostExecute

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@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();
    }
 
開發者ID:goodev,項目名稱:materialup,代碼行數:18,代碼來源:ShareDribbbleImageTask.java

示例10: performShare

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
void performShare(final FileListFragment.MyAdapter.ViewHolder holder) {
    if (!holder.exists) {
        Toast.makeText(callingActivity, R.string.no_file_warning, Toast.LENGTH_SHORT).show();
        return;
    }

    Uri fileUri = FileProvider.getUriForFile(
            callingActivity.getApplicationContext(), "vit01.idecmobile.provider", holder.entry.getLocalFile());

    Intent shareIntent = ShareCompat.IntentBuilder.from(callingActivity)
            .setType(callingActivity.getContentResolver().getType(fileUri))
            .setStream(fileUri)
            .getIntent();

    shareIntent.setData(fileUri);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    if (shareIntent.resolveActivity(callingActivity.getPackageManager()) != null) {
        callingActivity.startActivity(shareIntent);
    } else Toast.makeText(callingActivity, R.string.error, Toast.LENGTH_SHORT).show();
}
 
開發者ID:vit1-irk,項目名稱:idec-mobile,代碼行數:22,代碼來源:FileListFragment.java

示例11: onCreateView

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_article_detail, container, false);

    ScrollView scrollView = (ScrollView) mRootView.findViewById(R.id.scrollview);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        scrollView.setNestedScrollingEnabled(true);
    }

    mPhotoView = (ImageView) getActivity().findViewById(R.id.photo);

    getActivity().findViewById(R.id.share_fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(Intent.createChooser(ShareCompat.IntentBuilder.from(getActivity())
                    .setType("text/plain")
                    .setText("Some sample text")
                    .getIntent(), getString(R.string.action_share)));
        }
    });

    return mRootView;
}
 
開發者ID:frank-tan,項目名稱:XYZReader,代碼行數:25,代碼來源:ArticleDetailFragment.java

示例12: mailReport

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
/**
 * Starts the process of sending an E-mail message with the report
 * @param report the report to send
 */
private void mailReport(BugReport report) {

    final StringBuilder message = new StringBuilder();
    final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis();
    message.append("Time: ");
    formatter.printTo(message, report.getDate());
    message.append('\n');
    message.append("User description: ");
    message.append(report.getDesc());
    message.append("\nMetadata: ");
    message.append(report.getMeta());


    ShareCompat.IntentBuilder.from(this)
            .setType("message/rfc822")
            .addEmailTo(REPORT_ADDRESS)
            .setSubject("Cook-E Problem Report")
            .setText(message)
            .setChooserTitle(R.string.mail_report)
            .startChooser();
    finish();
}
 
開發者ID:Cook-E-team,項目名稱:Cook-E,代碼行數:27,代碼來源:BugReportActivity.java

示例13: onPostExecute

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@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,
            activity.getString(R.string.share_authority), renamed);
    ShareCompat.IntentBuilder.from(activity)
            .setText(getShareText())
            .setType(getImageMimeType(fileName))
            .setSubject(shot.title)
            .setStream(uri)
            .startChooser();
}
 
開發者ID:liulinbo,項目名稱:Amumu,代碼行數:19,代碼來源:ShareDribbbleImageTask.java

示例14: onOptionsItemSelected

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            getActivity().onBackPressed();
            return true;
        case R.id.action_share:
            if (mTrailers == null || mTrailers.size() == 0) return false;
            String trailerUrl = YouTubeTrailerUtils.buildVideoUriForTrailer(mTrailers.get(0)).toString();
            ShareCompat.IntentBuilder
                    .from(getActivity())
                    .setType("text/plain")
                    .setChooserTitle(mMovie.getTitle())
                    .setText(trailerUrl)
                    .startChooser();
            return true;
        default:
            return false;
    }
}
 
開發者ID:vanyaland,項目名稱:Popular-Movies,代碼行數:21,代碼來源:MovieDetailFragment.java

示例15: onPostExecute

import android.support.v4.app.ShareCompat; //導入依賴的package包/類
@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();
}
 
開發者ID:yongjhih,項目名稱:android-proguards,代碼行數:18,代碼來源:ShareDribbbleImageTask.java


注:本文中的android.support.v4.app.ShareCompat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。