/** * For Google Maps Check * * @return */ private boolean isGoogleMapsInstalled() { try { ApplicationInfo info = getPackageManager().getApplicationInfo( "com.google.android.apps.maps", 0); return true; } catch (PackageManager.NameNotFoundException e) { return false; } } private OnClickListener getGoogleMapsListener() { return new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); startActivity(intent); // Finish the activity so they can't circumvent the check finish(); } }; } public void checkGoogleMapInstalled() { if (!this.isGoogleMapsInstalled()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Install Google Map ?"); builder.setCancelable(false); builder.setPositiveButton("Install", getGoogleMapsListener()); AlertDialog dialog = builder.create(); dialog.show(); } }
判断是否安装了地图(无论什么地图)
类似这样子:
try { Uri mUri = Uri .parse("geo:31.249351,121.45905?q=上海交通大学&z=18"); intent = new Intent(Intent.ACTION_VIEW, mUri); startActivity(intent); } catch (Exception e) { // TODO: handle exception showToast("您未安装地图,不能查看!"); }
打开某一个已知程序
//打开日历 try{ intent=new Intent(); intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity")); startActivity(intent); }catch (ActivityNotFoundException e) { // TODO: handle exception Log.i("tag", "Sorry,we have not found the App."); } //打开另一个已知包名和启动类的App try{ intent=new Intent(); intent.setComponent(new ComponentName("com.ata.app","com.ata.app.LogoActivity")); startActivity(intent); }catch (ActivityNotFoundException e) { // TODO: handle exception Log.i("tag", "Sorry,we have not found the App."); }
判断服务是否运行.
/** * 判断服务是否运行. * @param context * @param className 判断的服务名字 * @return true 在运行 false 不在运行 */ public static boolean isServiceRunning(Context mContext, String className) { ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(Integer.MAX_VALUE); for(ActivityManager.RunningServiceInfo info:serviceList){ if(info.service.getClassName().equals(className)){ return true; } } return false; }
让你的Android应用与外部元素互动起来
http://blog.csdn.net/creativemobile/article/details/9673565