Android notify users when app version is updated on play store .

1 . First get current play store version.

int currentVersion,updateVersion;
VersionChecker versionChecker = new VersionChecker();
try {
String latestVersion = versionChecker.execute().get();
updateVersion = Integer.parseInt(latestVersion.substring(latestVersion.length()-1));
Toast.makeText(HomeActivity.this, latestVersion.toString(), Toast.LENGTH_SHORT).show();

} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}


PackageManager manager = this.getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(this.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

2. Get current app version with PackageManager .

PackageManager manager = this.getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(this.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
// Toast.makeText(this,
// "PackageName = " + info.packageName + "\nVersionCode = "
// + info.versionCode + "\nVersionName = "
// + info.versionName + "\nPermissions = " + info.permissions, Toast.LENGTH_SHORT).show();

currentVersion = info.versionCode;

3. Check if play store version is greater or not .

if (currentVersion<updateVersion){
updateAlert();
}

4. If greater show an alert dialog to download update version .

public void updateAlert(){


AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("There has an updated version on play store , update now ");
alertDialogBuilder.setPositiveButton("Update",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {


String url = "https://play.google.com/store/apps/details?id=coinatmfinder.com.app.android";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);


}
});

alertDialogBuilder.setNegativeButton("Later",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {


dialog.dismiss();


}
});

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}


 

Swift 3 / 4 get current location with location manager .

Step – 1 : 

First define LocationManager . And Current location of CLLocaion .

 

var manager = CLLocationManager()

var currentLocation: CLLocation!

Step 2 :
In ViewDidController get Current location with location manager . That’s it .

  manager.requestWhenInUseAuthorization()

        

        if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||

            CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){

            currentLocation = manager.location

            print("location is ", currentLocation.coordinate.latitude)

            print("location is ", currentLocation.coordinate.longitude)

            

            lat = currentLocation.coordinate.latitude

            lon = currentLocation.coordinate.longitude

            

            

        }

        

Here the complete code –

   var manager = CLLocationManager()

    var currentLocation: CLLocation!

      override func viewDidLoad() {

        super.viewDidLoad()

            manager.requestWhenInUseAuthorization()

          if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||

            CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){

            currentLocation = manager.location

            print("location is ", currentLocation.coordinate.latitude)

            print("location is ", currentLocation.coordinate.longitude)

            

            lat = currentLocation.coordinate.latitude

            lon = currentLocation.coordinate.longitude

            

            

        }

}



Swift 3 /4 take photo from camera or gallery and show it .

Step One : First create a project and take imageView and a button to capture image . Connect it to ViewController .

Step Two : Copy this code and run . hope it will be done . 😀



   class ImageCapture: UIViewControllerUIImagePickerControllerDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate{



     @IBOutlet var imageViewWeight: UIImageView!

     var imagePicker:UIImagePickerController?=UIImagePickerController()

override func viewDidLoad() {

        super.viewDidLoad()

         imagePicker?.delegate=self

    }

    



@IBAction func takeImage(_ sender: Any) {

      var alert = UIAlertController(title: "Choose type" , message: "Select image" , preferredStyle: .actionSheet);

      var photos = UIAlertAction(title : "Camera" , style: .default , handler: { (alert: UIAlertAction ) in

          self.openCamera()

    })

        var videos = UIAlertAction(title : "Gallery" , style: .default , handler: { (alert: UIAlertAction ) in

           self.openGallery()

      })

        

        var cancel = UIAlertAction(title : "Calcel" , style: .default , handler: nil)

        alert.addAction(photos)

        alert.addAction(videos)

        alert.addAction(cancel)

        present(alert, animated: true , completion: nil)

    }

 func openCamera () {

        

        if UIImagePickerController.isSourceTypeAvailable(.camera){

            imagePicker?.delegate = self

            imagePicker?.sourceType = .camera;

            imagePicker?.allowsEditing = true

            imagePicker?.mediaTypes = ["public.image"]

            

            self.present(imagePicker!, animated: true, completion: nil)

            

        }else{

            print("Camera not awailable")

        }

   }

    

    func openGallery() {

        

        if UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum){

            imagePicker?.delegate = self

            imagePicker?.sourceType = .savedPhotosAlbum;

            imagePicker?.allowsEditing = true

            imagePicker?.mediaTypes = ["public.image","public.movie"]

            self.present(imagePicker!, animated: true, completion: nil)

        }

      }

   func textFieldShouldReturn(_ textField: UITextField) -> Bool {

        self.view.endEditing(true)

        return false

    }

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {

        self.dismiss(animated: true, completion: { () -> Void in

            

        })

        

    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])

    {

       imageViewWeight.image = info[UIImagePickerControllerOriginalImage] as? UIImage

        picker.dismiss(animated: true, completion: nil)
  }
}