List of usage examples for android.app PendingIntent FLAG_NO_CREATE
int FLAG_NO_CREATE
To view the source code for android.app PendingIntent FLAG_NO_CREATE.
Click Source Link
From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java
/** * Used in L and later devices where "next alarm" is stored in the Alarm Manager. *///from ww w . j a v a 2 s. co m @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) { // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the // alarm that is going to fire next. The operation is constructed such that it is ignored // by AlarmStateManager. final AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); final int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0; final PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */, AlarmStateManager.createIndicatorIntent(context), flags); if (nextAlarm != null) { LogUtils.i("Setting upcoming AlarmClockInfo for alarm: " + nextAlarm.mId); long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis(); // Create an intent that can be used to show or edit details of the next alarm. PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(), AlarmNotifications.createViewAlarmIntent(context, nextAlarm), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmClockInfo info = new AlarmClockInfo(alarmTime, viewIntent); Utils.updateNextAlarm(alarmManager, info, operation); } else if (operation != null) { LogUtils.i("Canceling upcoming AlarmClockInfo"); alarmManager.cancel(operation); } }
From source file:com.psiphon3.psiphonlibrary.UpgradeChecker.java
/** * Creates the periodic alarm used to check for updates. Can be called unconditionally; it * handles cases when the alarm is already created. * @param appContext The application context. *//*ww w .j av a 2 s .c om*/ private static void createAlarm(Context appContext) { if (!allowedToSelfUpgrade(appContext)) { // Don't waste resources with an alarm if we can't possibly self-upgrade. log(appContext, R.string.upgrade_checker_no_alarm_no_selfupgrading, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } Intent intent = new Intent(appContext, UpgradeChecker.class); intent.setAction(ALARM_INTENT_ACTION); boolean alarmExists = (PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null); if (alarmExists) { log(appContext, R.string.upgrade_checker_alarm_exists, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } log(appContext, R.string.upgrade_checker_creating_alarm, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_FIFTEEN_MINUTES, AlarmManager.INTERVAL_HALF_DAY, alarmIntent); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get preferences getSettings();//from w w w. j a va2 s .com // Set alarm for checking completed torrents, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); } // Set alarm for RSS checking, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), RSSService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_DAY, alarmIntent); } // Set Theme (It must be fore inflating or setContentView) if (dark_ui) { this.setTheme(R.style.Theme_Dark); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); } } else { this.setTheme(R.style.Theme_Light); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); } } setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.app_bar); if (dark_ui) { toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); } setSupportActionBar(toolbar); // Set App title setTitle(R.string.app_shortname); // Drawer menu navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers); navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // drawerList = (ListView) findViewById(R.id.left_drawer); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are ArrayList<ObjectDrawerItem> serverItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> actionItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> settingsItems = new ArrayList<ObjectDrawerItem>(); // Add server category serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_servers, getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null)); // Server items int currentServerValue = 1; try { currentServerValue = Integer.parseInt(MainActivity.currentServer); } catch (NumberFormatException e) { } for (int i = 0; i < navigationDrawerServerItems.length; i++) { // Log.d("Debug", "MainActivity - currentServerValue - currentServerValue: " + currentServerValue); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1): " + (i + 1)); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1) == currentServerValue: " + ((i + 1) == currentServerValue)); serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i], DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer")); } // // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 1", DRAWER_ITEM_SERVERS, true, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 2", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 3", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // Add actions actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0], DRAWER_ITEM_ACTIONS, lastState.equals("all"), "refreshAll")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1], DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2], DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[3], DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[4], DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[5], DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive")); // Add settings actions // drawerItems.add(new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openOptions")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openSettings")); if (packageName.equals("com.lgallardo.youtorrentcontroller")) { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "getPro")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8], DRAWER_ITEM_ACTIONS, false, "openHelp")); } else { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "openHelp")); } // Set adapter rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems, settingsItems, null); rAdapter.notifyDataSetChanged(); // Log.d("Debug", "MainActivity - oldActionPosition: "+ (Arrays.asList(actionStates).indexOf(lastState))); // drawerList.setAdapter(adapter); mRecyclerView.setAdapter(rAdapter); mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager // Set selection according to last state setSelectionAndTitle(lastState); // Set the item click listener // drawerList.setOnItemClickListener(new DrawerItemClickListener()); // Get drawer title title = drawerTitle = getTitle(); // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // New ActionBarDrawerToggle for Google Material Desing (v7) drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); // getSupportActionBar().setTitle(title); } /** * Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // getSupportActionBar().setTitle(drawerTitle); // setTitle(R.string.app_shortname); } }; drawerLayout.setDrawerListener(drawerToggle); // drawerToggle.syncState(); // Finally we set the drawer toggle sync State getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); // Get options and save them as shared preferences // qBittorrentOptions qso = new qBittorrentOptions(); // qso.execute(new String[]{qbQueryString + "/preferences", "getSettings"}); // If it were awaked from an intent-filter, // Get token and cookie and then // get intent from the intent filter and Add URL torrent // Log.d("Debug", "MainActivity - 1"); new torrentTokenByIntent().execute(getIntent()); // Fragments // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first // fragment if (findViewById(R.id.fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // return; // } // This fragment will hold the list of torrents if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); // Set the second fragments container firstFragment.setSecondFragmentContainer(R.id.content_frame); // This i the second fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment"); } if (fragmentManager.findFragmentByTag("secondFragment") == null) { fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment"); } else { fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment"); } fragmentTransaction.commit(); // Second fragment will be added in ItemsFRagment's onListItemClick // method } else { // Phones handle just one fragment // Create an instance of ItemsFragments if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); // This is the about fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // // // Handle Item list empty due to Fragment stack // try { // FragmentManager fm = getFragmentManager(); // // if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.TorrentDetailsFragment) { // // refreshCurrent(); // // } // } // catch (Exception e) { // } // // return; // } // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment"); } // if torrent details was loaded reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); } fragmentTransaction.commit(); } // Activity is visible activityIsVisible = true; // First refresh refreshCurrent(); handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); // Load banner loadBanner(); }
From source file:net.olejon.mdapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Settings/*from ww w . ja v a2s . c om*/ PreferenceManager.setDefaultValues(mContext, R.xml.settings, false); // Installed long installed = mTools.getSharedPreferencesLong("INSTALLED"); if (installed == 0) mTools.setSharedPreferencesLong("INSTALLED", mTools.getCurrentTime()); // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout setContentView(R.layout.activity_main); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar); toolbar.setTitle(getString(R.string.main_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); // Search mSearchEditText = (EditText) findViewById(R.id.main_search_edittext); // Drawer mDrawer = (LinearLayout) findViewById(R.id.main_drawer); mDrawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_layout); TextView drawerVersionNameTextView = (TextView) findViewById(R.id.drawer_version_name); TextView drawerVersionCodeTextView = (TextView) findViewById(R.id.drawer_version_code); drawerVersionNameTextView .setText(getString(R.string.drawer_version_name) + ": " + mTools.getProjectVersionName()); drawerVersionCodeTextView .setText(getString(R.string.drawer_version_code) + ": " + mTools.getProjectVersionCode()); mDrawerLayout.setDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.project_name, R.string.project_name)); mDrawerLayout.setDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_content_description, R.string.drawer_content_description) { @Override public void onDrawerOpened(View drawerView) { mDrawerClosed = 0; } @Override public void onDrawerClosed(View drawerView) { TextView brukerhandbokenTextView = (TextView) findViewById(R.id.drawer_item_brukerhandboken); TextView analyseoversiktenTextView = (TextView) findViewById(R.id.drawer_item_analyseoversikten); TextView upToDateTextView = (TextView) findViewById(R.id.drawer_item_uptodate); TextView bmjTextView = (TextView) findViewById(R.id.drawer_item_bmj); TextView encyclopediasTextView = (TextView) findViewById(R.id.drawer_item_encyclopedias); brukerhandbokenTextView.setVisibility(View.GONE); analyseoversiktenTextView.setVisibility(View.GONE); upToDateTextView.setVisibility(View.GONE); bmjTextView.setVisibility(View.GONE); encyclopediasTextView.setVisibility(View.VISIBLE); switch (mDrawerClosed) { case R.id.drawer_item_nlh: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_nlh)); intent.putExtra("uri", "http://m.legemiddelhandboka.no/"); startActivity(intent); break; } case R.id.drawer_item_felleskatalogen: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_felleskatalogen)); intent.putExtra("uri", "http://www.felleskatalogen.no/m/medisin/"); startActivity(intent); break; } case R.id.drawer_item_brukerhandboken: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_brukerhandboken)); intent.putExtra("uri", "http://brukerhandboken.no/"); startActivity(intent); break; } case R.id.drawer_item_analyseoversikten: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_analyseoversikten)); intent.putExtra("uri", "http://www.analyseoversikten.no/"); startActivity(intent); break; } case R.id.drawer_item_uptodate: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_uptodate)); intent.putExtra("uri", "http://www.uptodate.com/contents/search"); startActivity(intent); break; } case R.id.drawer_item_bmj: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_bmj)); intent.putExtra("uri", "http://bestpractice.bmj.com/"); startActivity(intent); break; } case R.id.drawer_item_diseases_and_treatments: { Intent intent = new Intent(mContext, DiseasesAndTreatmentsActivity.class); startActivity(intent); break; } case R.id.drawer_item_lvh: { Intent intent = new Intent(mContext, LvhActivity.class); startActivity(intent); break; } case R.id.drawer_item_interactions: { Intent intent = new Intent(mContext, InteractionsActivity.class); startActivity(intent); break; } case R.id.drawer_item_poisonings: { Intent intent = new Intent(mContext, PoisoningsActivity.class); startActivity(intent); break; } case R.id.drawer_item_nasjonale_retningslinjer: { Intent intent = new Intent(mContext, NasjonaleRetningslinjerActivity.class); startActivity(intent); break; } case R.id.drawer_item_clinicaltrials: { Intent intent = new Intent(mContext, ClinicalTrialsActivity.class); startActivity(intent); break; } case R.id.drawer_item_atc: { Intent intent = new Intent(mContext, AtcActivity.class); startActivity(intent); break; } case R.id.drawer_item_icd10: { Intent intent = new Intent(mContext, Icd10Activity.class); startActivity(intent); break; } case R.id.drawer_item_manufacturers: { Intent intent = new Intent(mContext, ManufacturersActivity.class); startActivity(intent); break; } case R.id.drawer_item_pharmacies: { Intent intent = new Intent(mContext, PharmaciesActivity.class); startActivity(intent); break; } case R.id.drawer_item_scales: { Intent intent = new Intent(mContext, ScalesActivity.class); startActivity(intent); break; } case R.id.drawer_item_notifications_from_slv: { Intent intent = new Intent(mContext, NotificationsFromSlvActivity.class); startActivity(intent); break; } case R.id.drawer_item_calculators: { Intent intent = new Intent(mContext, CalculatorsActivity.class); startActivity(intent); break; } case R.id.drawer_item_notes: { Intent intent = new Intent(mContext, NotesActivity.class); startActivity(intent); break; } case R.id.drawer_item_tasks: { Intent intent = new Intent(mContext, TasksActivity.class); startActivity(intent); break; } case R.id.drawer_item_settings: { Intent intent = new Intent(mContext, SettingsActivity.class); startActivity(intent); break; } case R.id.drawer_item_donate: { Intent intent = new Intent(mContext, DonateActivity.class); startActivity(intent); break; } case R.id.drawer_item_feedback: { Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + getString(R.string.project_feedback_uri) + "?subject=" + getString(R.string.project_name))); startActivity(Intent.createChooser(intent, getString(R.string.project_feedback_text))); break; } case R.id.drawer_item_report_issue: { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.drawer_item_report_issue)); intent.putExtra("uri", getString(R.string.project_report_issue_uri)); startActivity(intent); break; } } } }); // View pager mViewPager = (ViewPager) findViewById(R.id.main_pager); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.main_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSearchEditText.requestFocus(); mInputMethodManager.showSoftInput(mSearchEditText, 0); } }); // Alarms Context applicationContext = getApplicationContext(); boolean messageAlarmIsStarted = (PendingIntent.getBroadcast(mContext, 1, new Intent(applicationContext, MessageIntentService.class), PendingIntent.FLAG_NO_CREATE) != null); if (!messageAlarmIsStarted) { MessageAlarm messageAlarm = new MessageAlarm(); messageAlarm.setAlarm(applicationContext); } boolean notificationsFromSlvAlarmIsStarted = (PendingIntent.getBroadcast(mContext, 2, new Intent(applicationContext, NotificationsFromSlvAlarm.class), PendingIntent.FLAG_NO_CREATE) != null); if (!notificationsFromSlvAlarmIsStarted) { NotificationsFromSlvAlarm notificationsFromSlvAlarm = new NotificationsFromSlvAlarm(); notificationsFromSlvAlarm.setAlarm(applicationContext); } // Get data GetDataTask getDataTask = new GetDataTask(); getDataTask.execute(); }
From source file:org.chromium.ChromeNotifications.java
private void clear(final CordovaArgs args, final CallbackContext callbackContext) { try {//from w ww .j av a 2s . c o m String notificationId = args.getString(0); PendingIntent pendingIntent = makePendingIntent(NOTIFICATION_CLICKED_ACTION, notificationId, -1, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { notificationManager.cancel(notificationId.hashCode()); pendingIntent.cancel(); callbackContext.success(1); } else { callbackContext.success(0); } } catch (Exception e) { Log.e(LOG_TAG, "Could not clear notification", e); callbackContext.error("Could not clear notification"); } }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void setKeepAliveAlarm(Context context) { Intent i = new Intent(ACTION_ALRM_SRV_KEEP_ALIVE).setPackage(context.getPackageName()); //set the alarm if not already existing PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_NO_CREATE); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); if (pi != null) { alarmMan.cancel(pi);/*from w ww .ja va 2 s . c o m*/ pi.cancel(); } pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + SERV_KEEP_ALIVE_TIME, SERV_KEEP_ALIVE_TIME, pi); }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void setKeepAliveAlarm() { Intent i = new Intent(ACTION_ALRM_SRV_KEEP_ALIVE); //set the alarm if not already existing PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_NO_CREATE); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); if (pi != null) { alarmMan.cancel(pi);//from w w w .j av a 2s . c o m pi.cancel(); } pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + SERV_KEEP_ALIVE_TIME, SERV_KEEP_ALIVE_TIME, pi); }
From source file:org.compose.mobilesdk.android.COMPOSESubService.java
/** * Query's the AlarmManager to check if there is * a keep alive currently scheduled//from ww w . j a va 2 s . c om * @return true if there is currently one scheduled false otherwise */ private synchronized boolean hasScheduledKeepAlives() { Intent i = new Intent(); i.setClass(this, COMPOSESubService.class); i.setAction(ACTION_KEEPALIVE); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_NO_CREATE); return (pi != null) ? true : false; }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get preferences getSettings();/*from ww w . j a va 2 s . co m*/ // Set alarm for checking completed torrents, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); } // Set alarm for RSS checking, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), RSSService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_DAY, alarmIntent); } // Set Theme (It must be fore inflating or setContentView) if (dark_ui) { this.setTheme(R.style.Theme_Dark); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); } } else { this.setTheme(R.style.Theme_Light); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); } } setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.app_bar); if (dark_ui) { toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); } setSupportActionBar(toolbar); // Set App title setTitle(R.string.app_shortname); // Drawer menu navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers); navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // drawerList = (ListView) findViewById(R.id.left_drawer); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are ArrayList<DrawerItem> serverItems = new ArrayList<DrawerItem>(); ArrayList<DrawerItem> actionItems = new ArrayList<DrawerItem>(); // ArrayList<ObjectDrawerItem> labelItems = new ArrayList<ObjectDrawerItem>(); ArrayList<DrawerItem> settingsItems = new ArrayList<DrawerItem>(); // Add server category serverItems.add(new DrawerItem(R.drawable.ic_drawer_servers, getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null)); // Server items int currentServerValue = 1; try { currentServerValue = Integer.parseInt(MainActivity.currentServer); } catch (NumberFormatException e) { } for (int i = 0; i < navigationDrawerServerItems.length; i++) { serverItems.add(new DrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i], DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer")); } // Add actions actionItems.add(new DrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0], DRAWER_ITEM_ACTIONS, lastState.equals("all"), "refreshAll")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1], DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2], DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_seeding, navigationDrawerItemTitles[3], DRAWER_ITEM_ACTIONS, lastState.equals("seeding"), "refreshSeeding")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[4], DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[5], DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive")); actionItems.add(new DrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive")); // Add labels // Add settings actions settingsItems.add(new DrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "openOptions")); settingsItems.add(new DrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[8], DRAWER_ITEM_ACTIONS, false, "openSettings")); if (packageName.equals("com.lgallardo.qbittorrentclient")) { settingsItems.add(new DrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[9], DRAWER_ITEM_ACTIONS, false, "getPro")); settingsItems.add(new DrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[10], DRAWER_ITEM_ACTIONS, false, "openHelp")); } else { settingsItems.add(new DrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[9], DRAWER_ITEM_ACTIONS, false, "openHelp")); } rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems, settingsItems, null); rAdapter.notifyDataSetChanged(); // drawerList.setAdapter(adapter); mRecyclerView.setAdapter(rAdapter); mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager // Set selection according to last state setSelectionAndTitle(lastState); // Get drawer title title = drawerTitle = getTitle(); // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // New ActionBarDrawerToggle for Google Material Desing (v7) drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); // getSupportActionBar().setTitle(title); } /** * Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // getSupportActionBar().setTitle(drawerTitle); // setTitle(R.string.app_shortname); } }; drawerLayout.setDrawerListener(drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); // Get options and save them as shared preferences qBittorrentOptions qso = new qBittorrentOptions(); qso.execute(new String[] { qbQueryString + "/preferences", "getSettings" }); // If it was awoken from an intent-filter, // get intent from the intent filter and Add URL torrent addTorrentByIntent(getIntent()); // Fragments // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first // fragment if (findViewById(R.id.fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // return; // } // This fragment will hold the list of torrents if (firstFragment == null) { firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); // Set the second fragments container firstFragment.setSecondFragmentContainer(R.id.content_frame); // This i the second fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment"); } if (fragmentManager.findFragmentByTag("secondFragment") == null) { fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment"); } else { fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment"); } fragmentTransaction.commit(); // Second fragment will be added in ItemsFragment's onListItemClick method } else { // Phones handle just one fragment // Create an instance of ItemsFragments if (firstFragment == null) { firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); // This is the about fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // // // Handle Item list empty due to Fragment stack // try { // FragmentManager fm = getFragmentManager(); // // if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { // // refreshCurrent(); // // } // } // catch (Exception e) { // } // // return; // } // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment"); } // if torrent details was loaded reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); } fragmentTransaction.commit(); } // Activity is visible activityIsVisible = true; // First refresh refreshCurrent(); handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); // Load banner loadBanner(); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void cancelTriggerAlwaysAlarm(int trigId) { Intent i = createTriggerAlwaysAlarmIntent(trigId); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { //cancel the alarm AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); alarmMan.cancel(pi);//from w ww. j a v a 2 s .com pi.cancel(); } }