Java Code Examples for android.content.Intent#getLongArrayExtra()

The following examples show how to use android.content.Intent#getLongArrayExtra() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteNotificationReceiver.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
  if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) {
    ApplicationDependencies.getMessageNotifier().clearReminder(context);

    final long[]    ids = intent.getLongArrayExtra(EXTRA_IDS);
    final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS);

    if (ids == null  || mms == null || ids.length != mms.length) return;

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        for (int i=0;i<ids.length;i++) {
          if (!mms[i]) DatabaseFactory.getSmsDatabase(context).markAsNotified(ids[i]);
          else         DatabaseFactory.getMmsDatabase(context).markAsNotified(ids[i]);
        }

        return null;
      }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  }
}
 
Example 2
Source File: MarkReadReceiver.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) {
    if (!CLEAR_ACTION.equals(intent.getAction()))
        return;

    final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

    if (threadIds != null) {
        NotificationManagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));
        AmeDispatcher.INSTANCE.getIo().dispatch(() -> {
            List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
            for (long threadId : threadIds) {
                ALog.d(TAG, "Marking as read: " + threadId);
                List<MarkedMessageInfo> messageIds = Repository.getThreadRepo(AMELogin.INSTANCE.getMajorContext()).setRead(threadId, true);
                messageIdsCollection.addAll(messageIds);
            }
            process(context, AMELogin.INSTANCE.getMajorContext(), messageIdsCollection);
            return Unit.INSTANCE;
        });
    }
}
 
Example 3
Source File: ShareActivity.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
private void handleResolvedMedia(Intent intent, boolean animate) {
  long   threadId         = intent.getLongExtra(EXTRA_THREAD_ID, -1);
  long[] recipientIds     = intent.getLongArrayExtra(EXTRA_RECIPIENT_IDS);
  int    distributionType = intent.getIntExtra(EXTRA_DISTRIBUTION_TYPE, -1);

  boolean hasResolvedDestination = threadId != -1 && recipientIds != null && distributionType != -1;

  if (!hasResolvedDestination && animate) {
    ViewUtil.fadeIn(fragmentContainer, 300);
    ViewUtil.fadeOut(progressWheel, 300);
  } else if (!hasResolvedDestination) {
    fragmentContainer.setVisibility(View.VISIBLE);
    progressWheel.setVisibility(View.GONE);
  } else {
    createConversation(threadId, RecipientFactory.getRecipientsForIds(this, recipientIds, true), distributionType);
  }
}
 
Example 4
Source File: DeleteNotificationReceiver.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
  if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) {
    MessageNotifier.clearReminder(context);

    final long[]    ids = intent.getLongArrayExtra(EXTRA_IDS);
    final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS);

    if (ids == null  || mms == null || ids.length != mms.length) return;

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        for (int i=0;i<ids.length;i++) {
          if (!mms[i]) DatabaseFactory.getSmsDatabase(context).markAsNotified(ids[i]);
          else         DatabaseFactory.getMmsDatabase(context).markAsNotified(ids[i]);
        }

        return null;
      }
    }.execute();
  }
}
 
Example 5
Source File: DownloadBroadcastReceiver.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called to open a given download item that is downloaded by the android DownloadManager.
 * @param context Context of the receiver.
 * @param intent Intent from the android DownloadManager.
 */
private void openDownload(final Context context, Intent intent) {
    long ids[] =
            intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
    if (ids == null || ids.length == 0) {
        DownloadManagerService.openDownloadsPage(context);
        return;
    }
    long id = ids[0];
    DownloadManager manager =
            (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    Uri uri = manager.getUriForDownloadedFile(id);
    if (uri == null) {
        // Open the downloads page
        DownloadManagerService.openDownloadsPage(context);
    } else {
        Intent launchIntent = new Intent(Intent.ACTION_VIEW);
        launchIntent.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(id));
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            context.startActivity(launchIntent);
        } catch (ActivityNotFoundException e) {
            DownloadManagerService.openDownloadsPage(context);
        }
    }
}
 
Example 6
Source File: DownloadBroadcastReceiver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called to open a given download item that is downloaded by the android DownloadManager.
 * @param context Context of the receiver.
 * @param intent Intent from the android DownloadManager.
 */
