android与其他应用的交互
使用隐式的Intent Implicit Intents一般用于从一个app到另一个app
而显示的Intent是用于一个app内页面的跳转
需要声明指定的动作
如Uri number = Uri.parse(“tel:5551234”);
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
指定电话号码的intent
// Map point based on address
Uri location = Uri.parse(“geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California”);
// Or map point based on latitude/longitude
// Uri location = Uri.parse(“geo:37.422219,-122.08364?z=14”); // z param is zoom level
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
查看地图
Uri webpage = Uri.parse(“http://www.android.com“);
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
查看网页
没有Uri数据类型则用setType()方法来指定intent附带的数据类型,用putextra()来装在mime型数据
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// The intent does not have a URI, so declare the “text/plain” MIME type
emailIntent.setType(HTTP.PLAIN_TEXT_TYPE);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {“jon@example.com”}); // recipients
emailIntent.putExtra(Intent.EXTRA_SUBJECT, “Email subject”);
emailIntent.putExtra(Intent.EXTRA_TEXT, “Email message text”);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(“content://path/to/email/attachment”));
// You can also attach multiple items by passing an ArrayList of Uris
验证是否有App去接收这个Intent
PackageManager packageManager = getPackageManager();
List activities = packageManager.queryIntentActivities(mapIntent, 0);
boolean isIntentSafe = activities.size() > 0;
// Start an activity if it's safe if (isIntentSafe) { startActivity(mapIntent); }
更多相关文章
- Android(安卓)Gradle 插件版本说明 以及 gradle插件版本和gradle
- android学习笔记22:可展开的ListView
- android 指定组件的圆角图片处理
- Android用于提示等待的ProgressDialog
- Android(安卓)获取sdcard音乐文件
- Android(安卓)RecyclerView更新某条/一条数据
- Android的 EditText的inputType类型
- AndroidManifest.xml里加入不同package的component
- 安卓利用百度api定位遇到 经纬度经纬度返回4.9E-324