Пример #1
1
  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {

    EditText title = (EditText) findViewById(R.id.title);
    EditText body = (EditText) findViewById(R.id.body);

    String titleText = title.getText().toString();
    String bodyText = body.getText().toString();

    switch (item.getItemId()) {
      case EMAIL_ID:
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, titleText);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, bodyText);
        startActivity(Intent.createChooser(emailIntent, "Send your email in:"));

        return true;

      case SMS_ID:
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.putExtra("sms_body", titleText + "\n\n" + bodyText);
        sendIntent.setType("vnd.android-dir/mms-sms");
        startActivity(Intent.createChooser(sendIntent, "Send your SMS in:"));

        return true;

      case BACK_ID:
        finish();
        return true;
    }

    return super.onMenuItemSelected(featureId, item);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final PackageManager pm = getPackageManager();
    if (pm == null) {
      launchInternalPicker();
      return;
    }

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("application/zip");

    try {
      if (pm.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES).size() > 0) {
        intent = new Intent();
        intent.setType("application/zip");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, REQUEST_PICK_FILE);
      } else {
        throw new ActivityNotFoundException();
      }
    } catch (ActivityNotFoundException e) {
      Timber.e(e, "No activity found to handle file picking! Falling back to default!");
      launchInternalPicker();
    }
  }
  public Intent intentForClick(Preference pref) {
    Intent intent = null;

    // TODO The current "delete" story is not fully handled by the respective applications.
    // When it is done, make sure the intent types below are correct.
    // If that cannot be done, remove these intents.
    final String key = pref.getKey();
    if (pref == mFormatPreference) {
      intent = new Intent(Intent.ACTION_VIEW);
      intent.setClass(getContext(), com.android.settings.MediaFormat.class);
      intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolume);
    } else if (pref == mItemApps) {
      intent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE);
      intent.setClass(getContext(), com.android.settings.Settings.ManageApplicationsActivity.class);
    } else if (pref == mItemDownloads) {
      intent =
          new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)
              .putExtra(DownloadManager.INTENT_EXTRAS_SORT_BY_SIZE, true);
    } else if (pref == mItemMusic) {
      intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("audio/mp3");
    } else if (pref == mItemDcim) {
      intent = new Intent(Intent.ACTION_VIEW);
      intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
      // TODO Create a Videos category, type = vnd.android.cursor.dir/video
      intent.setType("vnd.android.cursor.dir/image");
    } else if (pref == mItemMisc) {
      Context context = getContext().getApplicationContext();
      intent = new Intent(context, MiscFilesHandler.class);
      intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolume);
    }

    return intent;
  }
 private void shareWith(Message message) {
   Intent shareIntent = new Intent();
   shareIntent.setAction(Intent.ACTION_SEND);
   if (GeoHelper.isGeoUri(message.getBody())) {
     shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody());
     shareIntent.setType("text/plain");
   } else {
     shareIntent.putExtra(
         Intent.EXTRA_STREAM,
         activity.xmppConnectionService.getFileBackend().getJingleFileUri(message));
     shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
     String mime = message.getMimeType();
     if (mime == null) {
       mime = "image/webp";
     }
     shareIntent.setType(mime);
   }
   try {
     activity.startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
   } catch (ActivityNotFoundException e) {
     // This should happen only on faulty androids because normally chooser is always available
     Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT)
         .show();
   }
 }
Пример #5
1
        @Override
        public void onClick(View v) {
          Intent intent = new Intent(RouteActivity.this, MainActivity.class);
          int requestCode = -1;
          switch (v.getId()) {
            case R.id.spinner_start:
              intent.putExtra("title", getString(R.string.choice_start));
              if (endPoint != null) {
                intent.putExtra("geoPoint", endPoint);
              }
              intent.setType(Const.TYPE_ROUTE_START);
              requestCode = Const.REQUESTCODE_ROUTE_START;
              break;
            case R.id.spinner_end:
              if (startPoint != null) {
                intent.putExtra("geoPoint", startPoint);
              }
              intent.putExtra("title", getString(R.string.choice_end));
              intent.setType(Const.TYPE_ROUTE_END);
              requestCode = Const.REQUESTCODE_ROUTE_END;
              break;

            default:
              break;
          }
          startActivityForResult(intent, requestCode);
        }
