没有找到处理意图的活动 (act=android.intent.action.VIEW) 尝试安装 APK [英] No Activity Found to handle Intent (act=android.intent.action.VIEW) Trying to Install APK

查看:52
本文介绍了没有找到处理意图的活动 (act=android.intent.action.VIEW) 尝试安装 APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装我刚刚下载的 APK.但是,当我利用 Intent 安装 APK 时,我收到错误 android.content.ActivityNotFoundException: No Activity found to handle Intent...这是我的来源:

I'm trying to install an APK that I just downloaded. However, when I utilize the intent to install the APK I get error android.content.ActivityNotFoundException: No Activity found to handle Intent... Here's my source:

class DownloadTask extends AsyncTask<String, Integer, String> {
    private Context context;
    private String output;
    private Boolean install;
    private String file;
    private PowerManager.WakeLock wakeLock;

    public DownloadTask(Context context, String output, String file, Boolean install) {
        this.context = context;
        this.output = output;
        this.install = install;
        this.file = file;
    }

    @Override
    protected String doInBackground(String... surl) {
        InputStream input = null;
        OutputStream output = null;
        HttpURLConnection c = null;
        try {
            URL url = new URL(surl[0]);
            c = (HttpURLConnection) url.openConnection();
            c.connect();
            if (c.getResponseCode() != HttpURLConnection.HTTP_OK)
                return "Server returned HTTP " + c.getResponseCode() + " " + c.getResponseMessage();
            int filelength = c.getContentLength();
            input = c.getInputStream();
            output = new FileOutputStream(this.output + this.file);
            byte data[] = new byte[4096];
            long total = 0;
            int count;
            while ((count = input.read(data)) != -1) {
                total += count;
                if (filelength > 0)
                    publishProgress((int) (total * 100 / filelength));
                output.write(data, 0, count);
            }
        } catch (Exception e) {
            return e.toString();
        } finally {
            try {
                if (output != null) output.close();
                if (input != null) input.close();
            } catch (IOException e) {
            }
            if (c != null) c.disconnect();
        }

        return null;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
        wakeLock.acquire();
        pDialog.show();
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
        super.onProgressUpdate(progress);
        pDialog.setIndeterminate(false);
        pDialog.setMax(100);
        pDialog.setProgress(progress[0]);
    }

    @Override
    protected void onPostExecute(String result) {
        wakeLock.release();
        pDialog.dismiss();
        if (result != null)
            Toast.makeText(context, "Download error: " + result, Toast.LENGTH_LONG).show();
        else if (this.install) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + this.output + this.file), "application/vnd.android.package-archive");
            this.context.startActivity(intent);
        }
    }

}

这是错误的堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.lastboxusa.lastboxinstaller, PID: 3076
              android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///data/data/com.lastboxusa.lastboxinstaller/kodi.apk typ=application/vnd.android.package-acrhive }
                  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
                  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
                  at android.app.Activity.startActivityForResult(Activity.java:3424)
                  at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                  at android.app.Activity.startActivityForResult(Activity.java:3385)
                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
                  at android.app.Activity.startActivity(Activity.java:3627)
                  at android.app.Activity.startActivity(Activity.java:3595)
                  at com.lastboxusa.lastboxinstaller.MainActivity$DownloadTask.onPostExecute(MainActivity.java:136)
                  at com.lastboxusa.lastboxinstaller.MainActivity$DownloadTask.onPostExecute(MainActivity.java:59)
                  at android.os.AsyncTask.finish(AsyncTask.java:632)
                  at android.os.AsyncTask.access$600(AsyncTask.java:177)
                  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5017)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                  at dalvik.system.NativeStart.main(Native Method)

推荐答案

问题与 apk 的名称不是原始名称有关.将其重命名为原来的名称有效.

The problem had to do with the fact that the name of the apk was not the original. Renaming it to its original name worked.

这篇关于没有找到处理意图的活动 (act=android.intent.action.VIEW) 尝试安装 APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