Monday, 19 August 2013

Install apk file progrmatically

Install apk file progrmatically

I have downloaded apk file from localhost server using download Manager
api and also displaying which i have downloaded file but the thing is if i
click that .apk file, unable to install,it is give parsing package error.
This is my xml page
<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>
and here my code
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);
}
what are the procdure there to install apk file which is there in
downloadmanager? please suggest me, Thanks in advance. sorry for my
grammer mistake.

No comments:

Post a Comment