Пример #6
1
  private void share(String nameApp) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("image/jpeg");
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
    if (!resInfo.isEmpty()) {
      for (ResolveInfo info : resInfo) {
        Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
        targetedShare.setType("image/jpeg"); // put here your mime type

        try {
          if (info.activityInfo.packageName.toLowerCase().contains(nameApp)
              || info.activityInfo.name.toLowerCase().contains(nameApp)) {
            targetedShare.putExtra(Intent.EXTRA_TEXT, "My body of post/email");
            Intent i = getIntent();
            Uri myScreenshotUri = i.getParcelableExtra("screenshot");
            targetedShare.putExtra(Intent.EXTRA_STREAM, myScreenshotUri);

            targetedShare.setPackage(info.activityInfo.packageName);
            targetedShareIntents.add(targetedShare);
          }

          Intent chooserIntent =
              Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
          chooserIntent.putExtra(
              Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
          startActivity(chooserIntent);

        } catch (Exception e) {
          e.printStackTrace();
          Toast.makeText(this, "App not found on device!", Toast.LENGTH_LONG).show();
        }
      }
    }
  }
Пример #7
1
 public boolean showFileChooser(
     final String mimeType,
     final String chooserTitle,
     final boolean allowMultiple,
     final boolean mustCanRead) {
   if (mimeType == null || choosing) {
     return false;
   }
   choosing = true;
   // 檢查是否有可用的Activity
   final PackageManager packageManager = activity.getPackageManager();
   final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
   intent.setType(mimeType);
   List<ResolveInfo> list =
       packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
   if (list.size() > 0) {
     this.mustCanRead = mustCanRead;
     // 如果有可用的Activity
     Intent picker = new Intent(Intent.ACTION_GET_CONTENT);
     picker.setType(mimeType);
     picker.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
     picker.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
     // 使用Intent Chooser
     Intent destIntent = Intent.createChooser(picker, chooserTitle);
     activity.startActivityForResult(destIntent, ACTIVITY_FILE_CHOOSER);
     return true;
   } else {
     return false;
   }
 }
  /**
   * Share the provided photo through other android apps
   *
   * <p>Will share the image as a image/jpg content type and include title and description as extra
   *
   * @param slideshowPhoto
   */
  public void actionSharePhoto(SlideshowPhoto slideshowPhoto) {
    Log.i(LOG_PREFIX, "Attempting to share photo " + slideshowPhoto);
    // TODO: Refactor this code.. rather ugly due to some GoogleTV related hacks

    if (slideshowPhoto != null) {
      Intent shareIntent = new Intent();
      shareIntent.setAction(Intent.ACTION_SEND);
      // we assume the type is image/jpg
      shareIntent.setType("image/jpg");

      String sharedText =
          slideshowPhoto.getTitle()
              + ": "
              + slideshowPhoto.getDescription()
              + "\n\n"
              + getResources().getString(R.string.share_footer);

      // if we have a cached file, add the stream and the sharedText
      // if not, add the url and the sharedText
      if (slideshowPhoto.isCacheExisting(rootFileDirectory)) {
        String path =
            "file://" + rootFileDirectory.getAbsolutePath() + "/" + slideshowPhoto.getFileName();
        Log.i(LOG_PREFIX, "Attempting to pass stream url " + path);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
      } else {
        shareIntent.putExtra(
            Intent.EXTRA_TEXT, slideshowPhoto.getLargePhoto() + "\n\n" + sharedText);
      }

      shareIntent.putExtra(Intent.EXTRA_SUBJECT, slideshowPhoto.getTitle());

      // Start the actual sharing activity
      try {
        List<ResolveInfo> relevantActivities =
            getPackageManager().queryIntentActivities(shareIntent, 0);
        if (AndroidUtils.isGoogleTV(getApplicationContext())
            || relevantActivities == null
            || relevantActivities.size() == 0) {
          Log.i(
              LOG_PREFIX,
              "No activity found that can handle image/jpg. Performing simple text share");
          Intent backupShareIntent = new Intent();
          backupShareIntent.setAction(Intent.ACTION_SEND);
          backupShareIntent.setType("text/plain");
          String backupSharedText = slideshowPhoto.getLargePhoto() + "\n\n" + sharedText;
          backupShareIntent.putExtra(Intent.EXTRA_TEXT, backupSharedText);
          startActivity(backupShareIntent);
        } else {
          startActivity(shareIntent);
        }

      } catch (ActivityNotFoundException e) {
        notifyUser("Unable to share current photo");
      }

    } else {
      notifyUser("Unable to share current photo");
    }
  }
