我要做 Android 第四弹 ps(Q:如何启动其他应用的Activity?)
一、打开第三方应用
(1)
Intent intent=new Intent(); //包名 包名+类名(全路径) intent.setClassName("com.jack", "com.jack.PlaneActivity"); startActivity(intent);
(2)
Intent intent = new Intent(); ComponentName comp = new ComponentName("com.jack","com.jack.PlaneActivity"); intent.setComponent(comp); intent.setAction("android.intent.action.MAIN"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
(3)转载自https://blog.csdn.net/aaa111/article/details/41833189
public static final String APP_PACKAGE_NAME = "com.*.*";//包名 /** * 启动薄荷App * @param context */ public static void launchapp(Context context) { // 判断是否安装过App,否则去市场下载 if (isAppInstalled(context, APP_PACKAGE_NAME)) { context.startActivity(context.getPackageManager().getLaunchIntentForPackage(APP_PACKAGE_NAME)); } else { goToMarket(context, APP_PACKAGE_NAME); } } /** * 检测某个应用是否安装 * * @param context * @param packageName * @return */ public static boolean isAppInstalled(Context context, String packageName) { try { context.getPackageManager().getPackageInfo(packageName, 0); return true; } catch (NameNotFoundException e) { return false; } } /** * 去市场下载页面 */ public static void goToMarket(Context context, String packageName) { Uri uri = Uri.parse("market://details?id=" + packageName); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); try { context.startActivity(goToMarket); } catch (ActivityNotFoundException e) { } }
调用系统应用
(1)从 google 搜索内容
Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, "搜索内容") startActivity(intent);
(2)浏览网页
Uri uri = Uri.parse("http://www.google.com"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
(3)显示地图
Uri uri = Uri.parse("geo:38.899533,-77.036476"); Intent it = newIntent(Intent.Action_VIEW,uri); startActivity(it);
(4)拨打电话
Uri uri =Uri.parse("tel:xxxxxx"); Intent it = new Intent(Intent.ACTION_DIAL,uri); startActivity(it);
(5)发短信
//方法1: Intent it = newIntent(Intent.ACTION_VIEW); it.putExtra("sms_body", "TheSMS text"); it.setType("vnd.android-dir/mms-sms"); startActivity(it); //方法2: Uri uri =Uri.parse("smsto:0800000123"); Intent it = newIntent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", "TheSMS text"); startActivity(it); //方法三: String body="this is sms demo"; Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null)); mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body); mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true); mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true); startActivity(mmsintent);
(6)发 Email
Uri uri = Uri.parse("mailto:xxx@abc.com"); Intent it = newIntent(Intent.ACTION_SENDTO, uri); startActivity(it); Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com"); it.putExtra(Intent.EXTRA_TEXT, "Theemail body text"); it.setType("text/plain"); startActivity(Intent.createChooser(it,"Choose Email Client")); Intent it=new Intent(Intent.ACTION_SEND); String[] tos={"me@abc.com"}; String[]ccs={"you@abc.com"}; it.putExtra(Intent.EXTRA_EMAIL, tos); it.putExtra(Intent.EXTRA_CC, ccs); it.putExtra(Intent.EXTRA_TEXT, "Theemail body text"); it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text"); it.setType("message/rfc822"); startActivity(Intent.createChooser(it,"Choose Email Client")); Intent it = newIntent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text"); it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3"); sendIntent.setType("audio/mp3"); startActivity(Intent.createChooser(it,"Choose Email Client"));
(7)播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW); Uri uri =Uri.parse("file:///sdcard/song.mp3"); it.setDataAndType(uri,"audio/mp3"); startActivity(it); Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it);
(8)卸载 apk
Uri uri =Uri.fromParts("package", strPackageName, null); Intent it = newIntent(Intent.ACTION_DELETE, uri); startActivity(it);
(9)安装 apk
Uri installUri = Uri.fromParts("package","xxx", null); returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + filepath),"application/vnd.android.package-archive"); startActivity(intent);// 安装
(10)显示应用详细列表
Uri uri =Uri.parse("market://details?id=app_id"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it); //where app_id is the application ID, findthe ID //by clicking on your application on Markethome //page, and notice the ID from the addressbar //发现用package name也可以 //Uri uri =Uri.parse("market://details?id=<packagename>");
(11)寻找应用
Uri uri =Uri.parse("market://search?q=pname:pkg_name"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it); //where pkg_name is the full package pathfor an application
(12)打开联系人列表
//1 Intent i = new Intent(); i.setAction(Intent.ACTION_GET_CONTENT); i.setType("vnd.android.cursor.item/phone"); startActivityForResult(i, REQUEST_TEXT); //2 Uri uri = Uri.parse("content://contacts/people"); Intent it = new Intent(Intent.ACTION_PICK, uri); startActivityForResult(it, REQUEST_TEXT);
这篇文章是转载的,出处在这 https://blog.csdn.net/aaa111/article/details/41833189,随着 Android 版本的提高,权限也有很多的变化,所以可能会有一些方法不能使用,不过这里可以作为参考。也算是弥补了以下基本知识。再说了,记不得 Google 不就 OK 了是吧。
愿我们成为真实的自己。

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
我要做 Android 之启动模式
Q:如何避免配置改变时Activity重建? 这些部分都要归并到 Activity 异常情况下的生命周期分析情况。 一:由于资源相关配置发生改变,导致 Activity 被杀死或重新创建 例如屏幕发生旋转:横竖屏切换的时候,系统会自动调用 onSaveInstanceState 来保存切换时的数据,接着销毁当前的 Activity,然后重新创建一个 Activity,在调用 onRestoreInstanceState 恢复数据。 onSaveInstanceState --> onPause(不定)--> onStop --> onDestroy --> onCreate --> onStart --> onRestoreInstanceState --> onResume 为了避免由于配置改变导致Activity重建,可在 AndroidManifest.xml 中对应的 Activity 中设置android:configChanges="orientation|keyboardHidden|screenSize"。此时再次旋转屏幕时,该...
- 下一篇
Android 坐标总结
写这篇文章的原因是因为坐标遇到的坑太多了,所以要记录一下。 一.基本的坐标与获取 先来看看基本的一些内容。 假如一个屏幕的区域是这样,蓝色的那条叫状态栏(statusBar),下面橙色的那条叫导航(NavigationBar),中间绿色的是应用区域。标题栏是应用区域里面的,因为现在很多都是用到自定义的标题栏而不是系统的标题栏,所以这里不介绍。 1.获取整个屏幕的宽高 整个屏幕的宽高指的是蓝色、绿色加起来的部分。(注意不算橙色部分) WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight(); 2.获取状态栏高度 蓝色那栏状态栏 public float getStatusBarHeight() { int height = 0; try { Resources resources = application...
相关文章
文章评论
共有0条评论来说两句吧...