Adding search box on map with google api android

936 views Asked by At

I already add the search box and everything works well on every device with google maps installed, but when I try in a device with no google maps installed on it, the function doesn't work. I'm confused and try to add a waze deep links just in case if the device doesn't have google maps app so it might have waze. But waze deep link only works to direct to waze app. Any ideas or solution? I'm kinda confused cause not all Android device install google maps

1

There are 1 answers

2
user10384418 On

hey Iganov you are right not all Android device install google maps. So you can check if the device is installed the maps application then only enable your search filed to work. so you can create function to check as below

boolean GoogleMaps(String apk) {
 PackageManager pm = getPackageManager();
 try {
   pm.getPackageInfo(apk, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
    }

     return false;
   }

then you can call it in your on create activity as below

boolean appavialble = GoogleMaps("com.check.application");  

if(appavialble ) {
 //do your searching condition here         

 } else {
  //application not found force to download it or show alert 

  Uri.Builder uriBuilder = null;
 try {
    Intent intent = new Intent(Intent.ACTION_VIEW);
     uriBuilder = 
     Uri.parse("market://details").buildUpon().appendQueryParameter("id", 
      "com.check.application");
      intent.setData(uriBuilder.build());
         startActivity(intent);

      }catch (Exception e){

       system.out.println("error in connection");
    }


 }

Hope this helps.