Add Utils.getVersionName(Context)
This commit is contained in:
parent
7f23cc9d51
commit
6c81216bc2
@ -279,15 +279,12 @@ public class FDroid extends ActionBarActivity {
|
||||
|
||||
case R.id.action_about:
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.about, null);
|
||||
// Fill in the version...
|
||||
try {
|
||||
PackageInfo pi = getPackageManager()
|
||||
.getPackageInfo(getApplicationContext()
|
||||
.getPackageName(), 0);
|
||||
((TextView) view.findViewById(R.id.version))
|
||||
.setText(pi.versionName);
|
||||
} catch (Exception ignored) {
|
||||
|
||||
String versionName = Utils.getVersionName(this);
|
||||
if (versionName == null) {
|
||||
versionName = getString(R.string.unknown);
|
||||
}
|
||||
((TextView) view.findViewById(R.id.version)).setText(versionName);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(view);
|
||||
final AlertDialog alrt = builder.create();
|
||||
|
@ -72,11 +72,9 @@ public class RepoUpdater {
|
||||
|
||||
private URL getIndexAddress() throws MalformedURLException {
|
||||
String urlString = repo.address + "/index.jar";
|
||||
try {
|
||||
String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
String versionName = Utils.getVersionName(context);
|
||||
if (versionName != null) {
|
||||
urlString += "?client_version=" + versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Could not get client version name", e);
|
||||
}
|
||||
return new URL(urlString);
|
||||
}
|
||||
|
@ -675,4 +675,16 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to get the version name of the client. Return null on failure.
|
||||
public static String getVersionName(Context context) {
|
||||
String versionName = null;
|
||||
try {
|
||||
versionName = context.getPackageManager()
|
||||
.getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Could not get client version name", e);
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user