下面列出了android.content.Intent#getLongArrayExtra ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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;
});
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
@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();
}
}
@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();
}
}
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);
}
}
@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);
}
}
@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);
}
}
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);
}
@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, "已经取消下载");
}
}
@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();
}
}
@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();
}
}
/**
* 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);
}
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);
}
}
}
}
public static long[] getLongArrayExtra(Intent intent, String name) {
if (!hasIntent(intent) || !hasExtra(intent, name)) return null;
return intent.getLongArrayExtra(name);
}
@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();
}
}
@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);
}
}
}
@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);
}
}
}