以编程方式安装apk文件

时间:2013-08-20 05:31:33

标签: android android-emulator

我已经使用下载管理器api从localhost服务器下载了apk文件,并且还显示了我已经下载了文件,但事情是如果我点击.apk文件,无法安装,则会给出解析包错误。 这是我的xml页面

 <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClick"
        android:text="Start Download" >
    </Button>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showDownload"
        android:text="View Downloads" >
    </Button>

这里是我的代码

BroadcastReceiver broad = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            String action = intent.getAction();

            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(
                        DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                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)) {

                        // ImageView view = (ImageView)
                        // findViewById(R.id.imageView1);
                        final String uriString = c
                                .getString(c
                                        .getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        // search.setImageURI(Uri.parse(uriString));

                    }
                }
            }
        }

    };

    registerReceiver(broad, new IntentFilter(
            DownloadManager.ACTION_DOWNLOAD_COMPLETE));
public void showDownload(View view) {
    Intent i = new Intent();
    i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
    startActivity(i);
}

安装apk文件的程序是什么,在downloadmanager中有哪些?

0 个答案:

没有答案