重新安装应用程序不带过来发布Android版应用程序的所有变化 [英] Reinstalling app does not bring over all the changes of released app android
问题描述
我有一个重新安装旧的应用程序的新版本的一个项目,我使用自定义的自安装程序来安装应用程序。我看到与重新安装一些奇怪的行为。当应用程序下载该应用程序的发布版本,并非所有的最新变化随之而来。它的安装数天前释放。不知道为什么会这样。
我在想,我需要完全删除并重新安装应用程序在我自己的安装程序。
下面是code为自安装程序:
公共类AsyncActivity延伸活动{
公共静态INT TASKID;意图keepInApp;私人布尔messageShowing = FALSE;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.main); lblUpdating =(的TextView)findViewById(R.id.lblUpdating); 的TaskID = getTaskId(); keepInApp =新意图(this.getApplicationContext(),ServiceKeepInApp.class); 束束= getIntent()getExtras()。 如果(捆绑!= NULL){
thepackageName = bundle.getString(GlobalVars.keyPackageName);
GlobalVars.KeyPackageName = thepackageName; urlPath = bundle.getString(GlobalVars.keyFTPPath);
GlobalVars.KeyFTPPath = urlPath; downloadPath = bundle.getString(GlobalVars.keyDownloadLocation);
GlobalVars.deviceDownloadPath = downloadPath; 用户= bundle.getString(GlobalVars.keyFTPUser);
GlobalVars.FTPUser =用户; PW = bundle.getString(GlobalVars.keyFTPPassword);
GlobalVars.FTPPassword = PW; apkName = bundle.getString(GlobalVars.keyFileName);
GlobalVars.APKName = apkName; serverVersion = bundle.getString(GlobalVars.keyServerVersion);
GlobalVars.ServerVersion = serverVersion; 如果(bundle.getString(GlobalVars.keyScreenText)!= NULL){
lblUpdating.setText(Html.fromHtml(bundle.getString(GlobalVars.keyScreenText)));
} 如果(bundle.getString(GlobalVars.keyFont)!= NULL){
如果(!bundle.getString(GlobalVars.keyFont).equalsIgnoreCase()){
字样字体= Typeface.createFromAsset(getAssets(),字体/+ bundle.getString(GlobalVars.keyFont));
lblUpdating.setTypeface(字体);
}
} 如果(StringUtils.isBlank(urlPath)|| StringUtils.isBlank(downloadPath)|| StringUtils.isBlank(用户)|| StringUtils.isBlank(PW)
|| StringUtils.isBlank(apkName)|| StringUtils.isBlank(thepackageName)){
stopService(keepInApp);
完();
android.os.Process.killProcess(android.os.Process.myPid()); }其他{
startService(keepInApp);
}
} 尝试{
INT位置= urlPath.lastIndexOf(。);
ftpServerName = urlPath.substring(0,+位置4); // +4所以我们得到.COM
ftpUpdatePath = urlPath.substring(位置+ 4); // +4所以我们没有得到.copm 布尔downloadAPK = TRUE; 尝试{
文件APK =新的文件(downloadPath,apkName); 如果(APK!= NULL){
尝试{
软件包管理系统下午= getPackageManager();
PackageInfo圆周率= pm.getPackageArchiveInfo(downloadPath + apkName,0);
pi.applicationInfo.sourceDir = downloadPath + apkName;
pi.applicationInfo.publicSourceDir = downloadPath + apkName; 如果(Double.valueOf(pi.versionName).equals(Double.valueOf(serverVersion))){
downloadAPK = FALSE;
InstallApplication(thepackageName,apkName,downloadPath);
}
}赶上(例外五){
e.printStackTrace();
}
}
}赶上(例外五){
downloadAPK = FALSE;
ProgressTask任务=(ProgressTask)新ProgressTask(本);
task.execute(用户私服,ftpServerName,ftpUpdatePath,downloadPath,apkName,thepackageName);
e.printStackTrace();
} 如果(downloadAPK){
ProgressTask任务=(ProgressTask)新ProgressTask(本);
task.execute(用户私服,ftpServerName,ftpUpdatePath,downloadPath,apkName,thepackageName);
} }赶上(例外五){
stopService(keepInApp);
完();
android.os.Process.killProcess(android.os.Process.myPid());
e.printStackTrace();
}
} 公共无效InstallApplication(字符串的packageName,字符串apkName,字符串INSTALLPATH){
setIsMessageShowing(真); 乌里packageURI = Uri.parse(的packageName);
//意向意图=新意图(android.content.Intent.ACTION_VIEW,packageURI);
意向意图=新意图(android.content.Intent.ACTION_VIEW,packageURI); / *
*就在这里,我们应该能相对文件路径更改为
*无论我们选择下载APK到。
* / intent.setDataAndType(Uri.fromFile(新文件(installPath.toString()+ apkName.toString())),应用程序/ vnd.android.package归档);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(意向);
}
和的服务:
公共类ServiceKeepInApp延伸服务{私人布尔sendHandler = FALSE;处理器taskHandler =新的处理程序(){
@覆盖
公共无效的handleMessage(消息MSG){
super.handleMessage(MSG); ActivityManager activityManager =(ActivityManager)getSystemService(Service.ACTIVITY_SERVICE); 如果(activityManager.getRecentTasks(2,0)获得(0).ID!= AsyncActivity.taskID){
意向意图=新意图(Intent.ACTION_MAIN);
上下文mycon = getApplicationContext();
软件包管理系统经理= mycon.getApplicationContext()getPackageManager()。
意图= manager.getLaunchIntentForPackage(mycon.getPackageName()); intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(keyFTPPath,GlobalVars.FTPPath);
intent.putExtra(keyDownloadLocation,GlobalVars.deviceDownloadPath);
intent.putExtra(keyFTPUser,GlobalVars.FTPUser);
intent.putExtra(keyFTPPassword,GlobalVars.FTPPassword);
intent.putExtra(的KeyFileName,GlobalVars.APKName);
intent.putExtra(keyPackageName,GlobalVars.KeyPackageName);
intent.putExtra(GlobalVars.keyServerVersion,GlobalVars.ServerVersion); mycon.startActivity(意向);
} 如果(sendHandler){
taskHandler.sendEmptyMessageDelayed(0,1000);
}
}
};@覆盖
公共无效的onCreate(){
Log.v(服务,创造);
super.onCreate();
sendHandler = TRUE;
taskHandler.sendEmptyMessage(0);
}
和用于下载软件AsyncTask的:
类ProgressTask扩展的AsyncTask<弦乐,太虚,布尔> {
清单<消息>标题;
私人FTPClient mFTPClient = NULL; ProgressTask(上下文asyncActivity){
上下文= asyncActivity;
} / **进度对话框,显示该备份处理用户。 * / / **应用程序上下文。 * /
私人上下文的背景下; 保护布尔doInBackground(最终字符串参数... args){
布尔状态= NULL; 尝试{
状态= ftpConnect(参数[2],ARGS [0],ARGS [1],21); 如果(状态){
文件的DestinationPath =新的文件(参数[4]); 如果(!destinationPath.exists()){
destinationPath.mkdirs();
} 文件FROMFILE =新的文件(参数[3] + ARGS [5]); 文件TOFILE =新的文件(参数[4] +/+ ARGS [5]); 如果(toFile.exists()){
toFile.delete();
} 状态= ftpDownload(fromFile.toString(),toFile.toString()); mFTPClient.logout();
mFTPClient.disconnect(); InstallApplication(参数[6],ARGS [5],ARGS [4]);
}
返回状态; }赶上(例外五){
e.printStackTrace();
返回状态;
}
}
为什么软件停留在一个应用程序previous版本后,重新安装?我可以用code喜欢删除旧的包:
公共无效unInstallApp(字符串的packageName){
乌里packageURI = Uri.parse(packageName.toString());
意图uninstallIntent =新意图(Intent.ACTION_DELETE,packageURI);
context.startActivity(uninstallIntent);
}
文件没有被覆盖,所以这就是为什么发行版本没有更新。
I have a project that is re-installing a new version of an old app and I use a custom self installer to install the app. I am seeing some strange behavior with the re-install. When the app downloads the released version of the app, not all of the latest changes come with it. It's installing a release from several days ago. Not sure why this is happening.
I am thinking that I need to completely delete and reinstall the app in my self installer program.
Here is the code for the self installer:
public class AsyncActivity extends Activity {
public static int taskID;
Intent keepInApp;
private boolean messageShowing = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lblUpdating = (TextView)findViewById(R.id.lblUpdating);
taskID = getTaskId();
keepInApp = new Intent(this.getApplicationContext(), ServiceKeepInApp.class);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
thepackageName = bundle.getString(GlobalVars.keyPackageName);
GlobalVars.KeyPackageName = thepackageName;
urlPath = bundle.getString(GlobalVars.keyFTPPath);
GlobalVars.KeyFTPPath = urlPath;
downloadPath = bundle.getString(GlobalVars.keyDownloadLocation);
GlobalVars.deviceDownloadPath = downloadPath;
user = bundle.getString(GlobalVars.keyFTPUser);
GlobalVars.FTPUser = user;
pw = bundle.getString(GlobalVars.keyFTPPassword);
GlobalVars.FTPPassword = pw;
apkName = bundle.getString(GlobalVars.keyFileName);
GlobalVars.APKName = apkName;
serverVersion = bundle.getString(GlobalVars.keyServerVersion);
GlobalVars.ServerVersion = serverVersion;
if (bundle.getString(GlobalVars.keyScreenText) != null) {
lblUpdating.setText(Html.fromHtml(bundle.getString(GlobalVars.keyScreenText)));
}
if (bundle.getString(GlobalVars.keyFont) != null) {
if (!bundle.getString(GlobalVars.keyFont).equalsIgnoreCase("")) {
Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/" + bundle.getString(GlobalVars.keyFont));
lblUpdating.setTypeface(typeFace);
}
}
if (StringUtils.isBlank(urlPath) || StringUtils.isBlank(downloadPath) || StringUtils.isBlank(user) || StringUtils.isBlank(pw)
|| StringUtils.isBlank(apkName) || StringUtils.isBlank(thepackageName)) {
stopService(keepInApp);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
} else {
startService(keepInApp);
}
}
try {
int position = urlPath.lastIndexOf(".");
ftpServerName = urlPath.substring(0, position + 4); // +4 so we get .com
ftpUpdatePath = urlPath.substring(position + 4); // +4 so we don't get .copm
boolean downloadAPK = true;
try {
File apk = new File(downloadPath, apkName);
if (apk != null) {
try {
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(downloadPath + apkName, 0);
pi.applicationInfo.sourceDir = downloadPath + apkName;
pi.applicationInfo.publicSourceDir = downloadPath + apkName;
if (Double.valueOf(pi.versionName).equals(Double.valueOf(serverVersion))) {
downloadAPK = false;
InstallApplication(thepackageName, apkName, downloadPath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
downloadAPK = false;
ProgressTask task = (ProgressTask)new ProgressTask(this);
task.execute(user, pw, ftpServerName, ftpUpdatePath, downloadPath, apkName, thepackageName);
e.printStackTrace();
}
if (downloadAPK) {
ProgressTask task = (ProgressTask)new ProgressTask(this);
task.execute(user, pw, ftpServerName, ftpUpdatePath, downloadPath, apkName, thepackageName);
}
} catch (Exception e) {
stopService(keepInApp);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
e.printStackTrace();
}
}
public void InstallApplication(String packageName, String apkName, String installPath) {
setIsMessageShowing(true);
Uri packageURI = Uri.parse(packageName);
// Intent intent = new Intent(android.content.Intent.ACTION_VIEW, packageURI);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, packageURI);
/*
* Right here, we should be able to change the relative file-pathing to
* wherever we choose to download the apk to.
*/
intent.setDataAndType(Uri.fromFile(new File(installPath.toString() + apkName.toString())), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
And for the service:
public class ServiceKeepInApp extends Service {
private boolean sendHandler = false;
Handler taskHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
ActivityManager activityManager = (ActivityManager)getSystemService(Service.ACTIVITY_SERVICE);
if (activityManager.getRecentTasks(2, 0).get(0).id != AsyncActivity.taskID) {
Intent intent = new Intent(Intent.ACTION_MAIN);
Context mycon = getApplicationContext();
PackageManager manager = mycon.getApplicationContext().getPackageManager();
intent = manager.getLaunchIntentForPackage(mycon.getPackageName());
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("keyFTPPath", GlobalVars.FTPPath);
intent.putExtra("keyDownloadLocation", GlobalVars.deviceDownloadPath);
intent.putExtra("keyFTPUser", GlobalVars.FTPUser);
intent.putExtra("keyFTPPassword", GlobalVars.FTPPassword);
intent.putExtra("keyFileName", GlobalVars.APKName);
intent.putExtra("keyPackageName", GlobalVars.KeyPackageName);
intent.putExtra(GlobalVars.keyServerVersion, GlobalVars.ServerVersion);
mycon.startActivity(intent);
}
if (sendHandler) {
taskHandler.sendEmptyMessageDelayed(0, 1000);
}
}
};
@Override
public void onCreate() {
Log.v("Service", "created");
super.onCreate();
sendHandler = true;
taskHandler.sendEmptyMessage(0);
}
and for the AsyncTask that downloads the software:
class ProgressTask extends AsyncTask<String, Void, Boolean> {
List<Message> titles;
private FTPClient mFTPClient = null;
ProgressTask(Context asyncActivity) {
context = asyncActivity;
}
/** progress dialog to show user that the backup is processing. */
/** application context. */
private Context context;
protected Boolean doInBackground(final String... args) {
Boolean status = null;
try {
status = ftpConnect(args[2], args[0], args[1], 21);
if (status) {
File destinationPath = new File(args[4]);
if (!destinationPath.exists()) {
destinationPath.mkdirs();
}
File fromFile = new File(args[3] + args[5]);
File toFile = new File(args[4] + "/" + args[5]);
if (toFile.exists()) {
toFile.delete();
}
status = ftpDownload(fromFile.toString(), toFile.toString());
mFTPClient.logout();
mFTPClient.disconnect();
InstallApplication(args[6], args[5], args[4]);
}
return status;
} catch (Exception e) {
e.printStackTrace();
return status;
}
}
Why would a previous version of the software stay on the app after reinstall? Could I delete the old package with code like:
public void unInstallApp(String packageName) {
Uri packageURI = Uri.parse(packageName.toString());
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
context.startActivity(uninstallIntent);
}
File was not being overwritten, so this is why the release version didn't update.
这篇关于重新安装应用程序不带过来发布Android版应用程序的所有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!