本文整理汇总了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);
}
}
示例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()
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
});
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
}
示例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();
}