List of usage examples for android.content Intent setFlags
public @NonNull Intent setFlags(@Flags int flags)
From source file:com.ubuntuone.android.files.service.UpDownService.java
public void onQuotaExceeded() { // Cancel all transfers. TransferUtils.setUploadsState(getContentResolver(), TransferState.FAILED); // Cancel retry alarm. Alarms.unregisterRetryFailedAlarm(); String title = "Insufficient storage space"; String text = "Select to buy more storage"; // Notify the user, suggest storage upgrade. Notification notification = new NotificationCompat.Builder(this).setOngoing(false).setTicker(title) .setSmallIcon(R.drawable.stat_u1_logo).setOnlyAlertOnce(true).setAutoCancel(true).getNotification(); final Intent intent = new Intent(UpDownService.this, PreferencesActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(PreferencesActivity.PURCHASE_STORAGE_SCREEN, 1); final PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), REQUEST_PURCHASE_SCREEN, intent, 0);/*from www. j a v a 2 s . co m*/ notification.setLatestEventInfo(UpDownService.this, title, text, pi); notificationManager.notify(R.id.stat_quota_exceeded_id, notification); hasQuotaExceeded = true; }
From source file:by.zatta.pilight.connection.ConnectionService.java
private static void makeNotification(NotificationType type, String message) { Intent main; Intent kill;// ww w.j a va 2 s . com PendingIntent sentBroadcast; PendingIntent startMainActivity; PendingIntent killService; String myDate = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); //Log.v(TAG, "setting notification: " + type.name() + " while current = " + mCurrentNotif.name()); if (type != mCurrentNotif) { //Log.v(TAG, "setting NEW notification: " + type.name()); sendMessageToUI(MSG_SET_STATUS, type.name()); switch (type) { case DESTROYED: builder = new Notification.Builder(ctx); builder.setSmallIcon(R.drawable.eye_black).setLargeIcon(bigPic(R.drawable.eye_black)) .setContentTitle(aCtx.getString(R.string.app_name)).setContentText(message); mCurrentNotif = NotificationType.DESTROYED; break; case CONNECTING: kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message).setDeleteIntent(killService).setSmallIcon(R.drawable.eye_trans) .setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.CONNECTING; break; case CONNECTED: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setContentIntent(startMainActivity) .setSmallIcon(R.drawable.eye_white).setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.CONNECTED; break; case FAILED: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle("pilight") .setContentText(aCtx.getString(R.string.noti_failed)).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.FAILED; break; case LOST_CONNECTION: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.LOST_CONNECTION; break; case UPDATE: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder = new Notification.Builder(ctx).setContentTitle(title[0]).setContentText(message) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(startMainActivity).setSmallIcon(R.drawable.eye_white) .setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.UPDATE; break; default: break; } } else { if (message != null) { if (message.contains("Stamp")) { String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder.setContentTitle(title[0]).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } else { builder.setContentTitle(myDate).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } } } mNotMan.notify(35, builder.build()); }
From source file:id.zelory.tanipedia.activity.TanyaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tanya); toolbar = (Toolbar) findViewById(R.id.anim_toolbar); setSupportActionBar(toolbar);//from w w w . j ava 2 s. c om getSupportActionBar().setDisplayHomeAsUpEnabled(true); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("Tanya Tani"); animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow); fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin); drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer); setUpNavDrawer(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.getMenu().getItem(2).setChecked(true); TextView nama = (TextView) navigationView.findViewById(R.id.nama); nama.setText(PrefUtils.ambilString(this, "nama")); TextView email = (TextView) navigationView.findViewById(R.id.email); email.setText(PrefUtils.ambilString(this, "email")); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); drawerLayout.closeDrawers(); Intent intent; switch (menuItem.getItemId()) { case R.id.cuaca: intent = new Intent(TanyaActivity.this, CuacaActivity.class); break; case R.id.berita: intent = new Intent(TanyaActivity.this, BeritaActivity.class); break; case R.id.tanya: return true; case R.id.harga: intent = new Intent(TanyaActivity.this, KomoditasActivity.class); break; case R.id.logout: PrefUtils.simpanString(TanyaActivity.this, "nama", null); intent = new Intent(TanyaActivity.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); return true; case R.id.tentang: intent = new Intent(TanyaActivity.this, TentangActivity.class); startActivity(intent); return true; default: return true; } startActivity(intent); finish(); return true; } }); recyclerView = (RecyclerView) findViewById(R.id.scrollableview); recyclerView.setHasFixedSize(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.addOnScrollListener(new MyRecyclerScroll() { @Override public void show() { fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); } @Override public void hide() { fab.animate().translationY(fab.getHeight() + fabMargin) .setInterpolator(new AccelerateInterpolator(2)).start(); } }); tanyaGambar = (ImageView) findViewById(R.id.tanya_gambar); tanyaGambar.setVisibility(View.GONE); fab = (FrameLayout) findViewById(R.id.myfab_main); fab.setVisibility(View.GONE); fabBtn = (ImageButton) findViewById(R.id.myfab_main_btn); View fabShadow = findViewById(R.id.myfab_shadow); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fabShadow.setVisibility(View.GONE); fabBtn.setBackground(getDrawable(R.drawable.ripple_accent)); } fabBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(TanyaActivity.this).title("TaniPedia").content("Kirim Pertanyaan") .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT) .input("Ketik pertanyaan anda disini!", null, false, new MaterialDialog.InputCallback() { @Override public void onInput(MaterialDialog dialog, CharSequence input) { try { pertanyaan = URLEncoder.encode(input.toString(), "UTF-8"); new KirimSoal().execute(); } catch (UnsupportedEncodingException e) { Snackbar.make(fabBtn, "Terjadi kesalahan, silahkan coba lagi!", Snackbar.LENGTH_LONG).show(); e.printStackTrace(); } } }).positiveColorRes(R.color.primary_dark).positiveText("Kirim") .cancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { } }).negativeColorRes(R.color.primary_dark).negativeText("Batal").show(); } }); fabButton = (FabButton) findViewById(R.id.determinate); fabButton.showProgress(true); new DownloadData().execute(); fabButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fabButton.showProgress(true); new DownloadData().execute(); } }); }
From source file:dk.ciid.android.infobooth.activities.SubscriptionFinalActivity.java
private void changeActivity(String activityName) { Intent openActivity = new Intent(activityName); openActivity.putExtra("isInDebugMode", isInDebugMode); openActivity.putExtra("selectedService", selectedService); openActivity.putExtra("serviceIdItems", serviceIdItems); openActivity.putExtra("serviceNameItems", serviceNameItems); openActivity.putExtra("serviceDescItems", serviceDescItems); openActivity.putExtra("voice1", voice1); openActivity.putExtra("voice2", voice2); openActivity.putExtra("voice3", voice3); openActivity.putExtra("voice4", voice4); openActivity.putExtra("voice5", voice5); openActivity.putExtra("voice6", voice6); openActivity.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); mediaPlayer.stop();/*from ww w.j av a 2 s. co m*/ mediaPlayer.release(); startActivity(openActivity); closeAccessory(); }
From source file:com.irccloud.android.activity.LoginActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_RESOLVE_ERROR) { mResolvingError = false;/*from w ww . j a va 2 s . c o m*/ if (resultCode == RESULT_OK) { if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) { mGoogleApiClient.connect(); } } } else if (requestCode == REQUEST_RESOLVE_CREDENTIALS) { if (resultCode == RESULT_OK && data.hasExtra(Credential.EXTRA_KEY)) { Credential c = data.getParcelableExtra(Credential.EXTRA_KEY); name.setText(c.getName()); email.setText(c.getId()); password.setText(c.getPassword()); loading.setVisibility(View.GONE); login.setVisibility(View.VISIBLE); loginHintClickListener.onClick(null); new LoginTask().execute((Void) null); } else { loading.setVisibility(View.GONE); login.setVisibility(View.VISIBLE); } } else if (requestCode == REQUEST_RESOLVE_SAVE_CREDENTIALS) { if (resultCode == RESULT_OK) { Log.e("IRCCloud", "Credentials result: OK"); } Intent i = new Intent(LoginActivity.this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); if (getIntent() != null) { if (getIntent().getData() != null) i.setData(getIntent().getData()); if (getIntent().getExtras() != null) i.putExtras(getIntent().getExtras()); } startActivity(i); finish(); } }
From source file:com.markupartist.sthlmtraveling.PlannerFragment.java
/** * Setup a search short cut.//from ww w . java 2 s. c o m * * @param startPoint * the start point * @param endPoint * the end point */ protected void onCreateShortCut(Site startPoint, Site endPoint, String name) { Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint, null, true); Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, getActivity(), RoutesActivity.class); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Then, set up the container intent (the response to the caller) Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.shortcut); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); // Now, return the result to the launcher getActivity().setResult(Activity.RESULT_OK, intent); getActivity().finish(); }
From source file:com.raceyourself.android.samsung.ProviderService.java
/** * //from www .j a v a2 s .c o m * @param connectedPeerId * @param channelId * @param data */ private void onDataAvailableOnChannel(String connectedPeerId, long channelId, String data) { Log.d(TAG, "Received message on channel " + channelId + " from peer " + connectedPeerId + ": " + data); SAModel response = null; ensureDeviceIsRegistered(); // decide what to do based on the message if (data.contains(SAModel.GPS_STATUS_REQ)) { ensureGps(); if (gpsTracker.hasPosition() && registered) { response = new GpsStatusResp(GpsStatusResp.GPS_READY); } else if (gpsTracker.isGpsEnabled()) { response = new GpsStatusResp(GpsStatusResp.GPS_ENABLED); } else { response = new GpsStatusResp(GpsStatusResp.GPS_DISABLED); if (System.currentTimeMillis() > lastGpsReqTimestamp + 3000) { popupGpsDialog(); // only popup on first poll (they happen every second at time of writing..) } lastGpsReqTimestamp = System.currentTimeMillis(); } } else if (data.contains(SAModel.START_TRACKING_REQ)) { startTracking(); } else if (data.contains(SAModel.STOP_TRACKING_REQ)) { stopTracking(); } else if (data.contains(SAModel.AUTHENTICATION_REQ)) { // usually called when the user launches the app on gear authorize(); trySync(); // Popup webview with user/passwd boxes //Intent authenticationIntent = new Intent (this, AuthenticationActivity.class); //authenticationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //authenticationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); //startActivity(authenticationIntent); } else if (data.contains(SAModel.LOG_ANALYTICS)) { try { JSONObject json = new JSONObject(data); Helper.logEvent(json.getString("value")); } catch (JSONException e) { Log.e(TAG, "Error parsing analytics event", e); } } else if (data.contains(SAModel.LOG_TO_ADB)) { try { JSONObject json = new JSONObject(data); String logLevel = json.getString("logLevel"); String logMessage = json.getString("logMessage"); if (logLevel.equals("VERBOSE")) Log.v(CONSUMER_TAG, logMessage); else if (logLevel.equals("DEBUG")) Log.d(CONSUMER_TAG, logMessage); else if (logLevel.equals("INFO")) Log.i(CONSUMER_TAG, logMessage); else if (logLevel.equals("WARNING")) Log.w(CONSUMER_TAG, logMessage); else if (logLevel.equals("ERROR")) Log.e(CONSUMER_TAG, logMessage); } catch (JSONException e) { Log.e(TAG, "Error parsing sap-to-adb message", e); } } else if (data.contains(SAModel.WEB_LINK_REQ)) { JSONObject json; try { json = new JSONObject(data); String uri = WebLinkReq.fromJSON(json).getUri(); launchWebBrowser(uri); } catch (JSONException e) { Log.e(TAG, "Error parsing WebLinkReq", e); } } else if (data.contains(SAModel.REMOTE_CONFIGURATION_REQ)) { RemoteConfiguration config = SyncHelper.get("configurations/gear", RemoteConfiguration.class); if (config != null) response = new RemoteConfigurationResp(config.configuration); } else if (data.contains(SAModel.SHARE_SCORE_REQ)) { ShareScoreReq req = null; try { req = ShareScoreReq.fromJSON(new JSONObject(data)); } catch (JSONException e) { Log.e(TAG, "Error parsing ShareHighscoreReq", e); } if (req != null) { String filenameFormat = "gear-score-%d-%d-%s"; String shareType = "score"; if (req.getHighscore() < req.getScore()) { filenameFormat = "gear-high-score-%d-%d-%s"; shareType = "highscore"; } String imageUrl = "http://shared.raceyourself.com/" + MD5(String.format(filenameFormat, req.getScore(), Math.max(req.getScore(), req.getHighscore()), req.getSubtext())) + ".jpg"; Helper.logEvent( String.format("{\"event_type\":\"share\", \"share_type\":\"%s\", \"service\":\"%s\"}", shareType, req.getScore())); if ("google+".equals(req.getService())) { String text = String.format(req.getScore() > 1 ? "I ran %d laps!" : "I ran %d lap", req.getScore()); if (req.getHighscore() < req.getScore()) text = "I got a new highscore! " + text; Intent shareIntent = new PlusShare.Builder(this).setType("text/plain") .setText(text + " #RaceYourself").setContentUrl(Uri.parse(imageUrl)).getIntent(); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent); } else if ("facebook".equals(req.getService())) { Intent customIntent = new Intent("com.raceyourself.intent.FACEBOOK_SHARE"); if (req.getHighscore() < req.getScore()) customIntent.putExtra("name", "New Highscore!"); else customIntent.putExtra("name", "Eliminated!"); customIntent.putExtra("caption", String.format(req.getScore() > 1 || req.getScore() == 0 ? "I survived %d laps of the Eliminator! Get the app free at http://www.raceyourself.com" : "I survived %d lap of the Eliminator! Get the app free at http://www.raceyourself.com", req.getScore())); // customIntent.putExtra("description", ""); customIntent.putExtra("picture", imageUrl); customIntent.putExtra("link", "https://www.raceyourself.com/gear"); customIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(customIntent); } else if ("twitter".equals(req.getService())) { String cardUrl = "http://shared.raceyourself.com/" + MD5(String.format(filenameFormat, req.getScore(), Math.max(req.getScore(), req.getHighscore()), req.getSubtext())) + ".html"; String text = String.format( req.getScore() > 1 || req.getScore() == 0 ? "I survived %d laps of the Eliminator!" : "I survived %d lap of the Eliminator!", req.getScore()); String url = String.format("https://twitter.com/intent/tweet?url=%s&text=%s&via=Race_Yourself", cardUrl, text); Intent shareIntent = new Intent(Intent.ACTION_VIEW); shareIntent.setData(Uri.parse(url)); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent); } else { Log.e(TAG, "onDataAvailableOnChannel: ShareHighScoreReq: Unknown service: " + req.getService()); } } } else { Log.e(TAG, "onDataAvailableOnChannel: Unknown request received"); } // send the response if (response != null) { send(connectedPeerId, response); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** Show content activity */ private void showContent(EngagementReachContent content) { /* Update state */ mState = State.SHOWING;/*from w ww. j a va 2 s.c o m*/ mCurrentShownContentId = content.getLocalId(); /* Start activity */ Intent intent = content.getIntent(); filterIntentWithCategory(intent); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY); mShowingActivity = intent.getComponent(); mContext.startActivity(intent); }
From source file:it.chefacile.app.MainActivity.java
@Override public void onBackPressed() { new AlertDialog.Builder(this).setIcon(R.drawable.logo).setTitle("Exit").setMessage("Are you sure?") .setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override//www . ja v a 2s. c om public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//***Change Here*** startActivity(intent); finish(); System.exit(0); } }).setNegativeButton("no", null).show(); }
From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java
private void syncNotifications(Account account, SyncResult syncResult) throws AuthenticationException, IOException { final User user = AccountUtils.getUser(getContext(), account.name); final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()), account, getContext());// ww w . j a va 2 s . c o m final Gson gson = GsonUtils.getGson(); final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class); if (notifications == null) { syncResult.stats.numParseExceptions++; LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true); return; } ArrayList<String> fetchedNotCodes = new ArrayList<String>(); ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>(); for (Notification not : notifications) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not)); fetchedNotCodes.add(not.getCode()); if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values, SigarraContract.Notifcations.UPDATE_NOTIFICATION, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) { values.put(SigarraContract.Notifcations.CODE, account.name); values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode()); values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW); values.put(SigarraContract.Notifcations.CODE, account.name); bulkValues.add(values); } } // inserting the values if (bulkValues.size() > 0) { getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI, bulkValues.toArray(new ContentValues[0])); // if the account being synced is the current active accout // display notification if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) { final NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext()); notBuilder.setAutoCancel(true).setOnlyAlertOnce(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (bulkValues.size() == 1) { final Notification notification = gson.fromJson( bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class) .putExtra(NotificationsDescFragment.NOTIFICATION, notification); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage()) .setContentTitle(notification.getSubject()).setContentText(notification.getMessage()) .setContentIntent(notifyPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage()) .setBigContentTitle(notification.getSubject()) .setSummaryText(notification.getMessage())); mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build()); } else { final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size()); Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle(notTitle); // Moves events into the big view for (ContentValues value : bulkValues) { final Notification notification = gson.fromJson( value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); inboxStyle.addLine(notification.getSubject()); } // Moves the big view style object into the notification // object. notBuilder.setStyle(inboxStyle); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle) .setContentText("").setContentIntent(notifyPendingIntent); mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(), notBuilder.build()); } } } final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI, SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())), null); try { if (syncState.moveToFirst()) { if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) { // Report that we have checked the notifications final ContentValues values = new ContentValues(); values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis()); getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(account.name)); } } } finally { syncState.close(); } ArrayList<String> notToDelete = new ArrayList<String>(); final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI, new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null); try { if (cursor.moveToFirst()) { do { final String code = cursor.getString(0); if (!fetchedNotCodes.contains(code)) notToDelete.add(code); } while (cursor.moveToNext()); } else { // no notifications getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null); } } finally { cursor.close(); } if (notToDelete.size() > 0) getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI, SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])), SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, notToDelete.toArray(new String[0]))); syncResult.stats.numEntries += notifications.length; }