Intent
Intent分为显示和隐式intent;
显示intent:commponent+extra
隐式intent:Action+Data(uri、mimetype)+category
下面是隐式intent代码示例
button.Click+=delegate{
Intent intent=new Intent();
intent.SetAction(Intent.ActionDial);
//拨电话,前提需要设置应用程序Call权限
Android.Net.Uri uriTel=Android.Net.Uri.Parse("tel:110");
intent.SetData(uriTel);
/*
//启动一个应用
intent.SetAction(Intent.ActionMain);
//启动浏览器
intent.AddCategory(Intent.CategoryAppBrowser);
//回到桌面
intent.AddCategory(Intent.CateogroyHome);;
*/
StartAcitivity(intent);
}
自定义可以通过隐式intent启动的在activity
[IntentFilter(new string[]{"com.itlead.action1"},
Categories=new string[]{"com.itlead.category1",intent.CategoryDefault})]
//Intent启动
intent.AddAction("com.itlead.action1"});
intent.AddCategory(“com.itlead.category1");
还可以访问其他应用的action,只要知道相应的action
Android.Net.Uri fileUri=Android.Net.Uri.Parse("file:///mnt/sdcard/ttt.mp3");
//设定Mimetype
intent.SetAction(Intent.ActionView);
intent.SetDataAndType(fileUri,"audio/mpeg");
读取SDCard权限
Mount_UNMOUNT_FILESYSTEMS
WRITE_EXTERNAL_STORAGE
intent.SetAction(Android.Provider.MediaStore.ActionImageCapture);
Java.IO.File sdPath=Android.OS.Environment.ExternalStorageDirectory;
Java.IO.File imagefile=new Java.IO.File(sdPath.AbsolutePath,"1.jpeg");
imguri=Android.Net.Uri.FromFile(imagefile);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput,imguri);
StartActivityForResult(intent,2);
Android.Net.Uri imguri;
protected override void OnActivityResult(int requestCode,[GeneratedEnum] Result resoult)
{
if(requestCode==2 && result==Result.Ok)
{
ImageView iv=FindViewById<ImageView>(Resource.Id.imageView1);
iv.SetImageURI(imguri);
}
base.OnactivityResult(requestCode,result,data);
}