Java Code Examples for android.content.Intent.setType()

The following are Jave code examples for showing how to use setType() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: android-util2   File: IntentHelper.java   View Source Code Vote up 8 votes
public static void share(AppCompatActivity context, List<String> paths) {

        if (paths == null || paths.size() == 0) {
            return;
        }
        ArrayList<Uri> uris = new ArrayList<>();
        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
        intent.setType("*/*");
        for (String path : paths) {
            File file = new File(path);
            uris.add(Uri.fromFile(file));
        }
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        context.startActivity(intent);
    }
 
Example 2
Project: Paprika   File: RecipesFragment.java   View Source Code Vote up 7 votes
@Override
public void onShareClick(String sourceUrl) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, sourceUrl);
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, "Share using..."));
}
 
Example 3
Project: metacom-android   File: ChatFragment.java   View Source Code Vote up 7 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case TAKE_PHOTO:
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File f = new File(Environment.getExternalStorageDirectory() + TMP_METACOM_JPG);
            Uri uri = FileProvider.getUriForFile(getContext(), AUTHORITY_STRING, f);
            takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
            takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivityForResult(takePictureIntent, PICK_IMAGE_FROM_CAMERA);
            }
            return true;
        case FILE_EXPLORER:
            Intent intent = new Intent();
            intent.setType("*/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, getString(R.string
                            .select_file)),
                    PICK_IMAGE_FROM_EXPLORER);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 4
Project: PlusGram   File: MarkersActivity.java   View Source Code Vote up 7 votes
@Override
                public void onScanCompleted(String path, Uri uri) {
                    if (DEBUG) Log.v(TAG, "File scanned: " + path);
                    synchronized (mDrawingsToScan) {
                        if (path.equals(mPendingShareFile)) {
                            Intent sendIntent = new Intent(Intent.ACTION_SEND);
                            sendIntent.setType("image/png");
                            sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
                            startActivity(Intent.createChooser(sendIntent, "Send drawing to:"));
                            mPendingShareFile = null;
                        }
                        scanNext();
                    }


//                    if (saved) {
                        saved = false ;
                        Intent returnIntent = getIntent();
                        returnIntent.putExtra("path", path);
                        setResult(RESULT_OK, returnIntent);
                        finish();
//                    }


                }
 
Example 5
Project: Misc   File: MapLocationActivity.java   View Source Code Vote up 6 votes
/**
 * Send an SMS message using the default application.
 */
private void sendSMS() {
	try {
		Log.d(TAG, this.getClass().getSimpleName()
				+ ": sendSMS: mLatitude=" + mLatitude + " mLongitude="
				+ mLongitude);
		// Create the message
		int[] vals = getTowerValues();
		Date now = new Date();
		String msg = now + "\n";
		msg += "NID=" + mNid + " SID=" + mSid + " BID=" + mBid + "\n"
				+ String.format("%.6f", mLatitude * 1.e-6) + ","
				+ String.format("%.6f", mLongitude * 1.e-6);
		if (vals == null) {
			Utils.errMsg(this, "Cannot get tower values");
			return;
		}

		// Start the default SMS activity
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.putExtra("sms_body", msg);
		intent.setType("vnd.android-dir/mms-sms");
		startActivity(intent);
	} catch (Exception ex) {
		Utils.excMsg(this, "Error sending SMS", ex);
	}
}
 
Example 6
Project: actions   File: SendMail.java   View Source Code Vote up 6 votes
public void sending() {
    Log.d(TAG, "Sending");

    if (!validate()) {
        onSendFailed();
        return;
    }

    _sendButton.setEnabled(false);

    final ProgressDialog progressDialog = new ProgressDialog(SendMail.this,
            R.style.AppTheme_Dark_Dialog);
    progressDialog.setIndeterminate(true);
    progressDialog.setMessage("И-мэйл илгээж байна...");
    progressDialog.show();

    String from = _fromText.getText().toString();
    String to = _toText.getText().toString();
    String subject = _subjectText.getText().toString();
    String composeEmail = _composeEmailText.getText().toString();
    Intent sendingMailIntent = new Intent(Intent.ACTION_SEND);
    sendingMailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    sendingMailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendingMailIntent.putExtra(Intent.EXTRA_TEXT,composeEmail);
    sendingMailIntent.setType("message/rfc822");
    startActivity(sendingMailIntent);

    new android.os.Handler().postDelayed(
            new Runnable() {
                public void run() {
                    // On complete call either onSignupSuccess or onSignupFailed
                    // depending on success
                    onSendSuccess();
                    // onSignupFailed();
                    progressDialog.dismiss();
                }
            }, 3000);
}
 