Пример #9
0
  public static Intent buildSendFile(ArrayList<FileInfo> files) {
    ArrayList<Uri> uris = new ArrayList<Uri>();

    String mimeType = "*/*";
    for (FileInfo file : files) {
      if (file.IsDir) continue;

      File fileIn = new File(file.filePath);
      mimeType = getMimeType(file.fileName);
      Uri u = Uri.fromFile(fileIn);
      uris.add(u);
    }

    if (uris.size() == 0) return null;

    boolean multiple = uris.size() > 1;
    Intent intent =
        new Intent(
            multiple
                ? android.content.Intent.ACTION_SEND_MULTIPLE
                : android.content.Intent.ACTION_SEND);

    if (multiple) {
      intent.setType("*/*");
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
      intent.setType(mimeType);
      intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
    }

    return intent;
  }
  private void startSend(
      final CharSequence subject, final CharSequence text, final ArrayList<Uri> attachments) {
    final Intent intent;

    if (attachments.size() == 0) {
      intent = new Intent(Intent.ACTION_SEND);
      intent.setType("message/rfc822");
    } else if (attachments.size() == 1) {
      intent = new Intent(Intent.ACTION_SEND);
      intent.setType("text/plain");
      intent.putExtra(Intent.EXTRA_STREAM, attachments.get(0));
    } else {
      intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
      intent.setType("text/plain");
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
    }

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {Constants.REPORT_EMAIL});
    if (subject != null) intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);

    try {
      context.startActivity(
          Intent.createChooser(
              intent, context.getString(R.string.report_issue_dialog_mail_intent_chooser)));
      log.info("invoked chooser for sending issue report");
    } catch (final Exception x) {
      Toast.makeText(context, R.string.report_issue_dialog_mail_intent_failed, Toast.LENGTH_LONG)
          .show();
      log.error("report issue failed", x);
    }
  }
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case 1:
              pb.setVisibility(4);
              isRun = false;
              image.setImageBitmap(bm);

              break;
            case 3:
              progressDialog.dismiss();
              mThread = null;
              Toast.makeText(context, "Convert Success!!", Toast.LENGTH_SHORT).show();
              File file = new File(root_Path2 + MyApplication.folder_path + ".pdf");
              Intent mailIntent = new Intent(Intent.ACTION_SEND);
              mailIntent.putExtra(Intent.EXTRA_SUBJECT, "TinyScan");
              mailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
              if (file.getName().endsWith(".gz")) {
                mailIntent.setType("application/x-gzip"); // 如果是gz使用gzip的mime
              } else if (file.getName().endsWith(".txt")) {
                mailIntent.setType("text/plain"); // 纯文本则用text/plain的mime
              } else {
                mailIntent.setType("application/octet-stream"); // 其他的均使用流当做二进制数据来发送
              }
              startActivity(Intent.createChooser(mailIntent, "Export"));
              break;
            default:
              break;
          }
          super.handleMessage(msg);
        }
