【问题标题】:Android auto update resource files through developer consoleAndroid 通过开发者控制台自动更新资源文件
【发布时间】:2014-07-26 11:51:43
【问题描述】:

我的 Android 应用在 resource folder 中有原始文件,我从中检索对我的应用至关重要的数据。

这些资源文件需要不时更新,如果不是经常更新的话。

有没有办法通过谷歌更新机制(开发者控制台或任何其他工具)来实现这一点?

我知道 Google 的新政策不允许通过非 Playstore 来源更新应用。 Google's new policy

大多数时候我只需要更新这个特定的文件,并且大部分代码保持不变(除非有错误)。

我觉得让用户下载整个 .apk 文件只是为了更新一个原始文件是多余的。

【问题讨论】:

  • 您可以将文件托管在网络服务器上,然后将其下载到应用的私有目录或外部存储中。
  • 究竟什么是“应用程序的私有目录”???有没有办法在我的应用程序编码中使用私有目录文件?
  • 您使用 'Context.getFilesDir()' 来获取指向您的应用程序私有位置的路径。
  • 我可以从服务器下载新文件并使用 Context.getFilesDir() 将其放置在适当的位置。那么这回答了我的问题。谢谢!!

标签: android auto-update google-play resource-files


【解决方案1】:

不,这是不可能的,你不应该设计这样的应用程序。

我可以看到你想要什么,你想在不阻塞 UI 的情况下从服务器下载东西到客户端。

使用某种服务器端语言构建一个 api,如果只有远程文件已更新,则返回您想要的文件(您可以在客户端和服务器之间进行日期时间比较,如果不同,则下载它)

您可以尝试asynctask 进行 api 调用,返回您想要的文件并将其保存在资源文件夹中。

这是一个示例异步任务

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings.System;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class AsyncTaskActivity extends Activity implements OnClickListener {

    Button btn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn = (Button) findViewById(R.id.button1);
        // because we implement OnClickListener we only have to pass "this"
        // (much easier)
        btn.setOnClickListener(this);
    }

    public void onClick(View view) {
        // detect the view that was "clicked"
        switch (view.getId()) {
        case R.id.button1:
            new LongOperation().execute("");
            break;
        }
    }

    private class LongOperation extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Thread.interrupted();
                }
            }
            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {
            TextView txt = (TextView) findViewById(R.id.output);
            txt.setText("Executed"); // txt.setText(result);
            // might want to change "executed" for the returned string passed
            // into onPostExecute() but that is upto you
        }

        @Override
        protected void onPreExecute() {}
    }
}

我希望这能解决你的问题

【讨论】:

  • 没有。我知道如何在 Android 中使用线程。通过服务器更新是其中一种方法,但我如何在我的应用程序中使用该特定文件。在开发过程中,我将这样的文件放在资源->raw->file.f 部署应用程序后,该资源文件夹将在哪里?
  • @SreecharanDesabattula 您无法写入资源目录
  • 就像我指出的那样,我需要一些方法来从应用程序更新文件,并且该文件应该是应用程序私有的。不一定是资源目录。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 2014-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多