Show modal after installation or update of app [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this questionA lot of Android apps now display a modal with the most recent changelog after it is installe开发者_高级运维d or updated.
How can I display a scrollable modal after the application is initially installed or updated?
Try this:
With Android Change Log you can easily create, show and maintain an Android change log dialog.
Features are:
- display only what's new or the whole change log
- display on first start of newly installed app or new app version
- write the change log in a simplified language but also use HTML and CSS if needed...
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>
I think you're probably on the right track. For #1, I have a class that inherits off of dialog, and its layout simply has a ScrollView containing a TextView, and then a "dismiss" button after that.
Regarding #2, what I've done in mine is to store a setting for LastVersionNotesSeen that holds the ... well, the version number for the notes last displayed. :) If that number is less than the current version, I display the latest version notes and update the value to the current version.
For displaying the change log, you can also you localized (i.e. loaded from res folder) html in the dialog:
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(getString(R.string.changelog_dialog_title));
dialog.setIcon(getResources().getDrawable(R.drawable.icon));
WebView wv = new WebView(getApplicationContext());
wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8");
dialog.setView(wv);
dialog.setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
The magic is how to code the html 'page' in res/values/strings.xml:
<string name="changelog_dialog_text">
<![CDATA[<b>Version 1.3.0:</b>
<ul>
<li>Change 1</li>
<li>Change 2</li>
</ul>
]]>
</string>
精彩评论