4

I have an android application that needs google play services. Is there a option to put code inside my application to download and install google play services automatically if missing. I don't want users to download and install google play services separately and then install my application instead want to install both in a single go. Please let me know.

Thanks, Rajeev

rajeevraj33
  • 61
  • 1
  • 4
  • 3
    No, you cannot. An app cannot automatically install another app. Plus, to install your app, the users would need to get it from the play store, which means they must already have google play services installed. – Aleks G May 14 '14 at 14:59

2 Answers2

2

I think the correct way to do it is checking if the services are enable from within your app with isGooglePlayServicesAvailable(android.content.Context).

if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx) == ConnectionResult.SUCCESS) {
    // do your stuff (play service is available)
}

if the test doesn't pass, this will automatically display a button to download google play services

Then, you could test on :

onResultActivity

if it were installed, and run your app

marcolz
  • 2,880
  • 2
  • 23
  • 28
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
-1

as mentioned in comment , This is not "automatically" and also is not possible for the Play Services Framework except via software piracy.

if ur application can run and only after that u need google play service functionality :

Just do these step:

1, Download file use Asynctask or Service. Solution here

2, Pass downloaded file to package installer.

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");

startActivity(intent);

It's simple set path to downloaded file and mime type. More detail here. You can also look to the right. There is a list of related questions like yours

answer comes from "Jul" in this post :

How to download & install .apk file in Android application?

Community
  • 1
  • 1
Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68
  • This is not "automatically", as the user is still involved with the installation process. It also is not possible for the Play Services Framework except via software piracy, as the Play Services Framework is only distributed through the Play Store. – CommonsWare May 14 '14 at 15:11
  • ah didnt know about piracy thing. – Ahad Porkar May 14 '14 at 15:14