Android中检查、设置默认程序详解
Android作为一个伟大的系统,自然提供了设置默认打开程序的实现.在这篇文章中,我会介绍如何在Android系统中设置默认的程序.在设置默认程序之前,无非有两种情况,一种是已经有默认的程序,另一种则是没有任何默认程序.
检测是否有默认的程序
检查是必须的,因为结果关乎着我们下一步该怎么做.
publicvoidtestGetDefaultActivity(){
PackageManagerpm=mContext.getPackageManager();
Intentintent=newIntent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
ResolveInfoinfo=pm.resolveActivity(intent,PackageManager.MATCH_DEFAULT_ONLY);
Log.i(VIEW_LOG_TAG,"getDefaultActivityinfo="+info+";pkgName="+info.activityInfo.packageName);
}
其对应的日志输出如下
I/View (1145):ViewgetDefaultActivityinfo=ResolveInfo{410e4868com.android.internal.app.ResolverActivityp=0o=0m=0x0};pkgName=android