@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); List<Long> ids = AppSharePreferences.getDownloadIds(context); if (ids == null || !ids.contains(downId)) return; AppSharePreferences.deleteDownloadId(context, downId); DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = manager.query(new DownloadManager.Query().setFilterById(downId)); if (c == null || !c.moveToFirst()) return; String url = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); if (TextUtils.isEmpty(url)) { AppUtils.showToast(context, getResources().getString(R.string.download_fail) + "!"); return; } Uri uri = Uri.parse(url); c.close(); Intent i = new Intent(); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setAction("android.intent.action.VIEW"); i.addCategory("android.intent.category.DEFAULT"); i.setType("application/vnd.android.package-archive"); i.setData(uri); i.setDataAndType(uri, "application/vnd.android.package-archive"); startActivity(i); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == 30) { // 接受数据 int resu = getActivity().getIntent().getIntExtra("111", 0); AppUtils.showToast(getActivity(), resu + ""); } super.onActivityResult(requestCode, resultCode, data); }
@Override public void onBackPressed() { if (System.currentTimeMillis() - exitTime > 1500) { AppUtils.showToast(getApplicationContext(), getString(R.string.exit_message)); exitTime = System.currentTimeMillis(); return; } exitWithUserOption = true; finish(); }