private void openDownload(final Context context, Intent intent) {
    long ids[] =
            intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
    if (ids == null || ids.length == 0) {
        DownloadManagerService.openDownloadsPage(context);
        return;
    }
    long id = ids[0];
    Uri uri = DownloadManagerDelegate.getContentUriFromDownloadManager(context, id);
    if (uri == null) {
        // Open the downloads page
        DownloadManagerService.openDownloadsPage(context);
    } else {
        String downloadFilename = IntentUtils.safeGetStringExtra(
                intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH);
        boolean isSupportedMimeType =  IntentUtils.safeGetBooleanExtra(
                intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false);
        Intent launchIntent = DownloadManagerService.getLaunchIntentFromDownloadId(
                context, downloadFilename, id, isSupportedMimeType);
        if (!DownloadUtils.fireOpenIntentForDownload(context, launchIntent)) {
            DownloadManagerService.openDownloadsPage(context);
        }
    }
}
 
Example 7
Source File: DeleteActivity.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  setResult(RESULT_CANCELED);
  
  Intent intent = getIntent();
  long[] trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);

  Object retained = getLastNonConfigurationInstance();
  if (retained instanceof DeleteAsyncTask) {
    deleteAsyncTask = (DeleteAsyncTask) retained;
    deleteAsyncTask.setActivity(this);
  } else {
    deleteAsyncTask = new DeleteAsyncTask(this, trackIds);
    deleteAsyncTask.execute();
  }
}
 
Example 8
Source File: AndroidAutoHeardReceiver.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent)
{
  if (!HEARD_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1);
    NotificationManagerCompat.from(context).cancel(notificationId);

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();

        for (long threadId : threadIds) {
          Log.i(TAG, "Marking meassage as read: " + threadId);
          List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);

          messageIdsCollection.addAll(messageIds);
        }

        ApplicationDependencies.getMessageNotifier().updateNotification(context);
        MarkReadReceiver.process(context, messageIdsCollection);

        return null;
      }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  }
}
 
Example 9
Source File: DownloadBroadcastReceiver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called to open a particular download item.  Falls back to opening Download Home.
 * @param context Context of the receiver.
 * @param intent Intent from the android DownloadManager.
 */
private void openDownload(final Context context, Intent intent) {
    int notificationId = IntentUtils.safeGetIntExtra(
            intent, NotificationConstants.EXTRA_NOTIFICATION_ID, -1);
    DownloadNotificationService.hideDanglingSummaryNotification(context, notificationId);

    long ids[] =
            intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
    if (ids == null || ids.length == 0) {
        DownloadManagerService.openDownloadsPage(context);
        return;
    }

    long id = ids[0];
    Uri uri = DownloadManagerDelegate.getContentUriFromDownloadManager(context, id);
    if (uri == null) {
        DownloadManagerService.openDownloadsPage(context);
        return;
    }

    String downloadFilename = IntentUtils.safeGetStringExtra(
            intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH);
    boolean isSupportedMimeType =  IntentUtils.safeGetBooleanExtra(
            intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false);
    boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra(
            intent, DownloadNotificationService.EXTRA_IS_OFF_THE_RECORD, false);
    ContentId contentId = DownloadNotificationService.getContentIdFromIntent(intent);
    DownloadManagerService.openDownloadedContent(
            context, downloadFilename, isSupportedMimeType, isOffTheRecord, contentId.id, id);
}
 
Example 10
Source File: AndroidAutoHeardReceiver.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onReceive(final Context context, Intent intent,
                         @Nullable final MasterSecret masterSecret)
{
  if (!HEARD_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1);
    NotificationManagerCompat.from(context).cancel(notificationId);

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        for (long threadId : threadIds) {
          Log.i(TAG, "Marking message as read: " + threadId);
          DatabaseFactory.getThreadDatabase(context).setRead(threadId);
          //DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
        }

        MessageNotifier.updateNotification(context, masterSecret);
        return null;
      }
    }.execute();
  }
}
 
Example 11
Source File: MarkReadReceiver.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onReceive(final Context context, Intent intent,
                         @Nullable final MasterSecret masterSecret)
{
  if (!CLEAR_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    NotificationManagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        for (long threadId : threadIds) {
          Log.w(TAG, "Marking as read: " + threadId);
          DatabaseFactory.getThreadDatabase(context).setRead(threadId);
          DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
        }

        MessageNotifier.updateNotification(context, masterSecret);
        return null;
      }
    }.execute();
  }
}
 
