相关疑难解决方法(0)

我在哪里可以找到DownloadManager的ContentProvider实现

我尽可能多地搜索了android的开源代码,但是我无法通过2.3 SDK中的DownloadManager找到实际下载的实现.我找到了DownloadManager源代码和下载类源代码,该代码具有与ContentProvider交互的常量,但我无法找到该代码的源代码ContentProvider.

我想找到这个,以便我知道一个很好的方法来实现我自己的下载,因为我将使用比我的应用程序更小的2.3版本.

android android-contentprovider android-download-manager

6
推荐指数
1
解决办法
2278
查看次数

确定合适的缓冲区大小

我正在使用 ByteBuffer.allocateDirect() 分配一些缓冲内存以将文件读入内存,然后最终散列该文件字节并从中获取文件散列 (SHA)。输入文件的大小范围很大,从几 KB 到几 GB 不等。

我已经阅读了几个关于选择缓冲区大小的线程和页面(甚至一些在 SO 上)。有些人建议尝试选择本机 FileSystem 使用的一个,以尽量减少对部分块等进行读取操作的机会。比如4100字节的缓冲区,NTFS默认是4096,所以多出来的4位需要单独读操作,非常浪费。

所以坚持使用 2、1024、2048、4096、8192 等的幂。我看到一些推荐的缓冲区大小为 32KB,其他建议将缓冲区设置为输入文件的大小(对于小文件可能没问题,但是什么关于大文件?)。

坚持使用原生块大小的缓冲区有多重要?现代来说(假设现代 SATA 驱动器或更好的驱动器缓存至少有 8Mb,以及其他现代操作系统“魔法”来优化 I/O)缓冲区大小有多重要,我应该如何最好地确定将我的大小设置为多少?我可以静态设置它,还是动态确定它?感谢您的任何见解。

java buffer bytebuffer

5
推荐指数
1
解决办法
4339
查看次数

如何检测Google Play商店是否正在下载/安装特定应用?

许多应用程序提供安装开发人员或开发人员合作伙伴制作的其他应用程序的建议.建议只是可以安装推荐应用程序的Play商店的链接.

如果出现以下情况,我不想为app X提供推荐:

  • App X已经安装
  • App X正在安装中(例如在Google Play上下载)

检测是否安装了X很容易,但我似乎找不到任何API来从Google Play读取下载/安装状态.有没有办法检测用户是否正在安装应用程序X?

android google-play google-play-services

5
推荐指数
1
解决办法
3516
查看次数

如何在自定义ListView中使用Button OnClick和View Holder

我需要一些帮助,我正在使用一个视图来从动态arrayadapter中显示.

我有列表视图.

每行包含;

  • 标题(Textview),
  • 子标题(TextView),
  • 进度条
  • 下载按钮(按钮).

我想在单击"下载"按钮时显示进度条并隐藏"下载"按钮.单击第一行中的下载按钮时,将显示第一个进度条,但也显示第8个进度条.

这是我的代码.我做错了什么?

    public class TabInComingAdaptor extends BaseAdapter {

    public static class ViewHolder {
        TextView title;
        TextView desc;
        Button DownloadButton;
        ProgressBar pB;
    }

    private ArrayList<rowObject> data;
    private LayoutInflater inflater = null;
    private Application ap;
    // final private Activity currentActivity;
    Button progressButton1;
    int CurrentUser;

    public TabInComingAdaptor(Activity activity, Application application,
            ArrayList<rowObject> GelenFakslar) {
        // currentActivity = activity;
        ap = application;
        data = GelenFakslar;
        inflater = (LayoutInflater) ap
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return data.size();
    } …
Run Code Online (Sandbox Code Playgroud)

android android-listview android-viewholder

5
推荐指数
1
解决办法
8669
查看次数

计算估计的剩余下载时间

我有一个从URL下载文件的代码.
我有两个参数来计算下载的所有时间:

Long start = System.nanoTime();
// downloading...
Long end = System.nanoTime();
Run Code Online (Sandbox Code Playgroud)

我需要测量下载结束时的估计剩余时间.我怎么能这样做?

java android

5
推荐指数
1
解决办法
3643
查看次数

单击按钮后如何下载文件(Android Studio)

我最近在我的应用中创建了一个活动。现在,我希望用户在要查看指南时下载.pdf文件。我想在一个按钮上实现它。知道如何正确执行此操作吗?

下面是我的代码:

public class Exhibitor_Registration_Activity extends AppCompatActivity  {

    Button buttonDownload;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exhibitor_registration_);

        this.setTitle("Buyer Registration");

        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        myToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);

        final Button buttonDownload = (Button) findViewById(R.id.buttonDownload);

        buttonDownload.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                try {
                    //this is the file you want to download from the remote server
                    String path ="http://www.manilafame.com/website-assets/downloads/exhibitor-application-kit/local/201704/1-Summary-of-Participation-Details-April-2017_MN_002.pdfp";
                    //this is the name of the local file you will create
                    String targetFileName = null;
                    boolean eof = false;
                    URL u …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
1万
查看次数

Android替换应用程序无法安装

我的应用程序实现了自动升级功能,因为该应用程序不会向市场发布.apk文件托管在网络服务器上.我已经实现了以下链接的第一部分

使用AsyncTask并在对话框中显示下载进度

现在,当我运行应用程序时,会发生以下情况.

  1. 如果有新版本可用,则应用程序会提示用户是否要升级. 升级提示

  2. 如果用户选择"是",则应用程序从服务器下载文件. 下载

  3. 完成后,应用程序会提示用户是否要更换应用程序 替换提示
  4. 如果用户点击确定,则应用程序开始安装但在以下屏幕中失败 在此输入图像描述

没有提供关于为何发生这种情况的日志文件信息.请有人帮我理解可能导致此问题的原因.这是生成fianl 2屏幕而不是我的代码的默认android代码.

在异步任务上运行以下代码后会发生这种情况:

    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        // dismiss the progress dialog
        mProgressDialog.dismiss();
        // get the file
        String path = getFilesDir().getAbsolutePath()+ File.separator + getString(R.string.apk_file);
        File file = new File(path);
        // if it exists
        if(file.exists()) {
            // create and start the intent with the new file
            Intent intent = new Intent(Intent.ACTION_VIEW); 
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); 
            startActivity(intent);
        } else {
            // display error message 
            Toast.makeText(context, "File was not downloaded", Toast.LENGTH_LONG).show();
        }           
    }
