dparnas dparnas - 8 days ago 6
Android Question

Show modal after installation or update of app

A lot of Android apps now display a modal with the most recent changelog after it is installed or updated.

How can I display a scrollable modal after the application is initially installed or updated?

Answer

Ended up with the following code Part 1. Checking if the changelog should be viewed

        //evaluate if we will show changelog
    try {
        //current version
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        int versionCode = packageInfo.versionCode; 

        //version where changelog has been viewed
        SharedPreferences settings = getSharedPreferences(SAPNotePreferences.PREFS_NAME, 0);
        int viewedChangelogVersion = settings.getInt(SAPNotePreferences.KEY_CHANGELOG_VERSION_VIEWED, 0);

        if(viewedChangelogVersion<versionCode) {
            Editor editor=settings.edit();
            editor.putInt(SAPNotePreferences.KEY_CHANGELOG_VERSION_VIEWED, versionCode);
            editor.commit();
            displayChangeLog();
        }
    } catch (NameNotFoundException e) {
        Log.w("Unable to get version code. Will not show changelog", e);
    }

Part 2 displaying the changelog dialog

        //load some kind of a view
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.changelog_view, null);

    new AlertDialog.Builder(this)
    .setTitle("Changelog")
    .setIcon(android.R.drawable.ic_menu_info_details)
    .setView(view)
    .setNegativeButton("Close", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
          //
      }
    }).show();

Part 3 the layout with the changelog

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <ScrollView android:id="@+id/aboutscrollview" 
            android:orientation="vertical"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">    
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                    <TextView android:text="Thanks for installing ..."
                            android:layout_width="fill_parent" 
                            android:layout_height="wrap_content"
                            android:paddingLeft="15px"              
                            android:layout_gravity="center_vertical"
                            android:textColor="#ffffff" />  
                    <TextView android:text="Changes: "
                            android:layout_width="fill_parent" 
                            android:layout_height="wrap_content"            
                            android:paddingTop="15px"
                            android:paddingLeft="15px"
                            android:textStyle="bold"
                            android:textColor="#ffffff" />
                    <TextView android:text="v2.0:changes..."
                            android:layout_width="fill_parent" 
                            android:layout_height="wrap_content"
                            android:paddingLeft="15px"      
                            android:paddingBottom="10px"            
                            android:textColor="#ffffff" />
                    </LinearLayout>
            </ScrollView>                   
</LinearLayout>
Comments