首页 > 其他分享 >判断是否安装了Google地图

判断是否安装了Google地图

时间:2023-04-06 21:36:18浏览次数:44  
标签:Google return com builder 地图 Intent new intent 安装


判断是否安装了Google地图,没有弹出Dialog提示安装:

/**
	 * 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应用与外部元素互动起来


标签:Google,return,com,builder,地图,Intent,new,intent,安装
From: https://blog.51cto.com/u_5454003/6174167

相关文章

  • 地图商家电话采集,导出EXCEL
    前段时间,根据朋友的要求,开发了地图里的商家采集工具。地图商家如何导出?电话如何导出EXCEL?现在很多做销售工作的思路都开阔了,从地图上直接找商家推销。但是普遍反映一个一个从地图上翻找客户效率比较低。如何让销售人员专心去做他们擅长的业务营销呢?经过一段时间的琢磨,经过长......
  • 通过拍照或选择本地图片并剪裁图片设置成头像
    还是直接上代码importjava.io.File;importandroid.app.AlertDialog;importandroid.content.Context;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.graphics.Bitmap;importandroid.graphics.drawable.B......
  • 马尔科夫区制转移向量自回归模型,MSVAR模型,MS-VAR模型的GiveWin软件安装和操作过程
    马尔科夫区制转移向量自回归模型,MSVAR模型,MS-VAR模型的GiveWin软件安装和操作过程+MS-VAR各种图形制作(区制转换图、脉冲图、模型预测图和模型预测结果等等)+最优区制数和模型形式判断(MSI-VAR、MSM-VAR模型形式的最优选择问题,这是该模型的核心问题)。文档一共分为五部分,一是软件的安......
  • 一、docker的安装及docker-compose安装
    一.安装docker1.1安装curl-fsSLhttps://get.docker.com|bash-sdocker--mirrorAliyun#https://get.docker.com/是一个url地址,这个网址是下载docker脚本,点击这个网址就会看到一串shell脚本,ctrl+F查找mirror就可以看到2个,一个Aliyun,一个AzureChinaCloud使用上面代......
  • Hive下载安装配置
    0准备工作下载安装jdk:https://www.cnblogs.com/lgjb/p/17292890.html搭建Hadoop完全分布式集群:https://www.cnblogs.com/lgjb/p/17292835.html下载安装MySQL:https://www.cnblogs.com/lgjb/p/17293154.html1下载HiveHive官网:https://hive.apache.org/general/downloads/1.......
  • win 10系统安装DBC2000时卡死的解决方法
    在架设单机时,win10系统在安装DBC2000的时候可能会出现卡死的情况,比如安装DBC后无法在控制面板打开设置,或是设置到一半突然卡死。我相信有不少人都会遇到。遇到win10安装DBC2000时卡死的情况怎么办呢?今天飞飞就来和你分享下解决方法!当某个程序打不开或是卡死时大概率原因是因为这个......
  • 关于python安装模块之后pychram仍然提示没有安装模块的问题
    项目场景:如图所示:需要安装的包已经安装好,但是到了pycharm里就没法使用,相信很多小伙伴遇到过这个问题。原因分析:遇到这个问题的主要原因是你的电脑里安装了两个pycharm解释器,你安装后,实际上是安装到了你电脑的Python3而非pycharm解释器。解决方案:所以我们可以在pycharm里面直......
  • 【Linux】apache服务相关概念及安装
    文章目录web服务概述什么是apachehttpd工作模型apache的安装及应用1.apache的安装2.启动:3.设置开机启动:4.查看httpd的进程及端口号httpd的程序环境查看运行情况方法1:浏览器输入IP,可以查看到已经运行方法2:elinks命令测试总结web服务概述WEB服务器也称为WWW(WORLDWIDEWEB,万......
  • windows11安装wsl
    一:安装步骤1:打开电脑的搜索2:搜索框输入:powershell3:点击,自动进入窗口4:输入命令:wsl--install  二:遇到问题输入安装命令后,报错如下图:  三:解决方法控制面板--查看网络状态和任务--更改适配器设置--点击正在连接的网络--双击Internet协议版本4--输入如图2行数字即可......
  • Ubuntu 编译安装WireShark
    下载源码wgethttps://gitlab.com/wireshark/wireshark/-/archive/v3.6.12/wireshark-v3.6.12.zip你可以选择想要的版本,一般低一个最新版本比较好,资料多直接编译924ls925unzipwireshark-v3.6.12.zip926cdwireshark-v3.6.12/929clear930ls93......