使用.NET替换Uri的主机部分最好的方法是什么?
即:
string ReplaceHost(string original, string newHostName);
//...
string s = ReplaceHost("http://oldhostname/index.html", "newhostname");
Assert.AreEqual("http://newhostname/index.html", s);
//...
string s = ReplaceHost("http://user:pass@oldhostname/index.html", "newhostname");
Assert.AreEqual("http://user:pass@newhostname/index.html", s);
//...
string s = ReplaceHost("ftp://user:pass@oldhostname", "newhostname");
Assert.AreEqual("ftp://user:pass@newhostname", s);
//etc.
Run Code Online (Sandbox Code Playgroud)
System.Uri似乎没什么帮助.
我有一个用画廊和相机获得的Uris列表.这些Uris是这样的:content://media/external/images/media/94.我怎么能得到它的mime类型?
你如何正确构建一个没有该部分的mailto:link.
mailto:someaddress@example.com?
我不想要地址,只是想在之后的参数中通过mailto填写.
System.Uri有Host,Authority和DnsSafeHost.MS提供时的一个很好的例子Host,并DnsSafeHost在不同的位置.
我想要一个类似的例子/解释Host和Authority.
我在该应用程序中有图像厨房应用程序我将所有图像放入drawable-hdpi文件夹中.我在我的活动中调用了这样的图像:
private Integer[] imageIDs = {
R.drawable.wall1, R.drawable.wall2,
R.drawable.wall3, R.drawable.wall4,
R.drawable.wall5, R.drawable.wall6,
R.drawable.wall7, R.drawable.wall8,
R.drawable.wall9, R.drawable.wall10
};
Run Code Online (Sandbox Code Playgroud)
所以现在我想知道我如何使用共享Intent我分享这些图像我推出的共享代码如下:
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});
Run Code Online (Sandbox Code Playgroud)
当我点击分享按钮时我也有共享按钮分享框正在打开但当我克服任何服务时,大多数崩溃或一些服务说:无法打开图像所以我怎么能解决这个问题或者是否有任何其他格式代码来共享图像????
编辑:
我尝试使用下面的代码.但它不起作用.
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.android.test/*");
try { …Run Code Online (Sandbox Code Playgroud) If I have a URL like:
http://www.example.com:9090/test.html
Run Code Online (Sandbox Code Playgroud)
Then I know that www.example.com is the host name, but what do you call http://www.example.com:9090? Is there some kind of established name for that?
我有一个应用程序,我使用相机捕获视频.我可以获得视频的文件路径,但我需要它作为Uri.
我得到的文件路径:
/storage/emulated/0/DCIM/Camera/20141219_133139.mp4
Run Code Online (Sandbox Code Playgroud)
我需要的是这样的:
content//media/external/video/media/18576.
Run Code Online (Sandbox Code Playgroud)
这是我的代码.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// video successfully recorded
// preview the recorded video
// selectedImageUri = data.getData();
// Uri selectedImage = data.getData();
previewVideo();
tv1.setText(String.valueOf((fileUri.getPath())));
String bedroom=String.valueOf((fileUri.getPath()));
Intent i = new Intent();
i.putExtra(bhk1.BEDROOM2, bedroom);
setResult(RESULT_OK,i);
btnRecordVideo.setText("ReTake Video");
} else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),
"User cancelled video recording", …Run Code Online (Sandbox Code Playgroud) 的HttpRequest在Asp.Net 5(vNext)类包含(除其他事项外)解析有关的URL请求,诸如细节Scheme,Host,Path等.
我还没有发现任何公开原始请求URL的地方 - 只有这些解析的值.(以前的版本有Request.Uri)
我可以获取原始URL而无需将其与HttpRequest上可用的组件拼凑在一起吗?
如何检查uri字符串是否有效(您可以将其提供给Uri构造函数)?
到目前为止,我只有以下内容,但由于显而易见的原因,我更喜欢不那么粗野的方式:
Boolean IsValidUri(String uri)
{
try
{
new Uri(uri);
return true;
}
catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了Uri.IsWellFormedUriString,但它似乎并不喜欢你可以在构造函数中抛出的所有内容.例如:
String test = @"C:\File.txt";
Console.WriteLine("Uri.IsWellFormedUriString says: {0}", Uri.IsWellFormedUriString(test, UriKind.RelativeOrAbsolute));
Console.WriteLine("IsValidUri says: {0}", IsValidUri(test));
Run Code Online (Sandbox Code Playgroud)
输出将是:
Uri.IsWellFormedUriString says: False
IsValidUri says: True
Run Code Online (Sandbox Code Playgroud)
更新/应答
Uri构造函数默认使用类Absolute.当我尝试使用Uri.TryCreate和构造函数时,这导致了差异.如果匹配构造函数和TryCreate的UriKind,则会获得预期的结果.
uri ×10
.net ×3
android ×3
c# ×3
url ×2
asp.net-core ×1
c++ ×1
image ×1
mailto ×1
mime-types ×1
request ×1
share ×1
string ×1
terminology ×1