0

I am trying to install a non-market app in Android. It is downloaded in: file:///mnt/sdcard/Download/App.apk

What I am doing is:

Intent promptInstall = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(uriString)).setType("application/vnd.android.package-archive");
startActivity(promptInstall);

where uriString is : file:///mnt/sdcard/Download/App.apk.

But there is an exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=application/vnd.android.package-archive }

EDIT

I am downloading the app using DownloadManager:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(Uri.parse(MY_PATH_TP_APK));
Request req.setTitle("Test")
       .setDescription("Something useful.")
       .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "App.apk");
long enqueue = dm.enqueue(req);

After downloading:

_receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            Query query = new Query();
            query.setFilterById(enqueue);
            Cursor c = dm.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                    String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    Intent promptInstall = new  Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse(uriString))
                    .setType("application/vnd.android.package-archive");
                    startActivity(promptInstall);
                }
            }
        }
    }
};

How to fix it?

4

2 に答える 2

3

アプリの 1 つでこのコードを使用していますが、正常に動作しています。

Uri fileUri = Uri.fromFile(new File("/mnt/sdcard/Download", "App.apk"));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, "application/vnd.android.package-archive");
startActivity(intent);

コードに 1 つのスラッシュが多すぎる可能性があります (file://mnt ではなく file:///mnt (ここではわかりません))。

于 2012-06-21T06:34:57.557 に答える
1

交換

String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));

と:

c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
于 2012-07-29T04:05:43.147 に答える