deprecated

This commit is contained in:
Jerry Yan 2020-02-27 20:56:19 +08:00
parent cd57ea3243
commit d0e87b7258

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import java.io.File;
@ -21,19 +22,19 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
Intent install = new Intent(Intent.ACTION_VIEW);
DownloadManager.Query queryById = new DownloadManager.Query();
queryById.setFilterById(currentDownloadId);
Cursor downloadCursor = downloadManager.query(queryById);
Cursor cursor = downloadManager.query(queryById);
String filePath = null;
if(downloadCursor.moveToFirst()){
if(downloadCursor.getInt(downloadCursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL){
int fileNameIdx = downloadCursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
filePath = downloadCursor.getString(fileNameIdx);
if(cursor.moveToFirst()){
if(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL){
filePath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
}else{
downloadManager.remove(currentDownloadId);
downloadCursor.close();
cursor.close();
return;
}
downloadCursor.close();
cursor.close();
}
Log.i("FilePath",filePath);
if(filePath == null) return;
File file = new File(filePath);
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");