Pages

Friday 18 May 2012

Update your Android application apk on Google play

Update or change your Android apk...

Was Your previous app successful?  You want to update or change your previous apk ? then follow the following steps.Its quite easy task.

  1. Open your licensed application on eclipse. Go to the AndroidManifest file of your application.
  2. Change the version code and version name (It is very important. You cannot update a new apk with same version code and version name as that of previous one) .
  3. Clean & compile your app 
  4. Repeat process for the debug key (refer previous post to do that http://bewithandroid.blogspot.in/2012/05/publishing-android-application-on.html)
  5. Go to Google play developer console and select your previously uploaded app
  6. Upload your new apk from the applications's bin folder on google play.
  7. Deactivate your older apk and activate your new apk 
  8. Click the save option

You can also change the product details any time you want. Just save the details and wait for a while(sometime it takes 2-3hours), you will get your update(with new version code) on market page.

If you want to change your apk, you can deactivate the current apk and activate the apk you want.


When you publish a new version of your application, users will see an Update available notification next to your app in My Downloads in their device.

Google Play can manage updates to preloaded applications, provided the following conditions are met:

  • Package Name with the same Version Code of pre-loaded app must to be uploaded to the Developer Console
  • Pre-loaded app must be signed by using the same signature as in the app listed on Google Play
  • App must be free
  • User's device must match the targeting of current version of the application on Google Play

Note: The update notification feature is only available on devices running Android software version 1.1 or above.

Go ahead :)

Tuesday 15 May 2012

To do list for publishing your Android application on Google play app store


Let us go through the steps to be followed for publishing an android application.

  • Confirm that your application is free from errors. If possible avoid warning also to make your code clean and beautiful.
  •   Test your apk with emulator, do this for many times, so that you can find out small mistakes. 
  •  As a final test copy your apk to any device that support you application's android target version,there you can install it and see how it works.
I recommend this because you may have used some local resources like the local network of your computer system(with or without proxy settings) or local domain names,etc.. So do a final check to confirm everything is accessible from the device. ]

If all these works fine, then you can start preparation for publishing your great application.
    
  • You need a gmail account to open a google play developer account . If you have one, use it. Otherwise sign up for  new account here 
https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default&hl=en

  • Now you can open a new Google play developer account here. 
https://accounts.google.com/ServiceLogin?service=androiddeveloper&passive=true&nui=1&continue=https://play.google.com/apps/publish&followup=https://play.google.com/apps/publish .

Now you are in Google play console. There is simple registration process to complete. Go with that. You have to pay a one time registration fee $25, then you can publish your apps anytime you want. For the completion of registration process and verification of your payment details,it will take 24-72 hours, so pls avoid mistakes because it will waste your another 2-3 days. 

[Do not forget to check your account status regularly by login to the developer console. ]

You don't have to waste your precious time on these long hours. You can start preparation for publishing now itself. Because you can upload you apk that is ready to publish here and you can create resources needed for your application and can also edit the app details. But you can publish it only after completing the registration.

 If there is any problem with your registration after uploading the apk,don't be panic..the google play help team is there to support you. You can mail them directly to ask your doubts. they will help you until you get satisfied.

For you doubts in apk publishing and updation contact email id:
googleplay-developer-support@google.com

If you have any problems in registration process contact :
wallet-support@google.com

Now we can start

  • Get the public key of you google play account . Go to "Edit profile" link in the google play android developer console home page. There you can find your public key under "Licensing & In-app Billing" section. You need this value for licencing your app.
 [ You are not forced to do the licensing for your app. But it is a recommended way of publishing, to make your apk safe. The alternate facility available is to do the copy protection which will be removed soon.So it is better to use for both paid and free apps]





 Steps for licencing your app
  • Now you need  License Verification Library (LVL). First you check whether they are already with your android installation. For that go to android sdk folder(installed Android folder),  open extras->google->market_licensing->library.
  • Copy the contents of src folder inside the library folder to your application src folder  
           [ com.android.vending.licensing and com.android.vending.licensing.util ].


  • Adding License to your application
  Now see the sample folder inside the market_licensing folder. There you can find a sample licensing activity which you are going to add to your application


package com.example.android.market.licensing;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Secure;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.android.vending.licensing.AESObfuscator;
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;