Пример #12
0
 @Override
 public void onClick(final View view) {
   final Intent intent = getIntent();
   final Uri uri = intent.getData();
   final Uri orig = intent.getParcelableExtra(INTENT_KEY_URI_ORIG);
   switch (view.getId()) {
     case R.id.close:
       {
         onBackPressed();
         break;
       }
     case R.id.refresh_stop_save:
       {
         final LoaderManager lm = getSupportLoaderManager();
         if (!mImageLoaded && !lm.hasRunningLoaders()) {
           loadImage();
         } else if (!mImageLoaded && lm.hasRunningLoaders()) {
           stopLoading();
         } else if (mImageLoaded) {
           new SaveImageTask(this, mImageFile).execute();
         }
         break;
       }
     case R.id.share:
       {
         if (uri == null) {
           break;
         }
         final Intent share_intent = new Intent(Intent.ACTION_SEND);
         if (mImageFile != null && mImageFile.exists()) {
           share_intent.setType("image/*");
           share_intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile));
         } else {
           share_intent.setType("text/plain");
           share_intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
         }
         startActivity(Intent.createChooser(share_intent, getString(R.string.share)));
         break;
       }
     case R.id.open_in_browser:
       {
         final Uri uri_preferred = orig != null ? orig : uri;
         if (uri_preferred == null) return;
         final String scheme = uri_preferred.getScheme();
         if ("http".equals(scheme) || "https".equals(scheme)) {
           final Intent open_intent = new Intent(Intent.ACTION_VIEW, uri_preferred);
           open_intent.addCategory(Intent.CATEGORY_BROWSABLE);
           try {
             startActivity(open_intent);
           } catch (final ActivityNotFoundException e) {
             // Ignore.
           }
         }
         break;
       }
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
      case R.id.share:
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody =
            "Hey check swatch hubli app at playstore https://play.google.com/store/apps/details?id=practicalcoding.swatchbharat.main it was built by BVBCET students";
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Swatch bharat app");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, "Tell your friends"));
        return true;
      case R.id.like:
        Intent browserIntent =
            new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/PracticalCoding"));
        startActivity(browserIntent);
        return true;
      case R.id.rate:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=practicalcoding.swatchbharat.main"));
        startActivity(intent);
        return true;
      case R.id.feedback:
        String[] TO = {"*****@*****.**"};
        String[] CC = {
          "[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]"
        };
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setData(Uri.parse("mailto:"));
        emailIntent.setType("text/plain");

        emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
        emailIntent.putExtra(Intent.EXTRA_CC, CC);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback of Swatch Hubli app");
        emailIntent.putExtra(Intent.EXTRA_TEXT, "");

        try {
          startActivity(Intent.createChooser(emailIntent, "Send mail..."));
          finish();
          Log.i("Finished sending email...", "");
        } catch (android.content.ActivityNotFoundException ex) {
          Toast.makeText(
                  getApplicationContext(),
                  "There is no email client installed.",
                  Toast.LENGTH_SHORT)
              .show();
        }

        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
  public void addNewContact() {

    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setType("vnd.android.cursor.dir/person");
    intent.setType("vnd.android.cursor.dir/contact");
    intent.setType("vnd.android.cursor.dir/raw_contact");
    intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, phoneNum);

    this.finish();

    startActivity(intent);
  }
Пример #15
0
        @Override
        public void onClick(DialogInterface dialog, int which) {
          switch (which) {
            case 0:
              Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

              if (mMediaUri == null) {
                Toast.makeText(
                        MainActivity.this,
                        R.string.external_storage_error_message,
                        Toast.LENGTH_SHORT)
                    .show();
              } else {
                takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
              }

              break;
            case 1:
              // video
              Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
              mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
              if (mMediaUri == null) {
                Toast.makeText(
                        MainActivity.this,
                        R.string.external_storage_error_message,
                        Toast.LENGTH_SHORT)
                    .show();
              } else {
                videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
                videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                startActivityForResult(videoIntent, TAKE_VIDEO_REQUEST);
              }
              break;
            case 2:
              // choose photo
              Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
              choosePhotoIntent.setType("image/*");
              startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
              break;
            case 3:
              // choose video
              Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);
              chooseVideoIntent.setType("video/*");
              Toast.makeText(MainActivity.this, R.string.video_limit_warning, Toast.LENGTH_SHORT)
                  .show();
              startActivityForResult(chooseVideoIntent, PICK_VIDEO_REQUEST);
              break;
          }
        }
Пример #16
0
 public static void shareFood(Context context, String content, Uri uri) {
   BingLog.i("分享", "内容:" + content + "bitmap:" + uri);
   Intent shareIntent = new Intent(Intent.ACTION_SEND);
   if (uri != null) {
     shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
     shareIntent.setType("image/*");
   } else {
     shareIntent.setType("text/plain");
   }
   shareIntent.putExtra(Intent.EXTRA_TEXT, content);
   shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share)));
 }