Example 7
Project: Nimbus   File: UploadNewsFeedActivity.java   View Source Code Vote up 6 votes
private void createChooser() {
    if(ContextCompat.checkSelfPermission(UploadNewsFeedActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_DENIED){

        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
            requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 121);
        }

        return;

    }

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(Intent.createChooser(intent, "CHOOSE PHOTO"), PICK_IMAGE_REQUEST);
}
 
Example 8
Project: MyDemo   File: ShareUtil.java   View Source Code Vote up 6 votes
public static void share(Context context, String extraText) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.action_share));
    intent.putExtra(Intent.EXTRA_TEXT, extraText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(
            Intent.createChooser(intent, context.getString(R.string.action_share)));
}
 
Example 9
Project: yyox   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 调用系统安装了的应用分享
 *
 * @param context
 * @param title
 * @param url
 */
public static void showSystemShareOption(Activity context,
                                         final String title, final String url) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "分享:" + title);
    intent.putExtra(Intent.EXTRA_TEXT, title + " " + url);
    context.startActivity(Intent.createChooser(intent, "选择分享"));
}
 
Example 10
Project: IdealMedia   File: NavigationDrawerFragment.java   View Source Code Vote up 6 votes
@SuppressLint("SetJavaScriptEnabled")
private void shareTwitter() {
    Intent twitterIntent = new Intent();
    twitterIntent.setType("text/plain");
    twitterIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.like_text));

    final PackageManager packageManager = getActivity().getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(twitterIntent, PackageManager.MATCH_DEFAULT_ONLY);

    boolean found = false;
    for (ResolveInfo resolveInfo : list) {
        String p = resolveInfo.activityInfo.packageName;
        if (p != null && p.startsWith("com.twitter.android")) {
            found = true;
            twitterIntent.setPackage(p);
            startActivity(twitterIntent);

            ((NavigationActivity)getActivity()).getTracker(NavigationActivity.TrackerName.APP_TRACKER)
                    .send(new HitBuilders.EventBuilder().setCategory("Sharing").setAction("Twitter").setLabel("App").build());
        }
    }

    if (!found) {
        ProgressDialog progressDialog = new ProgressDialog(getActivity());

        TwitterShare d = new TwitterShare(
                getActivity(), progressDialog,
                "http://twitter.com/share?text=" + Uri.encode(getString(R.string.like_text_twitter)) + "&url=" + Uri.parse(getString(R.string.like_url)));
        d.show();

        progressDialog.setMessage(getString(R.string.text_loading));
        progressDialog.setCancelable(true);
        progressDialog.show();

        ((NavigationActivity)getActivity()).getTracker(NavigationActivity.TrackerName.APP_TRACKER)
                .send(new HitBuilders.EventBuilder().setCategory("Sharing").setAction("Twitter").setLabel("Web").build());
    }
}
 
Example 11
Project: Mybilibili   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * 从手机相册选择图片设置用户头像
 */
private void choseHeadImageFromGallery() {
    Intent intentFromGallery = new Intent();
    //设置文件类型
    intentFromGallery.setType("image/*");
    intentFromGallery.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intentFromGallery,CODE_GALLERY_REQUEST);
}
 
Example 12
Project: BaseCore   File: LocalShareUtils.java   View Source Code Vote up 6 votes
/**
 * 分享文字至所有第三方软件
 *
 * @param context
 * @param content
 */