/**
 * Welcome to the world of Android Market licensing. We're so glad to have you
 * onboard!
 *

 * The first thing you need to do is get your hands on your public key.
 * Update the BASE64_PUBLIC_KEY constant below with your encoded public key,
 * which you can find on the
 * Edit Profile
 * page of the Market publisher site.
 *

 * Log in with the same account on your Cupcake (1.5) or higher phone or
 * your FroYo (2.2) emulator with the Google add-ons installed. Change the
 * test response on the Edit Profile page, press Save, and see how this
 * application responds when you check your license.
 *

 * After you get this sample running, peruse the
 *
 * licensing documentation.

 */
public class MainActivity extends Activity {
    private static final String BASE64_PUBLIC_KEY = "REPLACE THIS WITH YOUR PUBLIC KEY";

    // Generate your own 20 random bytes, and put them here.
    private static final byte[] SALT = new byte[] {
        -46, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
        89
    };

    private TextView mStatusText;
    private Button mCheckLicenseButton;

    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;
    // A handler on the UI thread.
    private Handler mHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

        mStatusText = (TextView) findViewById(R.id.status_text);
        mCheckLicenseButton = (Button) findViewById(R.id.check_license_button);
        mCheckLicenseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                doCheck();
            }
        });

        mHandler = new Handler();

        // Try to use more data here. ANDROID_ID is a single point of attack.
        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

        // Library calls this when it's done.
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(
            this, new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
        doCheck();
    }

    protected Dialog onCreateDialog(int id) {
        // We have only one dialog.
        return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(R.string.unlicensed_dialog_body)
            .setPositiveButton(R.string.buy_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                        "http://market.android.com/details?id=" + getPackageName()));
                    startActivity(marketIntent);
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            })
            .create();
    }

    private void doCheck() {
        mCheckLicenseButton.setEnabled(false);
        setProgressBarIndeterminateVisibility(true);
        mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                mStatusText.setText(result);
                setProgressBarIndeterminateVisibility(false);
                mCheckLicenseButton.setEnabled(true);
            }
        });
    }

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow() {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            displayResult(getString(R.string.allow));
        }

        public void dontAllow() {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            displayResult(getString(R.string.dont_allow));
            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            showDialog(0);
        }

        public void applicationError(ApplicationErrorCode errorCode) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            String result = String.format(getString(R.string.application_error), errorCode);
            displayResult(result);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mChecker.onDestroy();
    }

}


Edit your main activity with this sample. Enough comments are there to help you. 

Replace public key with yours, and enough comments are there to edit. Copy the methods except the onCreate() and copy the code inside the onCreate() to your onCreate() method. Thats all.

You cannot test your code in this time, since it is checking the licensing,you cannot access the functionalities with emulator, you will be getting a message saying that you need licence.

  • Next you need to get a debug key that is valid for minimum 50years
        For that first you need to create a keystore. Open terminal(in linux) or command prompt(in widows).
Run the following command:
  keytool -genkey -v -keystore keystorefilename.keystore -alias aliasforkeystore 
  Provide the details after specifying a password for the keystore.Then a keystore file in the name keystorefilename.keystore will be created on the current path.
  •   Now open Eclipse,->  Select you application. Select File->export->export android application(sub option under Android). Next->browse project->Next->select use existing keystore file->browse keystore file and enter password(you just created)->Next->select create new key->Enter the details(Remember to give validity field greater than 50years)->next->finish.
Now your apk is ready to upload. Check you have entered a version code and version name which should be changed on each updation.

Now go to Google play. Upload you apk there. Edit the product details. You can add graphic assets,video link(demo for your app) etc.

If your registration process was completed, publish your app and test the licensing procedure. It will work fine, if you have done everything clean. If it has any problem, don't get upset. Edit your application based on the error showing. Change the version code and version name -> clean & compile your app -> repeat process for the debug key->  get your apk-> upload it as a new apk on google play. Deactivate older apk and activate your new apk and save.

You can change the product details any time you want. Just save the details and wait for a while, you will get your update on market page.

There is an option to add expansion files when your apk is of more than 50MB.

Now everything done..


Go ahead with your Android journey..Best of luck.. :)