Run Code Online (Sandbox Code Playgroud)

如果我卸载应用程序并使用浏览器转到文件位置,应用程序会自动下载,然后我可以从下载文件夹中成功安装它.

这可能是应用程序当前正在运行时应用程序正在尝试安装自己的问题吗?在升级过程中文件被下载到内部存储器而不是SD卡位置,因为我不能保证用户设备将存在SD卡.

android upgrade

4
推荐指数
1
解决办法
2624
查看次数

在android下载大文件的最佳方法?

我需要在我的应用程序上下载一个大文件(差不多2gb),我想知道最好的方法是什么,以及一些libs来帮助我.首先,我查看了Android异步Http库,但我没有找到显示如何发布进度或启动,暂停下载的示例.然后我不知道我是否应该使用这个lib或只是使用一个标准的http commons.其他问题是,我应该使用服务来下载我的文件吗?

你们可以给一个提示,怎么做?

android

4
推荐指数
1
解决办法
2万
查看次数

使用Dropbox网址android下载文件

嗨,大家好,我正在尝试使用Dropbox网址下载文件,我从Android的“下载文件”中复制了代码,并在使用DownloadManager类的ProgressDialog中显示了进度

    public void downloadFromDropBoxUrl(View view) {
        //verfying if the downloadmanager is available first.
        if (isDownloadManagerAvailable(getApplication())) {
            String url = "https://www.dropbox.com/s/m4z5u9qstxdtbc3/AllExams22.pdf?dl=0";
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.setDescription("Some descrition");
            request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            }
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "my-map.pdf");

// get download service and enqueue file
            DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            manager.enqueue(request);
        }
    }
    public static …
Run Code Online (Sandbox Code Playgroud)

android dropbox android-download-manager

4
推荐指数
1
解决办法
1958
查看次数

当互联网连接丢失时,读取Inputstream不停止

我正在使用asynctask来下载文件.它正常工作,直到我关闭我的Android的wifi连接(没有其他互联网连接),仍然没有更改下载对话框.当我通过日志检查时,我发现输入流的函数read()是不停止的.那么如何检查这种情况呢?这是我的代码:

URL url = new URL(this.url);
        URLConnection connection = url.openConnection();
        connection.setReadTimeout(1000);
        connection.connect();
        // this will be useful so that you can show a typical 0-100% progress bar
        int fileLength = connection.getContentLength();
        fileName = "temp.zip";

        // download the file
        InputStream input = new BufferedInputStream(connection.getInputStream());
        OutputStream output = new FileOutputStream(path+fileName);

        byte buffer[] = new byte[1024000];
        long total = 0;
        int count;
        Log.v("test download:","download in background");
        while (((count = input.read(buffer)) != -1)) {
            Log.v("test download:","read:"+count);
            total += count;
            publishProgress((int) (total * 100 / …
Run Code Online (Sandbox Code Playgroud)

android inputstream android-asynctask

3
推荐指数
1
解决办法
1893
查看次数