Пример #17
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_add_category:
       FragmentTransaction ft = getFragmentManager().beginTransaction();
       ft.addToBackStack(null);
       NewCategoryDialogFragment newCategoryFragment = new NewCategoryDialogFragment();
       newCategoryFragment.show(ft, "dialog");
       return true;
     case R.id.menu_settings:
       Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
       startActivity(settingsIntent);
       return true;
     case R.id.menu_about:
       DialogFragment newFragment = AboutDialogFragment.newInstance();
       newFragment.show(getFragmentManager(), "about_dialog");
       return true;
     case R.id.menu_feedback:
       Intent myIntent = new Intent(android.content.Intent.ACTION_SEND);
       myIntent.setType("text/plain");
       myIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.menu_feedback_subject));
       myIntent.putExtra(
           Intent.EXTRA_EMAIL, new String[] {getString(R.string.menu_feedback_address)});
       startActivity(
           Intent.createChooser(
               myIntent, getResources().getString(R.string.feedback_chooser_title)));
       return true;
     case R.id.menu_share:
       Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
       shareIntent.setType("text/plain");
       shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.menu_share_subject));
       shareIntent.putExtra(
           Intent.EXTRA_TEXT, getString(R.string.menu_share_url)); // TODO: fkt. das?
       startActivity(
           Intent.createChooser(
               shareIntent, getResources().getString(R.string.feedback_chooser_title)));
       return true;
     case android.R.id.home:
       Intent intent = new Intent(getActivity().getApplicationContext(), MainActivity.class);
       MyApplication.showRunningTimers = true;
       intent.setFlags(
           Intent.FLAG_ACTIVITY_NEW_TASK
               | Intent.FLAG_ACTIVITY_SINGLE_TOP
               | Intent.FLAG_ACTIVITY_CLEAR_TOP);
       getActivity().getApplication().startActivity(intent);
       return true;
     default:
       break;
   }
   return super.onOptionsItemSelected(item);
 }
Пример #18
0
  private void goToSelectPicture(int position) {
    switch (position) {
      case ACTION_TYPE_ALBUM:
        Intent intent;
        if (Build.VERSION.SDK_INT < 19) {
          intent = new Intent();
          intent.setAction(Intent.ACTION_GET_CONTENT);
          intent.setType("image/*");
          startActivityForResult(
              Intent.createChooser(intent, "选择图片"), ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
        } else {
          intent = new Intent(Intent.ACTION_PICK, Images.Media.EXTERNAL_CONTENT_URI);
          intent.setType("image/*");
          startActivityForResult(
              Intent.createChooser(intent, "选择图片"), ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
        }
        break;
      case ACTION_TYPE_PHOTO:
        // 判断是否挂载了SD卡
        String savePath = "";
        String storageState = Environment.getExternalStorageState();
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {
          savePath =
              Environment.getExternalStorageDirectory().getAbsolutePath() + "/oschina/Camera/";
          File savedir = new File(savePath);
          if (!savedir.exists()) {
            savedir.mkdirs();
          }
        }

        // 没有挂载SD卡,无法保存文件
        if (StringUtils.isEmpty(savePath)) {
          AppContext.showToastShort("无法保存照片,请检查SD卡是否挂载");
          return;
        }

        String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String fileName = "osc_" + timeStamp + ".jpg"; // 照片命名
        File out = new File(savePath, fileName);
        Uri uri = Uri.fromFile(out);

        theLarge = savePath + fileName; // 该照片的绝对路径

        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA);
        break;
      default:
        break;
    }
  }
Пример #19
0
  /** Notes sharing */
  public void shareNote(Note note) {

    String titleText = note.getTitle();

    String contentText = titleText + System.getProperty("line.separator") + note.getContent();

    Intent shareIntent = new Intent();
    // Prepare sharing intent with only text
    if (note.getAttachmentsList().size() == 0) {
      shareIntent.setAction(Intent.ACTION_SEND);
      shareIntent.setType("text/plain");
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

      // Intent with single image attachment
    } else if (note.getAttachmentsList().size() == 1) {
      shareIntent.setAction(Intent.ACTION_SEND);
      shareIntent.setType(note.getAttachmentsList().get(0).getMime_type());
      shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri());
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

      // Intent with multiple images
    } else if (note.getAttachmentsList().size() > 1) {
      shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
      ArrayList<Uri> uris = new ArrayList<>();
      // A check to decide the mime type of attachments to share is done here
      HashMap<String, Boolean> mimeTypes = new HashMap<>();
      for (Attachment attachment : note.getAttachmentsList()) {
        uris.add(attachment.getUri());
        mimeTypes.put(attachment.getMime_type(), true);
      }
      // If many mime types are present a general type is assigned to intent
      if (mimeTypes.size() > 1) {
        shareIntent.setType("*/*");
      } else {
        shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
      }

      shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);
    }

    startActivity(
        Intent.createChooser(
            shareIntent, getResources().getString(R.string.share_message_chooser)));
  }
