优秀网站建设最新报价,网站图片自动轮换怎么做的,wordpress 设置密码,百度seo价格查询系统目录 1、说明2、使用方法2.1 常用方法2.2 调用系统应用 3、参考资料 1、说明
在Android开发中常常会用到Intent进行不同活动启动#xff0c;整理资料如下
2、使用方法
2.1 常用方法
1、一般情况而言#xff0c;都是使用如下的方式进行调用
Intent intent new Intent(th… 目录 1、说明2、使用方法2.1 常用方法2.2 调用系统应用 3、参考资料 1、说明
在Android开发中常常会用到Intent进行不同活动启动整理资料如下
2、使用方法
2.1 常用方法
1、一般情况而言都是使用如下的方式进行调用
Intent intent new Intent(this, typeof(UpLoadService));
intent.PutExtra(serviceType, once);
StartService(intent);也存在调用第三方的情况
Intent intent new Intent(android.intent.action.MAIN);
intent.setClassName(当前Act的全限定类名,启动Act的全限定类名);
startActivity(intent);具体可参考这篇文章Android 启动一个Activity的几种方式
2、传递数组参数
//加载
var intent new Intent(this, typeof(TranslationHistoryActivity));
intent.PutStringArrayListExtra(phone_numbers, phoneNumbers);
StartActivity(intent);//获取数据---在某个Activity中获取数据
protected override void OnCreate(Bundle bundle)
{base.OnCreate(bundle);// Create your application herevar phoneNumbers Intent.Extras.GetStringArrayList(phone_numbers) ?? new string[0];this.ListAdapter new ArrayAdapterstring(this, Android.Resource.Layout.SimpleListItem1, phoneNumbers);
}3、使用Bundle传递
//加载
public static MineFragment NewInstance(MainActivity mainActivity, string employeeID,string employeeName,string loginTime)
{var frag1 new MineFragment(mainActivity);Bundle bundle new Bundle();bundle.PutString(id, employeeID);bundle.PutString (name, employeeName);bundle.PutString(loginTime, loginTime);frag1.Arguments bundle;return frag1;
}//获取时使用
string employeeID Arguments.GetString(id, );
string employeeName Arguments.GetString(name, );
string loginTime Arguments.GetString(loginTime, );4、在Activity中使用
加载数据
//加载数据
Bundle bundle new Bundle(); //得到bundle对象
bundle.putString(sff, value值); //key-sff,通过key得到value-value值(String型)
bundle.putInt(iff, 175); //key-iff,value-175
intent.putExtras(bundle); //通过intent将bundle传到另个Activity
startActivity(intent);//读取数据
Bundle bundle this.getIntent().getExtras(); //读取intent的数据给bundle对象
String str1 bundle.getString(sff); //通过key得到value
int int1 bundle.getInt(iff); 5、使用Handler
//加载数据
Message messagenew Message();//new一个Message对象
message.what MESSAGE_WHAT_2;//给消息做标记
Bundle bundle new Bundle(); //得到Bundle对象
bundle.putString(text1,消息传递参数); //往Bundle中存放数据
bundle.putInt(text2,44); //往Bundle中put数据
message.setData(bundle);//mes利用Bundle传递数据
mHandler.sendMessage(message);//Handler将消息放入消息队列//读取数据
String str1msg.getData().getString(text1);
int int1msg.getData().getString(text2);2.2 调用系统应用
有时需要调用系统的应用例如发短信、打电话之类则需要指定Action。 Intent有很多overload形式以下两种比较常用
public Intent(String action)
public Intent(String action, Uri uri) 例如拨打电话
//Java写法
Uri uri Uri.parse(tel:10086);
// 参数分别为调用拨打电话组件的Action和获取Data数据的Uri
Intent intent new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent); //Xamarin写法
var intent new Intent(Intent.ActionCall);
intent.SetData(Android.Net.Uri.Parse(tel: Intent.GetStringExtra(phoneNumber)));
StartActivity(intent);Intent调用常见系统组件有如下 // 调用浏览器
Uri webViewUri Uri.parse(http://blog.csdn.net/zuolongsnail);
Intent intent new Intent(Intent.ACTION_VIEW, webViewUri); // 调用地图
Uri mapUri Uri.parse(geo:100,100);
Intent intent new Intent(Intent.ACTION_VIEW, mapUri); // 播放mp3
Uri playUri Uri.parse(file:///sdcard/test.mp3);
Intent intent new Intent(Intent.ACTION_VIEW, playUri);
intent.setDataAndType(playUri, audio/mp3); // 调用拨打电话
Uri dialUri Uri.parse(tel:10086);
Intent intent new Intent(Intent.ACTION_DIAL, dialUri);
// 直接拨打电话需要加上权限uses-permission idandroid.permission.CALL_PHONE /
Uri callUri Uri.parse(tel:10086);
Intent intent new Intent(Intent.ACTION_CALL, callUri); // 调用发邮件这里要事先配置好的系统Email否则是调不出发邮件界面的
Uri emailUri Uri.parse(mailto:zuolongsnail163.com);
Intent intent new Intent(Intent.ACTION_SENDTO, emailUri);
// 直接发邮件
Intent intent new Intent(Intent.ACTION_SEND);
String[] tos { zuolongsnailgmail.com };
String[] ccs { zuolongsnail163.com };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, the email text);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.setType(text/plain);
Intent.createChooser(intent, Choose Email Client); // 发短信
Intent intent new Intent(Intent.ACTION_VIEW);
intent.putExtra(sms_body, the sms text);
intent.setType(vnd.android-dir/mms-sms);
// 直接发短信
Uri smsToUri Uri.parse(smsto:10086);
Intent intent new Intent(Intent.ACTION_SENDTO, smsToUri);
intent.putExtra(sms_body, the sms text);
// 发彩信
Uri mmsUri Uri.parse(content://media/external/images/media/23);
Intent intent new Intent(Intent.ACTION_SEND);
intent.putExtra(sms_body, the sms text);
intent.putExtra(Intent.EXTRA_STREAM, mmsUri);
intent.setType(image/png); // 卸载应用
Uri uninstallUri Uri.fromParts(package, com.app.test, null);
Intent intent new Intent(Intent.ACTION_DELETE, uninstallUri);
// 安装应用
Intent intent new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(/sdcard/test.apk), application/vnd.android.package-archive); // 在Android Market中查找应用
Uri uri Uri.parse(market://search?q愤怒的小鸟);
Intent intent new Intent(Intent.ACTION_VIEW, uri);
3、参考资料
1、Android应用开发中Intent的作用及使用方法 2、Android中Bundle