Example 12
Source File: DownloadReceiver.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    DownloadManager manager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
    if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())){
        DownloadManager.Query query = new DownloadManager.Query();
        //在广播中取出下载任务的id
        long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
        query.setFilterById(id);
        Cursor c = manager.query(query);
        if(c.moveToFirst()) {
            //获取文件下载路径
            String filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
            //如果文件名不为空,说明已经存在了,拿到文件名想干嘛都好
            if(filename != null){
                File file  = new File(filename);
                Intent anotherIntent = new Intent();
                anotherIntent.addFlags(anotherIntent.FLAG_ACTIVITY_NEW_TASK);
                anotherIntent.setAction(android.content.Intent.ACTION_VIEW);
                anotherIntent.setDataAndType(Uri.fromFile(file),
                        "application/vnd.android.package-archive");
                context.startActivity(anotherIntent);
            }
        }
    }else if(DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(intent.getAction())){
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        //点击通知栏取消下载
        manager.remove(ids);
        //ShowToastUtil.showShortToast(context, "已经取消下载");
    }

}
 
Example 13
Source File: QifExportOptions.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
public static QifExportOptions fromIntent(Intent data) {
    WhereFilter filter = WhereFilter.fromIntent(data);
    Currency currency = CurrencyExportPreferences.fromIntent(data, "qif");
    String dateFormat = data.getStringExtra(QifExportActivity.QIF_EXPORT_DATE_FORMAT);
    long[] selectedAccounts = data.getLongArrayExtra(QifExportActivity.QIF_EXPORT_SELECTED_ACCOUNTS);
    boolean uploadToDropbox = data.getBooleanExtra(QifExportActivity.QIF_EXPORT_UPLOAD_TO_DROPBOX, false);
    return new QifExportOptions(currency, dateFormat, selectedAccounts, filter, uploadToDropbox);
}
 
Example 14
Source File: MarkReadReceiver.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
  if (!CLEAR_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    NotificationManagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));

    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();

        for (long threadId : threadIds) {
          Log.i(TAG, "Marking as read: " + threadId);
          List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
          messageIdsCollection.addAll(messageIds);
        }

        process(context, messageIdsCollection);

        ApplicationDependencies.getMessageNotifier().updateNotification(context);

        return null;
      }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  }
}
 
Example 15
Source File: SaveActivity.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Intent intent = getIntent();
  trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
  trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
  playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);

  if (!FileUtils.isExternalStorageWriteable()) {
    Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
    finish();
    return;
  }

  File directory = playTrack ? new File(getCacheDir(), FileUtils.PLAY_TRACKS_DIR)
      : new File(FileUtils.getPath(trackFileFormat.getExtension()));
  if (!FileUtils.ensureDirectoryExists(directory)) {
    Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
    finish();
    return;
  }

  if (playTrack) {
    for (File file : directory.listFiles()) {
      file.delete();
    }
  }

  directoryDisplayName = playTrack ? directory.getName()
      : FileUtils.getPathDisplayName(trackFileFormat.getExtension());

  Object retained = getLastNonConfigurationInstance();
  if (retained instanceof SaveAsyncTask) {
    saveAsyncTask = (SaveAsyncTask) retained;
    saveAsyncTask.setActivity(this);
  } else {
    saveAsyncTask = new SaveAsyncTask(this, trackIds, trackFileFormat, playTrack, directory);
    saveAsyncTask.execute();
  }
}
 
Example 16
Source File: IntentUtil.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
public static long[] getLongArrayExtra(Intent intent, String name) {
    if (!hasIntent(intent) || !hasExtra(intent, name)) return null;
    return intent.getLongArrayExtra(name);
}
 
