[英]Android Application will auto update when a new version is released on play store
I update the new version of my application in play store.我在 Play 商店中更新了我的应用程序的新版本。 Want to make auto update in those phone where the application is already installed.
想要在已经安装了应用程序的手机中进行自动更新。 I did this work.
我做了这项工作。
dependencies {
compile 'org.jsoup:jsoup:1.10.2'
}
and in MainActivity
I did this work-在
MainActivity
我做了这项工作-
public class MainActivity extends AppCompatActivity {
String newVersion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new FetchAppVersionFromGooglePlayStore().execute();
}
class FetchAppVersionFromGooglePlayStore extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
try {
return
Jsoup.connect("https://play.google.com/store/apps/details?id=" + "com.directed.android.smartstart" + "&hl=en")
.timeout(10000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();
} catch (Exception e) {
return "";
}
}
protected void onPostExecute(String string) {
newVersion = string;
Log.d("new Version", newVersion);
}
}
}
But, still not working.但是,仍然无法正常工作。 How can I solve this problem?
我怎么解决这个问题?
I believe what you want is to support in-app updates.我相信您想要的是支持应用内更新。 As the official docs states, In-app updates shows a dialog to the user in case an update is available and it's the user's choice whether he/she wants to update it or not.
正如官方文档所述,应用内更新会向用户显示一个对话框,以防有更新可用,并且用户可以选择是否要更新它。
This is how it looks like:这是它的样子:
I personally find it good because as an android developer, I want my users to stay updated considering privacy and security concerns.我个人觉得这很好,因为作为 android 开发人员,考虑到隐私和安全问题,我希望我的用户保持更新。 and it doesn't enforce user to update maintaining the UX.
并且它不强制用户更新维护 UX。
This way you don't have to mess with JSOUP as it works with in-built AppUpdateManager
.这样您就不必弄乱 JSOUP 了,因为它可以与内置的
AppUpdateManager
。 You should give it a read on the official docs: Support in-app updates .您应该阅读官方文档:支持应用内更新。
EDIT: You can further set and check update priority evaluating the severity of update whether it's necessary.编辑:您可以进一步设置和检查更新优先级,评估更新的严重性是否有必要。 As official document states:
正如官方文件所述:
The Google Play Developer API allows you to set the priority of each update. Google Play Developer API 允许您设置每次更新的优先级。 This allows your app to decide how strongly to recommend an update to the user.
这允许您的应用决定向用户推荐更新的强度。 For example, consider the following strategy for setting update priority:
例如,考虑以下设置更新优先级的策略:
Minor UI improvements: Low-priority update;
较小的 UI 改进:低优先级更新; request neither a flexible nor immediate update.
既不要求灵活更新,也不要求立即更新。
Performance improvements: Medium-priority update;
性能改进:中优先级更新; request a flexible update.
请求灵活更新。
Critical security update: High-priority update;
关键安全更新:高优先级更新; require an immediate update.
需要立即更新。
To determine priority, Google Play uses an integer value between 0 and 5, with > 0 being the default, and 5 being the highest priority.
为了确定优先级,Google Play 使用介于 0 和 5 之间的 integer 值,> 0 是默认值,5 是最高优先级。 To set the priority for an update, use
inAppUpdatePriority
field under Edits.tracks.releases in the Google Play Developer API.要设置更新的优先级,请使用 Google Play Developer API 中 Edits.tracks.releases 下的
inAppUpdatePriority
字段。 Priority can only be set when rolling out a new release, and cannot be changed later.优先级只能在推出新版本时设置,以后不能更改。
Priority is relevant because it will change the frequency of the update dialog visible to user as bothering user to update every time for minor update is not a good UX.优先级是相关的,因为它会改变用户可见的更新对话框的频率,因为每次小更新都会打扰用户进行更新,这不是一个好的用户体验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.