public static void ShareText(Context context, String content) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, content);
    intent.setType("text/plain");
    //设置分享列表的标题,并且每次都显示分享列表
    context.startActivity(Intent.createChooser(intent, "分享到"));

}
 
Example 13
Project: boohee_v5.6   File: BrowserActivity.java   View Source Code Vote up 6 votes
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
    BrowserActivity.this.mUploadMessage = uploadMsg;
    Intent i = new Intent("android.intent.action.GET_CONTENT");
    i.addCategory("android.intent.category.OPENABLE");
    i.setType("*/*");
    BrowserActivity.this.startActivityForResult(Intent.createChooser(i, "File Browser"), 1);
}
 
Example 14
Project: MyFire   File: OnekeyShareThemeImpl.java   View Source Code Vote up 6 votes
/** 判断指定平台是否只能使用客户端分享 */
final boolean isUseClientToShare(Platform platform) {
	String name = platform.getName();
	if ("Wechat".equals(name) || "WechatMoments".equals(name)
			|| "WechatFavorite".equals(name) || "ShortMessage".equals(name)
			|| "Email".equals(name) || "GooglePlus".equals(name)
			|| "QQ".equals(name) || "Pinterest".equals(name)
			|| "Instagram".equals(name) || "Yixin".equals(name)
			|| "YixinMoments".equals(name) || "QZone".equals(name)
			|| "Mingdao".equals(name) || "Line".equals(name)
			|| "KakaoStory".equals(name) || "KakaoTalk".equals(name)
			|| "Bluetooth".equals(name) || "WhatsApp".equals(name)
			|| "BaiduTieba".equals(name) || "Laiwang".equals(name)
			|| "LaiwangMoments".equals(name) || "Alipay".equals(name)
			|| "FacebookMessenger".equals(name)
			) {
		return true;
	} else if ("Evernote".equals(name)) {
		if ("true".equals(platform.getDevinfo("ShareByAppClient"))) {
			return true;
		}
	} else if ("SinaWeibo".equals(name)) {
		if ("true".equals(platform.getDevinfo("ShareByAppClient"))) {
			Intent test = new Intent(Intent.ACTION_SEND);
			test.setPackage("com.sina.weibo");
			test.setType("image/*");
			ResolveInfo ri = platform.getContext().getPackageManager().resolveActivity(test, 0);
			return (ri != null);
		}
	}

	return false;
}
 
Example 15
Project: codedemos   File: CameraUtilActivity.java   View Source Code Vote up 6 votes
/**
 * open camera (need permission)
 */
void gotoPhoto() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent, REQUEST_CODE_PHOTO);
}
 
Example 16
Project: boohee_v5.6   File: BrowserActivity.java   View Source Code Vote up 6 votes
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String
        capture) {
    BrowserActivity.this.mUploadMessage = uploadMsg;
    Intent i = new Intent("android.intent.action.GET_CONTENT");
    i.addCategory("android.intent.category.OPENABLE");
    i.setType("image/*");
    BrowserActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), 1);
}
 
Example 17
Project: text_converter   File: ShareUtil.java   View Source Code Vote up 6 votes
public static void shareApp(Activity context, String appId) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    String url = String.format("http://play.google.com/store/apps/details?id=%s", appId);
    intent.putExtra(Intent.EXTRA_TEXT, url);
    intent.setType("text/plain");
    context.startActivity(intent);
}
 
Example 18
Project: Cable-Android   File: ConversationFragment.java   View Source Code Vote up 6 votes
private void handleForwardMessage(MessageRecord message) {
  Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
  composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString());
  if (message.isMms()) {
    MediaMmsMessageRecord mediaMessage = (MediaMmsMessageRecord) message;
    if (mediaMessage.containsMediaSlide()) {
      Slide slide = mediaMessage.getSlideDeck().getSlides().get(0);
      composeIntent.putExtra(Intent.EXTRA_STREAM, slide.getUri());
      composeIntent.setType(slide.getContentType());
    }
  }
  startActivity(composeIntent);
}
 
