List of usage examples for android.content Intent setAction
public @NonNull Intent setAction(@Nullable String action)
From source file:chat.client.agent.ChatClientAgent.java
private void notifyParticipantsChanged() { Intent broadcast = new Intent(); broadcast.setAction("jade.demo.chat.REFRESH_PARTICIPANTS"); logger.log(Level.INFO, "Sending broadcast " + broadcast.getAction()); context.sendBroadcast(broadcast);// w w w . ja v a 2 s. c o m }
From source file:chat.client.agent.ChatClientAgent.java
private void notifySpoken(String speaker, String sentence) { Intent broadcast = new Intent(); broadcast.setAction("jade.demo.chat.REFRESH_CHAT"); broadcast.putExtra("sentence", speaker + ": " + sentence + "\n"); logger.log(Level.INFO, "Sending broadcast " + broadcast.getAction()); context.sendBroadcast(broadcast);/*from w ww .j av a 2 s. com*/ }
From source file:pffy.mobile.flax.FlaxActivity.java
private boolean sendDetailsByIntent() { if (this.mExportFacts.equals("") || this.mExportFacts == null) { // do not send empty files return false; }/*from w ww. j a v a 2 s . c o m*/ // boilerplate intent code Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, this.mExportFacts); sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.msg_shareto))); return true; }
From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java
void selectItem(int position) { Intent intent = new Intent(); String id = ids.get(position); intent.putExtra("imageCall", "3/album/" + id); intent.putExtra("id", id); intent.setAction(ImgurHoloActivity.IMAGES_INTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent);//from w w w. j a v a 2 s. c o m }
From source file:com.kii.cloud.sync.DownloadManager.java
/** * Download KiiFile./*from w ww. java 2 s . co m*/ * * @param destFile * - specifiy where the downloaded file is saved. * @param srcFile * - KiiFile to be downloaded * @param overwrite * - specifiy if overwrite the destination file. * @throws IOException */ private void downloadKiiFile(File destFile, KiiFile srcFile, boolean overwrite) throws IOException { boolean result = true; InputStream input = null; FileOutputStream fos = null; BufferedOutputStream bos = null; File tempDest = null; try { // check for valid URL String remotePath = srcFile.getRemotePath(); if (remotePath == null) { Log.e(TAG, "remotePath is empty"); throw new IllegalArgumentException("HTTP download URL is empty"); } Log.d(TAG, "downloadKiiFile, remotePath is " + remotePath); // check if the destinated file exist // if yes, check if overwrite permitted if (destFile.exists()) { if (!overwrite) { throw new IllegalArgumentException("File already exist:" + destFile.getAbsolutePath()); } } // check if the destinated folder exist // if not, create the folder File destFolder = destFile.getParentFile(); if (destFolder == null) { throw new IllegalArgumentException("Cannot create folder for file: " + destFile); } if (!destFolder.exists()) { destFolder.mkdirs(); } // send notification that download in progress if (mContext != null) { Intent intent = new Intent(); intent.setAction(ACTION_DOWNLOAD_START); intent.putExtra(DOWNLOAD_DEST_PATH, destFile.getAbsolutePath()); mContext.sendBroadcast(intent); Intent progressIntent = new Intent(mContext.getApplicationContext(), ProgressListActivity.class); NotificationUtil.showDownloadProgressNotification(mContext.getApplicationContext(), progressIntent, destFile.getAbsolutePath()); } // create a temp file for download the file tempDest = new File(destFile.getAbsoluteFile() + "." + Long.toString(System.currentTimeMillis())); HttpGet httpGet = new HttpGet(remotePath); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != 200) { throw new IOException( "Code: " + statusLine.getStatusCode() + "; Reason:" + statusLine.getReasonPhrase()); } HttpEntity entity = response.getEntity(); if (entity == null) { throw new IOException("Cannot read file content."); } input = entity.getContent(); fos = new FileOutputStream(tempDest); bos = new BufferedOutputStream(fos); int len = -1; byte[] buffer = new byte[1024]; // download the file by batch while ((len = input.read(buffer)) > 0) { bos.write(buffer, 0, len); downloadCurrentSize += len; } // delete the existing if it exist if (destFile.exists()) { destFile.delete(); } if (tempDest.exists()) { Log.d(TAG, "Download file: s=" + tempDest.length() + "; d=" + tempDest.lastModified()); // rename the download file to it original file if (!tempDest.renameTo(destFile)) { throw new IllegalArgumentException("Failed to rename:" + tempDest.getAbsolutePath()); } // TODO: the download is success, update the kiifile status; // after rename, create a new file handler tempDest = new File(destFile.getAbsolutePath()); // check if the file exists if (tempDest.exists()) { if (tempDest.setLastModified(srcFile.getUpdateTime()) == false) { // on some Galaxy phones, it will fail, we simply ignore // this error and print an error log Log.e(TAG, "Failed to restore:" + tempDest.getAbsolutePath()); } } else { throw new IllegalArgumentException( "Failed to restore, file not exist after rename:" + tempDest.getAbsolutePath()); } } else { throw new IllegalArgumentException( "Failed to restore, file not exist after dnload:" + tempDest.getAbsolutePath()); } } catch (IllegalArgumentException ex) { if (mContext != null) { Intent intent = new Intent(); intent.setAction(ACTION_DOWNLOAD_START); intent.putExtra(DOWNLOAD_DEST_PATH, destFile.getAbsolutePath()); mContext.sendBroadcast(intent); Intent progressIntent = new Intent(mContext.getApplicationContext(), ProgressListActivity.class); NotificationUtil.showDownloadProgressNotification(mContext.getApplicationContext(), progressIntent, ex.getMessage()); result = false; } throw new IOException("IllegalArgumentException:" + ex.getMessage()); } finally { Utils.closeSilently(bos); Utils.closeSilently(fos); Utils.closeSilently(input); if (mContext != null) { Intent intent = new Intent(); intent.setAction(ACTION_DOWNLOAD_END); intent.putExtra(DOWNLOAD_DEST_PATH, destFile.getAbsolutePath()); intent.putExtra(DOWNLOAD_RESULT, result); mContext.sendBroadcast(intent); // cancel the notification if no error if (result) { NotificationUtil.cancelDownloadProgressNotification(mContext); } else { // delete the temp file if error exist if ((tempDest != null) && tempDest.exists()) { tempDest.delete(); } } KiiSyncClient.getInstance(mContext).notifyKiiFileLocalChange(); // force the system to run a media scan MediaScannerConnection.scanFile(mContext, new String[] { destFile.getAbsolutePath() }, null, null); } } }
From source file:com.concentricsky.android.khanacademy.data.KADataService.java
private void broadcastLibraryUpdateNotification() { Intent intent = new Intent(); intent.setAction(ACTION_LIBRARY_UPDATE); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:org.openintents.updatechecker.UpdateChecker.java
public void parseVeeCheck(String uri) { VeecheckResult result = null;//from ww w . j ava2 s. c o m try { VeecheckVersion version = new VeecheckVersion(mPackageName, String.valueOf(mCurrentVersion), mCurrentVersionName); try { result = performRequest(version, uri); } catch (Exception e) { Log.v(LOG_TAG, "Failed to process versions.", e); return; } finally { } if (result.matched) { Log.d(LOG_TAG, "Matching intent found."); if (result.latestVersion.getVersionCode() != null) { try { mLatestVersion = Integer.parseInt(result.latestVersion.getVersionCode()); } catch (NumberFormatException e) { mLatestVersion = 0; } } else { mLatestVersion = 0; } mLatestVersionName = result.latestVersion.getVersionName(); mComment = null; // create intent Intent intent = new Intent(); if (Intent.ACTION_VIEW.equals(result.action)) { intent.setAction(result.action); if (result.data != null) { Uri intentUri = Uri.parse(result.data); if (result.type != null) { intent.setDataAndType(intentUri, result.type); } else { intent.setData(intentUri); } } else { if (result.type != null) { intent.setType(result.type); } } if (result.extras != null) { for (Entry<String, String> e : result.extras.entrySet()) { intent.putExtra(e.getKey(), e.getValue()); } } ResolveInfo info = mContext.getPackageManager().resolveActivity(intent, 0); if (info != null) { mUpdateIntent = intent; } } else { Log.v(TAG, "no view action but " + result.action); } } else { result = null; Log.d(LOG_TAG, "No matching intent found."); } } finally { } }
From source file:com.krayzk9s.imgurholo.services.UploadService.java
public void onGetObject(Object o, String tag) { String id = (String) o; if (id.length() == 7) { if (totalUpload != -1) ids.add(id);/*from w w w . java 2 s . co m*/ if (ids.size() == totalUpload) { ids.add(0, ""); //weird hack because imgur eats the first item of the array for some bizarre reason NewAlbumAsync newAlbumAsync = new NewAlbumAsync("", "", apiCall, ids, this); newAlbumAsync.execute(); } } else if (apiCall.settings.getBoolean("AlbumUpload", true)) { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); Intent viewImageIntent = new Intent(); viewImageIntent.setAction(Intent.ACTION_VIEW); viewImageIntent.setData(Uri.parse("http://imgur.com/a/" + id)); Intent shareIntent = new Intent(); shareIntent.setType("text/plain"); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + id); PendingIntent viewImagePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), shareIntent, 0); Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated) .setContentText("Finished Uploading Album").setContentTitle("imgur Image Uploader") .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, "Share", sharePendingIntent).build(); Log.d("Built", "Notification built"); notificationManager.cancel(0); notificationManager.notify(1, notification); Log.d("Built", "Notification display"); } else { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated) .setContentText("Finished Uploading All Images").setContentTitle("imgur Image Uploader") .build(); Log.d("Built", "Notification built"); notificationManager.cancel(0); notificationManager.notify(1, notification); Log.d("Built", "Notification display"); } }
From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java
private void cancelAlarm(String action) { Intent i = new Intent(this, getClass()); i.setAction(action); PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pi);/*from ww w . j a v a 2 s .c o m*/ } }
From source file:com.openerp.services.MessageSyncService.java
/** * Perform sync./* w ww . ja v a 2 s . com*/ * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateWidgetIntent.putExtra(MessageWidget.ACTION_MESSAGE_WIDGET_UPDATE, true); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { MessageDB msgDb = new MessageDB(context); msgDb.setAccountUser(user); OEHelper oe = msgDb.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); newContext.put("default_model", "res.users"); newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : ids arguments.addNull(); // Param 2 : domain OEDomain domain = new OEDomain(); // Data limit. PreferenceManager mPref = new PreferenceManager(context); int data_limit = mPref.getInt("sync_data_limit", 60); domain.add("create_date", ">=", OEDate.getDateBefore(data_limit)); if (!extras.containsKey("group_ids")) { // Last id JSONArray msgIds = new JSONArray(); for (OEDataRow row : msgDb.select()) { msgIds.put(row.getInt("id")); } domain.add("id", "not in", msgIds); domain.add("|"); // Argument for check partner_ids.user_id is current user domain.add("partner_ids.user_ids", "in", new JSONArray().put(user_id)); domain.add("|"); // Argument for check notification_ids.partner_ids.user_id // is // current user domain.add("notification_ids.partner_id.user_ids", "in", new JSONArray().put(user_id)); // Argument for check author id is current user domain.add("author_id.user_ids", "in", new JSONArray().put(user_id)); } else { JSONArray group_ids = new JSONArray(extras.getString("group_ids")); // Argument for group model check domain.add("model", "=", "mail.group"); // Argument for group model res id domain.add("res_id", "in", group_ids); } arguments.add(domain.getArray()); // Param 3 : message_unload_ids arguments.add(new JSONArray()); // Param 4 : thread_level arguments.add(true); // Param 5 : context arguments.add(oe.updateContext(newContext)); // Param 6 : parent_id arguments.addNull(); // Param 7 : limit arguments.add(50); List<Integer> ids = msgDb.ids(); if (oe.syncWithMethod("message_read", arguments)) { int affected_rows = oe.getAffectedRows(); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.messages_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.messages_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } List<Integer> updated_ids = updateOldMessages(msgDb, oe, user, ids); intent.putIntegerArrayListExtra("updated_ids", (ArrayList<Integer>) updated_ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); context.sendBroadcast(updateWidgetIntent); } }