Example 17
Source File: GpgEncryptionParamsFragment.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
private void handleActivityResult() {
    if (mTempActivityResult != null) {
        int requestCode = mTempActivityResult.getRequestCode();
        int resultCode = mTempActivityResult.getResultCode();
        Intent data = mTempActivityResult.getData();
        mTempActivityResult = null;


        if (requestCode == EncryptionParamsActivityContract.REQUEST_CODE_DOWNLOAD_KEY) {
            if (resultCode == Activity.RESULT_OK) {
                handleDownloadedKey(getActivity(), mTempDownloadKeyId, data);
            } else {
                // Ln.w("user cancelled pendingintent activity");
            }
        } else if (requestCode == EncryptionParamsActivityContract.REQUEST_CODE_RECIPIENT_SELECTION) {
            if (resultCode == Activity.RESULT_OK) {
                if (data != null) {
                    if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS) || data.hasExtra("key_ids_selected"/*OpenPgpApi.EXTRA_KEY_IDS_SELECTED*/)) {
                        long[] keyIds = new long[0];
                        if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) {
                            keyIds = data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
                        } else if (data.hasExtra("key_ids_selected"/*OpenPgpApi.EXTRA_KEY_IDS_SELECTED*/)) {
                            keyIds = data.getLongArrayExtra("key_ids_selected"/*OpenPgpApi.EXTRA_KEY_IDS_SELECTED*/);
                        }
                        //not sure why Anal Studio / Gradle can't find the new EXTRA_KEY_IDS_SELECTED constant
                        //also not sure why they had to change it, but well, need to check for both

                        Long[] keys = new Long[keyIds.length];
                        for (int i = 0; i < keyIds.length; i++) {
                            keys[i] = keyIds[i];
                        }
                        if (keyIds != null && keyIds.length > 0) {

                            mEditorPgpEncryptionParams.addPublicKeyIds(keys, getGpgEncryptionHandler(getActivity()).getGpgOwnPublicKeyId());
                            updatePgpRecipientsList();
                        }
                    } else {
                        triggerRecipientSelection(EncryptionParamsActivityContract.REQUEST_CODE_RECIPIENT_SELECTION, data);
                    }
                } else {
                    //Ln.w("REQUEST_CODE_RECIPIENT_SELECTION returned without data");
                }

            } else {
                // Ln.w("REQUEST_CODE_RECIPIENT_SELECTION returned with result code %s" , resultCode);
            }
        } else if (requestCode == EncryptionParamsActivityContract.REQUEST_CODE_OWNSIGNATUREKEY_SELECTION) {
            if (resultCode == Activity.RESULT_OK) {
                if (data != null) {
                    if (data.hasExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
                        long signKeyId = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
                        mEditorPgpEncryptionParams.setOwnPublicKey(signKeyId);
                        getGpgEncryptionHandler(getActivity()).setGpgOwnPublicKeyId(signKeyId);
                        updatePgpOwnKey();
                        updatePgpRecipientsList();

                    } else {
                        triggerSigningKeySelection(data);
                    }
                } else {
                    // Ln.w("ACTION_GET_SIGN_KEY_ID returned without data");
                }

            } else {
                //   Ln.w("ACTION_GET_SIGN_KEY_ID returned with result code %s", resultCode);
            }
        }
    }
}
 
Example 18
Source File: DownloadCompleteReveiver.java    From WayHoo with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();

	if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
		long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
		if (id == Preferences.getDownloadId(context)) {
			Query query = new Query();
			query.setFilterById(id);
			downloadManager = (DownloadManager) context
					.getSystemService(Context.DOWNLOAD_SERVICE);
			Cursor cursor = downloadManager.query(query);

			int columnCount = cursor.getColumnCount();
			String path = null;
			while (cursor.moveToNext()) {
				for (int j = 0; j < columnCount; j++) {
					String columnName = cursor.getColumnName(j);
					String string = cursor.getString(j);
					if ("local_uri".equals(columnName)) {
						path = string;
					}
				}
			}
			cursor.close();

			if (path != null) {
				Preferences.setDownloadPath(context, path);
				Preferences.setDownloadStatus(context, -1);
				Intent installApkIntent = new Intent();
				installApkIntent.setAction(Intent.ACTION_VIEW);
				installApkIntent.setDataAndType(Uri.parse(path),
						"application/vnd.android.package-archive");
				installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
						| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
				context.startActivity(installApkIntent);
			}
		}
	} else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
		long[] ids = intent
				.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
		if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) {
			Intent downloadIntent = new Intent();
			downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
			downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
					| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
			context.startActivity(downloadIntent);
		}
	}
}
 
Example 19
Source File: DownloadCompleteReveiver.java    From WayHoo with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();

	if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
		long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
		if (id == Preferences.getDownloadId(context)) {
			Query query = new Query();
			query.setFilterById(id);
			downloadManager = (DownloadManager) context
					.getSystemService(Context.DOWNLOAD_SERVICE);
			Cursor cursor = downloadManager.query(query);

			int columnCount = cursor.getColumnCount();
			String path = null;
			while (cursor.moveToNext()) {
				for (int j = 0; j < columnCount; j++) {
					String columnName = cursor.getColumnName(j);
					String string = cursor.getString(j);
					if ("local_uri".equals(columnName)) {
						path = string;
					}
				}
			}
			cursor.close();

			if (path != null) {
				Preferences.setDownloadPath(context, path);
				Preferences.setDownloadStatus(context, -1);
				Intent installApkIntent = new Intent();
				installApkIntent.setAction(Intent.ACTION_VIEW);
				installApkIntent.setDataAndType(Uri.parse(path),
						"application/vnd.android.package-archive");
				installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
						| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
				context.startActivity(installApkIntent);
			}
		}
	} else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
		long[] ids = intent
				.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
		if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) {
			Intent downloadIntent = new Intent();
			downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
			downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
					| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
			context.startActivity(downloadIntent);
		}
	}
}