Example 19
Project: CSipSimple   File: CollectLogs.java   View Source Code Vote up 5 votes
public static Intent getLogReportIntent(String userComment, Context ctx) {
	LogResult logs = getLogs(ctx);
	
	
	Intent sendIntent = new Intent(Intent.ACTION_SEND);
       sendIntent.putExtra(Intent.EXTRA_SUBJECT, "CSipSimple Error-Log report");
       sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CustomDistribution.getSupportEmail() });
       
       
       
       StringBuilder log = new StringBuilder();
       log.append(userComment);
       log.append(LINE_SEPARATOR);
       log.append(LINE_SEPARATOR);
       log.append(getApplicationInfo(ctx));
       log.append(LINE_SEPARATOR);
       log.append(getDeviceInfo());
       log.append(LINE_SEPARATOR);
       log.append(logs.head);
       

       if(logs.file != null) {
       	sendIntent.putExtra( Intent.EXTRA_STREAM, Uri.fromFile(logs.file) );
       	/*
       	BufferedReader buf;
		String line;
		try {
			buf = new BufferedReader(new FileReader(logs.second));
		
			while( (line = buf.readLine()) != null ) {
				 log.append(line);
			}
		
		} catch (FileNotFoundException e) {
			Log.e(THIS_FILE, "Impossible to open log file", e);
		} catch (IOException e) {
			Log.e(THIS_FILE, "Impossible to read log file", e);
		}
		*/
       }
       

       log.append(LINE_SEPARATOR);
       log.append(LINE_SEPARATOR);
       log.append(userComment);
       
       sendIntent.setType("message/rfc822");
       
       sendIntent.putExtra(Intent.EXTRA_TEXT, log.toString());
       
       return sendIntent;
}
 
Example 20
Project: CodeCompilerApp   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (fileOpened && searchResult != null) {
        MenuItem imReplace = menu.findItem(R.id.im_replace);
        MenuItem imReplaceAll = menu.findItem(R.id.im_replace_all);
        MenuItem imPrev = menu.findItem(R.id.im_previous_item);
        MenuItem imNext = menu.findItem(R.id.im_next_item);

        if (imReplace != null)
            imReplace.setVisible(searchResult.canReplaceSomething());

        if (imReplaceAll != null)
            imReplaceAll.setVisible(searchResult.canReplaceSomething());

        if (imPrev != null)
            imPrev.setVisible(searchResult.hasPrevious());

        if (imNext != null)
            imNext.setVisible(searchResult.hasNext());


    } else if (fileOpened) {
        MenuItem imSave = menu.findItem(R.id.im_save);
        MenuItem imUndo = menu.findItem(R.id.im_undo);
        MenuItem imRedo = menu.findItem(R.id.im_redo);

        if (mEditor != null) {
            if (imSave != null)
                imSave.setVisible(mEditor.canSaveFile());
            if (imUndo != null)
                imUndo.setVisible(mEditor.getCanUndo());
            if (imRedo != null)
                imRedo.setVisible(mEditor.getCanRedo());
        } else {
            imSave.setVisible(false);
            imUndo.setVisible(false);
            imRedo.setVisible(false);
        }

        MenuItem imMarkdown = menu.findItem(R.id.im_view_markdown);
        boolean isMarkdown = Arrays.asList(MimeTypes.MIME_MARKDOWN).contains(FilenameUtils.getExtension(greatUri.getFileName()));
        if (imMarkdown != null)
            imMarkdown.setVisible(isMarkdown);

        MenuItem imShare = menu.findItem(R.id.im_share);
        if (imMarkdown != null) {
            ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat
                    .getActionProvider(imShare);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, greatUri.getUri());
            shareIntent.setType("text/plain");
            shareAction.setShareIntent(shareIntent);
        }
    }

    MenuItem imDonate = menu.findItem(R.id.im_donate);
    if (imDonate != null)
        if (ProCheckUtils.isPro(this, false))
            imDonate.setVisible(false);

    return true;
}