Intent用法实例


1.无参数Activity跳转
Intentit=newIntent(Activity.Main.this,Activity2.class);
startActivity(it);


2.向下一个Activity传递数据(使用Bundle和Intent.putExtras)
Intentit=newIntent(Activity.Main.this,Activity2.class);
Bundlebundle=newBundle();
bundle.putString("name","ThisisfromMainActivity!");
it.putExtras(bundle);//it.putExtra(“test”,"shuju”);
startActivity(it);//startActivityForResult(it,REQUEST_CODE);
对于数据的获取可以采用:
Bundlebundle=getIntent().getExtras();Stringname=bundle.getString("name");


3.向上一个Activity返回结果(使用setResult,针对startActivityForResult(it,REQUEST_CODE)启动的Activity)
Intentintent=getIntent();
Bundlebundle2=newBundle();
bundle2.putString("name","ThisisfromShowMsg!");
intent.putExtras(bundle2);
setResult(RESULT_OK,intent);


4.回调上一个Activity的结果处理函数(onActivityResult)
@Override

protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
//TODOAuto-generatedmethodstub
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==REQUEST_CODE){
if(resultCode==RESULT_CANCELED)
setTitle("cancle");
elseif(resultCode==RESULT_OK){
Stringtemp=null;
Bundlebundle=data.getExtras();
if(bundle!=null)temp=bundle.getString("name");
setTitle(temp);
}
}
}

显示网页
1.Uriuri=Uri.parse("http://google.com");
2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
3.startActivity(it);


显示地图
1.Uriuri=Uri.parse("geo:38.899533,-77.036476");
2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
3.startActivity(it);
4.//其他geoURI範例
5.//geo:latitude,longitude
6.//geo:latitude,longitude?z=zoom
7.//geo:0,0?q=my+street+address
8.//geo:0,0?q=business+near+city
9.//google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom


路径规划
1.Uriuri=Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
3.startActivity(it);
4.//wherestartLat,startLng,endLat,endLngarealongwith6decimalslike:50.123456


打电话
1.//叫出拨号程序
2.Uriuri=Uri.parse("tel:0800000123");
3.Intentit=newIntent(Intent.ACTION_DIAL,uri);
4.startActivity(it);
1.//直接打电话出去
2.Uriuri=Uri.parse("tel:0800000123");
3.Intentit=newIntent(Intent.ACTION_CALL,uri);
4.startActivity(it);
5.//用這個,要在AndroidManifest.xml中,加上
6.//<uses-permissionid="android.permission.CALL_PHONE"/>


传送SMS/MMS
1.//调用短信程序
2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
3.it.putExtra("sms_body","TheSMStext");
4.it.setType("vnd.android-dir/mms-sms");
5.startActivity(it);
1.//传送消息
2.Uriuri=Uri.parse("smsto://0800000123");
3.Intentit=newIntent(Intent.ACTION_SENDTO,uri);
4.it.putExtra("sms_body","TheSMStext");
5.startActivity(it);
1.//传送MMS
2.Uriuri=Uri.parse("content://media/external/images/media/23");
3.Intentit=newIntent(Intent.ACTION_SEND);
4.it.putExtra("sms_body","sometext");
5.it.putExtra(Intent.EXTRA_STREAM,uri);
6.it.setType("image/png");
7.startActivity(it);


传送Email
1.Uriuri=Uri.parse("mailto:[email protected]");
2.Intentit=newIntent(Intent.ACTION_SENDTO,uri);
3.startActivity(it);
1.Intentit=newIntent(Intent.ACTION_SEND);
2.it.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
3.it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
4.it.setType("text/plain");
5.startActivity(Intent.createChooser(it,"ChooseEmailClient"));
1.Intentit=newIntent(Intent.ACTION_SEND);
2.String[]tos={"[email protected]"};
3.String[]ccs={"[email protected]"};
4.it.putExtra(Intent.EXTRA_EMAIL,tos);
5.it.putExtra(Intent.EXTRA_CC,ccs);
6.it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
7.it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
8.it.setType("message/rfc822");
9.startActivity(Intent.createChooser(it,"ChooseEmailClient"));
1.//传送附件
2.Intentit=newIntent(Intent.ACTION_SEND);
3.it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
4.it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
5.sendIntent.setType("audio/mp3");
6.startActivity(Intent.createChooser(it,"ChooseEmailClient"));


播放多媒体
Uriuri=Uri.parse("file:///sdcard/song.mp3");
Intentit=newIntent(Intent.ACTION_VIEW,uri);
it.setType("audio/mp3");
startActivity(it);
Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
Intentit=newIntent(Intent.ACTION_VIEW,uri);
startActivity(it);


Market相关
1.//寻找某个应用
2.Uriuri=Uri.parse("market://search?q=pname:pkg_name");
3.Intentit=newIntent(Intent.ACTION_VIEW,uri);
4.startActivity(it);
5.//wherepkg_nameisthefullpackagepathforanapplication
1.//显示某个应用的相关信息
2.Uriuri=Uri.parse("market://details?id=app_id");
3.Intentit=newIntent(Intent.ACTION_VIEW,uri);
4.startActivity(it);
5.//whereapp_idistheapplicationID,findtheID
6.//byclickingonyourapplicationonMarkethome
7.//page,andnoticetheIDfromtheaddressbar
Uninstall应用程序
1.Uriuri=Uri.fromParts("package",strPackageName,null);
2.Intentit=newIntent(Intent.ACTION_DELETE,uri);
3.startActivity(it);

更多相关文章

  1. Android中安全退出程序的六种方法
  2. Android(3) 注册界面点击返回登录界面并传值
  3. Android应用程序组件Content Provider应用实例(4)
  4. Android从App跳转到微信小程序,无需微信SDK,防止友盟冲突
  5. Android(安卓)开发(二) Android(安卓)Permission 中英文对照
  6. Android(安卓)SDK 1.0 电话号码的例子(Demo)
  7. Android(安卓)Native 应用程序启动 Activity 的方法
  8. 使用RecyclerView加载不出数据的原因可能有:
  9. android获取应用列表

随机推荐

  1. 使用手机调试Android软件
  2. Android(安卓)launcher -- launcher源码
  3. 【android】解决在图库中缩略图与实际图
  4. android AIDL通信
  5. android
  6. Android(安卓)应用语言设置的实现
  7. Android下载网络文本
  8. 大家一起讨论简称论-关于简单Selector的
  9. Android启动过程
  10. Android(安卓)网络通信框架Volley简介(Go