android.content.Intent.setType()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(302)

本文整理了Java中android.content.Intent.setType()方法的一些代码示例,展示了Intent.setType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.setType()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:setType

Intent.setType介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
  startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
  Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

代码示例来源:origin: stackoverflow.com

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

代码示例来源:origin: nickbutcher/plaid

public static void addToPocket(Context context,
                String url,
                String tweetStatusId) {
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setPackage(PACKAGE);
  intent.setType(MIME_TYPE);
  intent.putExtra(Intent.EXTRA_TEXT, url);
  if (tweetStatusId != null && tweetStatusId.length() > 0) {
    intent.putExtra(EXTRA_TWEET_STATUS_ID, tweetStatusId);
  }
  intent.putExtra(EXTRA_SOURCE_PACKAGE, context.getPackageName());
  context.startActivity(intent);
}

代码示例来源:origin: ArthurHub/Android-Image-Cropper

List<Intent> intents = new ArrayList<>();
Intent galleryIntent =
  action == Intent.ACTION_GET_CONTENT
    ? new Intent(action)
    : new Intent(action, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0);
for (ResolveInfo res : listGallery) {
 Intent intent = new Intent(galleryIntent);
 intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
 intent.setPackage(res.activityInfo.packageName);
 intents.add(intent);

代码示例来源:origin: stackoverflow.com

intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, person.name);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, person.mobile);
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, person.email);
String email = person.email;
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

代码示例来源:origin: stackoverflow.com

Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");

File downloadedPic =  new File(
  Environment.getExternalStoragePublicDirectory(
  Environment.DIRECTORY_DOWNLOADS),
  "q.jpeg");

picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));

代码示例来源:origin: square/leakcanary

private void startShareIntentChooser(Uri heapDumpUri) {
 Intent intent = new Intent(Intent.ACTION_SEND);
 intent.setType("application/octet-stream");
 intent.putExtra(Intent.EXTRA_STREAM, heapDumpUri);
 startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with)));
}

代码示例来源:origin: pockethub/PocketHub

private void startImagePicker() {
  Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
  photoPickerIntent.setType("image/*");
  startActivityForResult(photoPickerIntent, REQUEST_CODE_SELECT_PHOTO);
}

代码示例来源:origin: stackoverflow.com

public void onClickWhatsApp(View view) {

  PackageManager pm=getPackageManager();
  try {

    Intent waIntent = new Intent(Intent.ACTION_SEND);
    waIntent.setType("text/plain");
    String text = "YOUR TEXT HERE";

    PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
    //Check if package exists or not. If not then code 
    //in catch block will be called
    waIntent.setPackage("com.whatsapp");

    waIntent.putExtra(Intent.EXTRA_TEXT, text);
    startActivity(Intent.createChooser(waIntent, "Share with"));

  } catch (NameNotFoundException e) {
    Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
        .show();
  }  

}

代码示例来源:origin: stackoverflow.com

public Intent findTwitterClient() {
  final String[] twitterApps = {
      // package // name - nb installs (thousands)
      "com.twitter.android", // official - 10 000
      "com.twidroid", // twidroid - 5 000
      "com.handmark.tweetcaster", // Tweecaster - 5 000
      "com.thedeck.android" }; // TweetDeck - 5 000 };
  Intent tweetIntent = new Intent();
  tweetIntent.setType("text/plain");
  final PackageManager packageManager = getPackageManager();
  List<ResolveInfo> list = packageManager.queryIntentActivities(
      tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);

  for (int i = 0; i < twitterApps.length; i++) {
    for (ResolveInfo resolveInfo : list) {
      String p = resolveInfo.activityInfo.packageName;
      if (p != null && p.startsWith(twitterApps[i])) {
        tweetIntent.setPackage(p);
        return tweetIntent;
      }
    }
  }

  return null;
}

代码示例来源:origin: stackoverflow.com

Intent intent = new Intent();
 intent.setType("image/*");
 intent.setAction(Intent.ACTION_GET_CONTENT);
 intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
 startActivityForResult(Intent.createChooser(intent,
     "Complete action using"), PHOTO_PICKER_ID);

代码示例来源:origin: stackoverflow.com

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri fileUri = FileProvider.getUriForFile(mContext, "com.myfileprovider", new File(mFilename));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
mContext.startActivity(Intent.createChooser(shareIntent, mChooserTitle));

代码示例来源:origin: naman14/Timber

public static void shareTrack(final Context context, long id) {
  try {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.putExtra(Intent.EXTRA_STREAM, getSongUri(context, id));
    context.startActivity(Intent.createChooser(share, "Share"));
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: crazycodeboy/TakePhoto

/**
 * 获取选择照片的Intent
 *
 * @return
 */
public static Intent getPickIntentWithGallery() {
  Intent intent = new Intent();
  intent.setAction(Intent.ACTION_PICK);//Pick an item from the data
  intent.setType("image/*");//从所有图片中进行选择
  return intent;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void startActivityForResultAndReceiveResult_shouldSendResponsesBackToActivity() throws Exception {
 TranscriptActivity activity = Robolectric.setupActivity(TranscriptActivity.class);
 activity.startActivityForResult(new Intent().setType("audio/*"), 123);
 activity.startActivityForResult(new Intent().setType("image/*"), 456);
 shadowOf(activity).receiveResult(new Intent().setType("image/*"), Activity.RESULT_OK,
   new Intent().setData(Uri.parse("content:foo")));
 assertThat(activity.transcript)
   .containsExactly(
     "onActivityResult called with requestCode 456, resultCode -1, intent data content:foo");
}

代码示例来源:origin: stackoverflow.com

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
try {
  activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
  ToastHelper.MakeShortText("Whatsapp have not been installed.");
}

代码示例来源:origin: stackoverflow.com

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
 getIntent.setType("image/*");
 Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 pickIntent.setType("image/*");
 Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
 chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
 startActivityForResult(chooserIntent, PICK_IMAGE);

代码示例来源:origin: stackoverflow.com

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
  "Hey check out my app at: https://play.google.com/store/apps/details?id=com.google.android.apps.plus");
sendIntent.setType("text/plain");
startActivity(sendIntent);

代码示例来源:origin: stackoverflow.com

try {
  exportRealmFile = new File(getActivity().getExternalCacheDir(), "export.realm");
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, "YOUR MAIL");
intent.putExtra(Intent.EXTRA_SUBJECT, "YOUR SUBJECT");
intent.putExtra(Intent.EXTRA_TEXT, "YOUR TEXT");
Uri u = Uri.fromFile(exportRealmFile);
intent.putExtra(Intent.EXTRA_STREAM, u);

代码示例来源:origin: TeamNewPipe/NewPipe

private void shareUrl(String subject, String url) {
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setType("text/plain");
  intent.putExtra(Intent.EXTRA_SUBJECT, subject);
  intent.putExtra(Intent.EXTRA_TEXT, url);
  startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title)));
}

相关文章

Intent类方法