Пример #20
0
 private void switchToConversation(
     Conversation conversation, String text, String nick, boolean pm, boolean newTask) {
   Intent viewConversationIntent = new Intent(this, ConversationActivity.class);
   viewConversationIntent.setAction(Intent.ACTION_VIEW);
   viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid());
   if (text != null) {
     viewConversationIntent.putExtra(ConversationActivity.TEXT, text);
   }
   if (nick != null) {
     viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
     viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE, pm);
   }
   viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
   if (newTask) {
     viewConversationIntent.setFlags(
         viewConversationIntent.getFlags()
             | Intent.FLAG_ACTIVITY_NEW_TASK
             | Intent.FLAG_ACTIVITY_SINGLE_TOP);
   } else {
     viewConversationIntent.setFlags(
         viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
   }
   startActivity(viewConversationIntent);
   finish();
 }
Пример #21
0
 // COMPARTINHAMENTO (EX: ARQUIVO, TEXTO...)
 public void share() {
   Intent intent = new Intent(Intent.ACTION_SEND);
   intent.setType("text/plain");
   intent.putExtra(Intent.EXTRA_TEXT, getText(R.string.app_name) + ": " + "+titulo -link");
   startActivity(Intent.createChooser(intent, getText(R.string.action_share)));
   finish();
 }
 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   if (url.startsWith("file")) {
     // Keep local assets in this WebView.
     return false;
   } else if (url.startsWith("mailto:")) {
     try {
       MailTo mt = MailTo.parse(url);
       Intent i = new Intent(Intent.ACTION_SEND);
       i.setType("message/rfc822");
       i.putExtra(Intent.EXTRA_EMAIL, new String[] {mt.getTo()});
       i.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
       context.startActivity(i);
       view.reload();
     } catch (ActivityNotFoundException e) {
       Log.w(TAG, "Problem with Intent.ACTION_SEND", e);
       new AlertDialog.Builder(context)
           .setTitle("Contact Info")
           .setMessage("Please send your feedback to: [email protected]")
           .setPositiveButton(
               "Done",
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                   Log.d("AlertDialog", "Positive");
                 }
               })
           .show();
     }
     return true;
   } else {
     // Open external URLs in Browser.
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
     return true;
   }
 }
Пример #23
0
 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   if (url.startsWith("http")) {
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
     view.getContext().startActivity(intent);
     return true;
   }
   if (url.endsWith("prop")) {
     try {
       FileInputStream fis = new FileInputStream(new File(new URI(url)));
       Intent intent = new Intent(Intent.ACTION_SEND);
       intent.setType("text/html");
       intent.putExtra(Intent.EXTRA_TEXT, MainService.readFile(fis));
       view.getContext().startActivity(intent);
     } catch (Exception e) {
       Log.d(getClass().getName(), e.getMessage());
     }
     return true;
   }
   if (url.endsWith("zip")) {
     shareReport(view.getContext());
     return true;
   }
   return false;
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_info) {
      Intent intent = new Intent(TarotFeedbackActivity.this, AboutActivity.class);
      startActivity(intent);
      return true;
    } else if (id == R.id.action_renew) {
      updateList();
      return true;
    } else if (id == R.id.action_share) {
      Intent i = new Intent(Intent.ACTION_SEND);
      i.setType("text/plain");
      i.putExtra(
          Intent.EXTRA_TEXT,
          "https://play.google.com/store/apps/details?id=com.apex.tarot.feedback");
      startActivity(Intent.createChooser(i, "Share and spread the word"));
      return true;
    } else if (id == R.id.action_invite) {
      onInviteClicked();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
Пример #25
0
 @Override
 public void onClick(DialogInterface dialog, int which) {
   switch (which) {
     case 0: // Take photo
       Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
       if (mMediaUri == null) {
         // display an error
         Toast.makeText(
                 getApplicationContext(), // I am not sure about this getApplicationContext
                 // thing.
                 "There was a problem accessing your devices external storage",
                 Toast.LENGTH_LONG)
             .show();
       }
       takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
       startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
       break;
     case 1: // Take Choose Photo
       Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
       choosePhotoIntent.setType("image/*");
       startActivityForResult(choosePhotoIntent, CHOOSE_PHOTO_REQUEST);
       break;
   }
 }
 private void onDialogClick(NavBarButton button, int command) {
   switch (command) {
     case 0: // Set Click Action
       button.setPickLongPress(false);
       createActionDialog(button);
       break;
     case 1: // Set Long Press Action
       button.setPickLongPress(true);
       createActionDialog(button);
       break;
     case 2: // set Custom Icon
       int width = 100;
       int height = width;
       Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
       intent.setType("image/*");
       intent.putExtra("crop", "true");
       intent.putExtra("aspectX", width);
       intent.putExtra("aspectY", height);
       intent.putExtra("outputX", width);
       intent.putExtra("outputY", height);
       intent.putExtra("scale", true);
       intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFileUri());
       intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
       Log.i(TAG, "started for result, should output to: " + getTempFileUri());
       startActivityForResult(intent, REQUEST_PICK_CUSTOM_ICON);
       break;
     case 3: // Delete Button
       mButtons.remove(mPendingButton);
       mNumberofButtons--;
       break;
   }
   refreshButtons();
 }
Пример #27
0
 public void shareAddress() {
   Intent intent2 = new Intent();
   intent2.setAction(Intent.ACTION_SEND);
   intent2.setType("text/plain");
   intent2.putExtra(Intent.EXTRA_TEXT, user_address_wallet);
   startActivity(Intent.createChooser(intent2, "Share via"));
 }
 public static void shareText(Activity context, String text) {
   Intent sendIntent = new Intent();
   sendIntent.setAction(Intent.ACTION_SEND);
   sendIntent.putExtra(Intent.EXTRA_TEXT, text);
   sendIntent.setType("text/plain");
   context.startActivity(sendIntent);
 }
  public void onClickShare(View view) {
    String textToSend =
        mBufferTextView
            .getText()
            .toString(); // (mShowDataInHexFormat ? mHexSpanBuffer : mAsciiSpanBuffer).toString();

    if (textToSend != null && textToSend.length() > 0) {

      Intent sendIntent = new Intent();
      sendIntent.setAction(Intent.ACTION_SEND);
      sendIntent.putExtra(Intent.EXTRA_TEXT, textToSend);
      sendIntent.putExtra(
          Intent.EXTRA_SUBJECT,
          getString(R.string.uart_share_subject)); // subject will be used if sent to an email app
      sendIntent.setType(
          "text/*"); // Note: don't use text/plain because dropbox will not appear as destination
      // startActivity(sendIntent);
      startActivity(
          Intent.createChooser(
              sendIntent,
              getResources()
                  .getText(R.string.uart_sharechooser_title))); // Always show the app-chooser
    } else {
      new AlertDialog.Builder(this)
          .setMessage(getString(R.string.uart_share_empty))
          .setPositiveButton(android.R.string.ok, null)
          .show();
    }
  }
Пример #30
0
 /** 给朋友分享 */
 public static void gotoShare(Activity activity) {
   Intent sendIntent = new Intent();
   sendIntent.setAction(Intent.ACTION_SEND);
   sendIntent.setType("text/*");
   sendIntent.putExtra(Intent.EXTRA_TEXT, "App+,一款不错的App管理应用");
   activity.startActivity(sendIntent);
 }