Java Code Examples for android.app.PendingIntent
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: WidgetUpdater1x2.java

@Override protected void fillRemoteViewsLoading(RemoteViews updateViews,Context context){ updateViews.setTextViewText(R.id.widget1x2_lastupdate,"Loading"); Intent viewIntent=new Intent(context,MainActivity.class); PendingIntent pending=PendingIntent.getActivity(context,0,viewIntent,0); updateViews.setOnClickPendingIntent(R.id.widget1x2_widget,pending); }
Example 2
From project Absolute-Android-RSS, under directory /src/com/AA/Recievers/.
Source file: AlarmReceiver.java

/** * Creates a pending intent for our RSS Service * @param context - Context that will be managing this alarm * @return - The pending intent that will be sent to the alarm manager */ public static PendingIntent getPendingIntent(Context context){ Intent service=new Intent(); service.setClass(context,AlarmReceiver.class); PendingIntent pendingIntent=PendingIntent.getBroadcast(context,ALARM_ID,service,PendingIntent.FLAG_UPDATE_CURRENT); return pendingIntent; }
Example 3
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/helper/.
Source file: NotificationHelper.java

public void showRecordingNotification(){ long time=System.currentTimeMillis(); Notification notification=new Notification(R.drawable.ic_media_record,aircastingIsRecording,time); notification.flags&=~Notification.FLAG_AUTO_CANCEL; Intent notificationIntent=new Intent(context,SoundTraceActivity.class); PendingIntent pendingIntent=PendingIntent.getActivity(context,REQUEST_ANY,notificationIntent,EMPTY_FLAGS); notification.setLatestEventInfo(context,aircastingIsRecording,"",pendingIntent); notificationManager.notify(RECORDING_ID,notification); }
Example 4
From project AlarmApp-Android, under directory /src/org/alarmapp/services/.
Source file: PositionService.java

private void setupFireDepartmentGeofence(){ LogEx.verbose("Setting up fire departments geo fence"); int geofenceRadius=Integer.parseInt(AlarmApp.getPreferences().getString("firedepartment_geofence_radius","150")); LonLat pos=AlarmApp.getUser().getFireDepartment().getPosition(); Intent intent=getTrackingIntent(Actions.FINISHED_TRACKING); PendingIntent pendingIntent=PendingIntent.getService(this,0,intent,0); locationManager.addProximityAlert(pos.getLatitude(),pos.getLongitude(),geofenceRadius,MAX_TRACKING_TIME,pendingIntent); }
Example 5
From project and-bible, under directory /AndBible/src/net/bible/android/view/activity/page/.
Source file: MenuCommandHandler.java

public boolean restartIfRequiredOnReturn(int requestCode){ if (requestCode == MenuCommandHandler.REFRESH_DISPLAY_ON_FINISH) { Log.i(TAG,"Refresh on finish"); if (!CommonUtils.getLocalePref().equals(mPrevLocalePref)) { PendingIntent intent=PendingIntent.getActivity(callingActivity.getBaseContext(),0,new Intent(callingActivity.getIntent()),callingActivity.getIntent().getFlags()); AlarmManager mgr=(AlarmManager)callingActivity.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC,System.currentTimeMillis() + 1000,intent); System.exit(2); return true; } } return false; }
Example 6
From project andlytics, under directory /src/com/github/andlyticsproject/io/.
Source file: ExportService.java

/** * Send a notification to the progress bar. */ protected void sendNotification(String message){ Intent startActivityIntent=new Intent(); PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(),0,startActivityIntent,0); Builder builder=new NotificationCompat2.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.statusbar_andlytics); builder.setContentTitle(getResources().getString(R.string.app_name) + ": " + getApplicationContext().getString(R.string.export_)); builder.setContentText(message); builder.setContentIntent(pendingIntent); builder.setDefaults(0); builder.setAutoCancel(true); builder.setOngoing(true); notificationManager.notify(NOTIFICATION_ID_PROGRESS,builder.build()); }
Example 7
From project android-bankdroid, under directory /src/com/liato/bankdroid/appwidget/.
Source file: AutoRefreshService.java

public static void sendWidgetRefresh(final Context context){ final Intent updateIntent=new Intent(BROADCAST_WIDGET_REFRESH); final PendingIntent pendingIntent=PendingIntent.getBroadcast(context,0,updateIntent,PendingIntent.FLAG_UPDATE_CURRENT); try { pendingIntent.send(); } catch ( final CanceledException e) { Log.e("",e.getMessage(),e); } }
Example 8
From project android-joedayz, under directory /Proyectos/SystemServicesTest/src/com/androideity/systemservices/.
Source file: SystemServicesTestActivity.java

public void startAlert(View view){ EditText text=(EditText)findViewById(R.id.txt_tiempo); int i=Integer.parseInt(text.getText().toString()); Intent intent=new Intent(this,VibrationPhone.class); PendingIntent pendingIntent=PendingIntent.getBroadcast(this.getApplicationContext(),234324243,intent,0); AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (i * 1000),pendingIntent); Toast.makeText(this,"Has fijado la alarma en " + i + " segundos",Toast.LENGTH_LONG).show(); }
Example 9
From project android-pedometer, under directory /src/name/bagi/levente/pedometer/.
Source file: StepService.java

/** * Show a notification while this service is running. */ private void showNotification(){ CharSequence text=getText(R.string.app_name); Notification notification=new Notification(R.drawable.ic_notification,null,System.currentTimeMillis()); notification.flags=Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent pedometerIntent=new Intent(); pedometerIntent.setComponent(new ComponentName(this,Pedometer.class)); pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent=PendingIntent.getActivity(this,0,pedometerIntent,0); notification.setLatestEventInfo(this,text,getText(R.string.notification_subtitle),contentIntent); mNM.notify(R.string.app_name,notification); }
Example 10
From project Android-Terminal-Emulator, under directory /src/jackpal/androidterm/.
Source file: TermService.java

@Override public void onCreate(){ compat=new ServiceForegroundCompat(this); mTermSessions=new SessionList(); Notification notification=new Notification(R.drawable.ic_stat_service_notification_icon,getText(R.string.service_notify_text),System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT; Intent notifyIntent=new Intent(this,Term.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,notifyIntent,0); notification.setLatestEventInfo(this,getText(R.string.application_terminal),getText(R.string.service_notify_text),pendingIntent); compat.startForeground(RUNNING_NOTIFICATION,notification); Log.d(TermDebug.LOG_TAG,"TermService started"); return; }
Example 11
From project android-tether, under directory /src/og/android/tether/.
Source file: WidgetProvider.java

static RemoteViews buildUpdate(Context context){ Intent intent=new Intent(context,WidgetProvider.class); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); PendingIntent pendingIntent=PendingIntent.getBroadcast(context,0,intent,0); RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.appwidget_provider_layout); views.setOnClickPendingIntent(R.id.button,pendingIntent); updateWidgetButtons(views,context); return views; }
Example 12
From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/activity/.
Source file: NowPlayingNotificationManager.java

private Notification buildNotification(String title,String text,int icon){ final Intent actintent=new Intent(mContext,NowPlayingActivity.class); actintent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); final PendingIntent intent=PendingIntent.getActivity(mContext,0,actintent,0); final Notification notification=new Notification(icon,title,System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT; notification.setLatestEventInfo(mContext,title,text,intent); return notification; }
Example 13
From project androidannotations, under directory /HelloWorldEclipse/src/com/googlecode/androidannotations/helloworldeclipse/.
Source file: MyActivity.java

@UiThread(delay=2000) void showNotificationsDelayed(){ Notification notification=new Notification(R.drawable.icon,"Hello !",0); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(),0); notification.setLatestEventInfo(getApplicationContext(),"My notification","Hello World!",contentIntent); notificationManager.notify(1,notification); }
Example 14
private void sendSMS(String phoneNumber,String message){ registerReceiver(new SmsSentReciever(),new IntentFilter(Constants.SENT)); registerReceiver(new SmsDeliveredReciever(),new IntentFilter(Constants.DELIVERED)); PendingIntent sentPI=PendingIntent.getBroadcast(this,0,new Intent(Constants.SENT),0); PendingIntent deliveredPI=PendingIntent.getBroadcast(this,0,new Intent(Constants.DELIVERED),0); SmsManager.getDefault().sendTextMessage(phoneNumber,null,message,sentPI,deliveredPI); }
Example 15
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/widget/.
Source file: SettingsAppWidgetProvider.java

/** * Creates PendingIntent to notify the widget of a button click. * @param context * @param appWidgetId * @return */ private static PendingIntent getLaunchPendingIntent(Context context,int appWidgetId,int buttonId){ Intent launchIntent=new Intent(); launchIntent.setClass(context,SettingsAppWidgetProvider.class); launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE); launchIntent.setData(Uri.parse("custom:" + buttonId)); PendingIntent pi=PendingIntent.getBroadcast(context,0,launchIntent,0); return pi; }
Example 16
From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/provider/.
Source file: RenderFXWidgetProvider.java

private static PendingIntent getLaunchPendingIntent(Context context,int appWidgetId,int buttonId){ Intent launchIntent=new Intent(); launchIntent.setClass(context,RenderFXWidgetProvider.class); launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE); launchIntent.setData(Uri.parse("custom:" + appWidgetId + "/"+ buttonId)); PendingIntent pi=PendingIntent.getBroadcast(context,0,launchIntent,0); return pi; }
Example 17
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.
Source file: CalendarSyncEnabler.java

/** * Show the "Exchange calendar added" notification. * @param emailAddresses space delimited list of email addresses of Exchange accounts. It'llbe shown on the notification. */ void showNotificationForTest(String emailAddresses){ PendingIntent launchCalendarPendingIntent=PendingIntent.getActivity(mContext,0,createLaunchCalendarIntent(),0); String tickerText=mContext.getString(R.string.notification_exchange_calendar_added); Notification n=new Notification(R.drawable.stat_notify_calendar,tickerText,System.currentTimeMillis()); n.setLatestEventInfo(mContext,tickerText,emailAddresses,launchCalendarPendingIntent); n.flags=Notification.FLAG_AUTO_CANCEL; NotificationManager nm=(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID_EXCHANGE_CALENDAR_ADDED,n); }
Example 18
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/gadget/.
Source file: PhotoAppWidgetProvider.java

private static RemoteViews buildStackWidget(Context context,int widgetId,Entry entry){ RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.appwidget_main); Intent intent=new Intent(context,WidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,widgetId); intent.putExtra(WidgetService.EXTRA_WIDGET_TYPE,entry.type); intent.putExtra(WidgetService.EXTRA_ALBUM_PATH,entry.albumPath); intent.setData(Uri.parse("widget://gallery/" + widgetId)); views.setRemoteAdapter(R.id.appwidget_stack_view,intent); views.setEmptyView(R.id.appwidget_stack_view,R.id.appwidget_empty_view); Intent clickIntent=new Intent(context,WidgetClickHandler.class); PendingIntent pendingIntent=PendingIntent.getActivity(context,0,clickIntent,PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.appwidget_stack_view,pendingIntent); return views; }
Example 19
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/handover/.
Source file: HandoverManager.java

PendingIntent buildCancelIntent(){ Intent intent=new Intent(ACTION_CANCEL_HANDOVER_TRANSFER); intent.putExtra(EXTRA_SOURCE_ADDRESS,sourceAddress); PendingIntent pi=PendingIntent.getBroadcast(mContext,0,intent,0); return pi; }
Example 20
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.
Source file: SearchWidgetProvider.java

private static void rescheduleAction(Context context,boolean reschedule,String action,long period){ AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); PendingIntent intent=createBroadcast(context,action); alarmManager.cancel(intent); if (reschedule) { if (DBG) Log.d(TAG,"Scheduling action " + action + " after period "+ period); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime() + period,period,intent); } else { if (DBG) Log.d(TAG,"Cancelled action " + action); } }
Example 21
From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.
Source file: Util.java

public static void showOutdatedNotification(Context context){ if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Preferences.OUTDATED_NOTIFICATION,true)) { NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.stat_su,context.getString(R.string.notif_outdated_ticker),System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,new Intent(context,UpdaterActivity.class),0); notification.setLatestEventInfo(context,context.getString(R.string.notif_outdated_title),context.getString(R.string.notif_outdated_text),contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; nm.notify(UpdaterService.NOTIFICATION_ID,notification); } }
Example 22
From project android_packages_apps_Tag, under directory /src/com/android/apps/tag/.
Source file: TagViewer.java

@Override public void onStop(){ super.onStop(); PendingIntent pending=getPendingIntent(); pending.cancel(); if (mReceiver != null) { unregisterReceiver(mReceiver); mReceiver=null; } }
Example 23
/** * Starts the repeating Alarm that sends the fetch Intent. */ private boolean scheduleRepeatingAlarm(){ final AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); final PendingIntent pIntent=getRepeatingIntent(); final int frequencyMs=getFetchFrequencyS(); final long firstTime=SystemClock.elapsedRealtime() + frequencyMs; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime,frequencyMs,pIntent); MyLog.d(TAG,"Started repeating alarm in a " + frequencyMs + "ms rhythm."); return true; }
Example 24
From project andtweet, under directory /src/com/xorcode/andtweet/.
Source file: AndTweetService.java

/** * Starts the repeating Alarm that sends the fetch Intent. */ private boolean scheduleRepeatingAlarm(){ final AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); final PendingIntent pIntent=getRepeatingIntent(); final int frequencyMs=getFetchFrequencyS(); final long firstTime=SystemClock.elapsedRealtime() + frequencyMs; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime,frequencyMs,pIntent); d(TAG,"Started repeating alarm in a " + frequencyMs + "ms rhythm."); return true; }
Example 25
From project anode, under directory /src/net/haltcondition/anode/.
Source file: WidgetUpdater.java

private void setAlarm(Context context){ Log.d(TAG,"Setting Alarm"); SettingsHelper settings=new SettingsHelper(context); Intent i=new Intent(Common.USAGE_ALARM); PendingIntent pi=PendingIntent.getBroadcast(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarm=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); alarm.setInexactRepeating(AlarmManager.RTC,System.currentTimeMillis(),settings.getUpdateInterval(),pi); }
Example 26
From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/ui/tutorials/.
Source file: TutorialsProvider.java

public synchronized static void showNotificationIcon(Context context,IntentToLaunch notificationData){ final NotificationManager mngr=((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)); Notification notification=new Notification(notificationData.NotificationIcon,context.getText(notificationData.NotificationText),System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationData.IntentToStart,0); notification.setLatestEventInfo(context,context.getText(notificationData.NotificationTitle),context.getText(notificationData.NotificationText),contentIntent); notification.defaults=0; notification.flags=Notification.FLAG_AUTO_CANCEL; mngr.notify(notificationData.NotificationID,notification); }
Example 27
From project Backyard-Brains-Android-App, under directory /src/com/backyardbrains/audio/.
Source file: AudioService.java

/** * Toggle a notification that this service is running. * @param show show if true, hide otherwise. * @see android.app.Notification * @see NotificationManager#notify() */ private void showNotification(boolean show){ if (show) { CharSequence text=getText(R.string.mic_thread_running); Notification not=new Notification(R.drawable.ic_launcher_byb,text,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,BackyardAndroidActivity.class),0); not.setLatestEventInfo(this,"Backyard Brains",text,contentIntent); mNM.notify(NOTIFICATION,not); } else { if (mNM != null) { mNM.cancel(NOTIFICATION); } } }
Example 28
From project Barcamp-Bangalore-Android-App, under directory /bcb_app/src/com/bangalore/barcamp/.
Source file: BCBUtils.java

public static PendingIntent createPendingIntentForID(Context context,String id,int slot,int session){ Intent intent=new Intent(context,SessionAlarmIntentService.class); intent.putExtra(SessionAlarmIntentService.SESSION_ID,id); intent.putExtra(SessionAlarmIntentService.EXTRA_SLOT_POS,slot); intent.putExtra(SessionAlarmIntentService.EXTRA_SESSION_POSITION,session); int idInt=Integer.parseInt(id); PendingIntent pendingIntent=PendingIntent.getService(context,idInt,intent,PendingIntent.FLAG_ONE_SHOT); return pendingIntent; }
Example 29
From project Binaural-Beats, under directory /src/com/ihunda/android/binauralbeat/.
Source file: BBeat.java

private void _start_notification(String programName){ Notification notification=new Notification(R.drawable.icon,getString(R.string.notif_started),System.currentTimeMillis()); Context context=getApplicationContext(); CharSequence contentTitle=getString(R.string.notif_started); CharSequence contentText=getString(R.string.notif_descr,programName); Intent notificationIntent=this.getIntent(); PendingIntent contentIntent=PendingIntent.getActivity(this,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; mNotificationManager.notify(NOTIFICATION_STARTED,notification); }
Example 30
From project Birthday-widget, under directory /Birthday/src/main/java/cz/krtinec/birthday/.
Source file: NotificationSender.java

protected static void fireBirthdayAlert(Context ctx,Event c,Long when){ String label=formatLabel(ctx,c); Notification n=new Notification(R.drawable.icon,label,when); n.flags=n.flags | Notification.FLAG_AUTO_CANCEL; n.defaults=Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS; Intent i=new Intent(ctx,Birthday.class); PendingIntent pendingIntent=PendingIntent.getActivity(ctx,NOTIFY_CODE,i,PendingIntent.FLAG_CANCEL_CURRENT); n.setLatestEventInfo(ctx,label,formatMessage(ctx,c),pendingIntent); NotificationManager manager=(NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify("Birthday",(int)c.getContactId(),n); }
Example 31
From project BombusLime, under directory /src/org/bombusim/lime/.
Source file: NotificationMgr.java

public void showOnlineNotification(boolean online){ if (!serviceIcon) return; int icon=((online) ? R.drawable.ic_launcher : R.drawable.ic_launcher_gray); CharSequence title=context.getText(R.string.app_name); CharSequence message=context.getText((online) ? R.string.presence_online : R.string.presence_offline); Notification notification=new Notification(icon,title,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,new Intent("org.bombusim.lime",null,context,RosterActivity.class),0); notification.setLatestEventInfo(context,title,message,contentIntent); notification.flags|=Notification.FLAG_NO_CLEAR; notification.flags|=Notification.FLAG_ONGOING_EVENT; mNM.notify(NOTIFICATION_ONLINE,notification); }
Example 32
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.
Source file: BookCatalogueApp.java

/** * Show a notification while this app is running. * @param title * @param message */ public static void showNotification(int id,String title,String message,Intent i){ CharSequence text=message; Notification notification=new Notification(R.drawable.ic_stat_logo,text,System.currentTimeMillis()); notification.flags|=Notification.FLAG_AUTO_CANCEL; PendingIntent contentIntent=PendingIntent.getActivity(context,0,i,0); notification.setLatestEventInfo(context,title,text,contentIntent); mNotifier.notify(id,notification); }
Example 33
From project bookmarktodesktop-android-application, under directory /src/be/vbsteven/bmtodesk/.
Source file: BackgroundSharingService.java

/** * shows the progress notification */ private void showProgress(){ Notification n=new Notification(R.drawable.icon,"Sending bookmark to server...",System.currentTimeMillis()); Intent i=new Intent(this,MainActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(this,1,i,0); n.setLatestEventInfo(this,"Bookmark to Desktop","Sending bookmark to server...",contentIntent); nManager.notify(2,n); }
Example 34
From project btmidi, under directory /BluetoothMidi/src/com/noisepages/nettoyeur/bluetooth/midi/.
Source file: BluetoothMidiService.java

/** * Attempts to connect to the given Bluetooth device with foreground privileges. * @param addr String representation of the MAC address of the Bluetooth device * @param intent intent to be wrapped in a pending intent and fired when the user selects the notification * @param description description of the notification * @throws IOException */ public void connect(String addr,Intent intent,String description) throws IOException { connect(addr); PendingIntent pi=PendingIntent.getActivity(getApplicationContext(),0,intent,0); Notification notification=new Notification(R.drawable.din5,TAG,System.currentTimeMillis()); notification.setLatestEventInfo(this,TAG,description,pi); notification.flags|=Notification.FLAG_ONGOING_EVENT; startForeground(ID,notification); }
Example 35
From project callmeter, under directory /src/de/ub0r/android/callmeter/data/.
Source file: LogRunnerReceiver.java

/** * Schedule next update. * @param context {@link Context} * @param delay delay in milliseconds * @param action {@link Intent}'s action */ public static void schedNext(final Context context,final long delay,final String action){ Log.d(TAG,"schedNext(ctx, " + delay + ","+ action+ ")"); final Intent i=new Intent(context,LogRunnerReceiver.class); if (action != null) { i.setAction(action); } final PendingIntent pi=PendingIntent.getBroadcast(context,0,i,PendingIntent.FLAG_CANCEL_CURRENT); final long t=SystemClock.elapsedRealtime() + delay; final AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.ELAPSED_REALTIME,t,pi); }
Example 36
From project cicada, under directory /cicada/src/org/cicadasong/cicada/.
Source file: CicadaService.java

private void startForeground(){ String notificationTitle=getString(R.string.notification_title); String notificationBody=getString(R.string.notification_body); Notification notification=new Notification(R.drawable.statusbar,notificationTitle,0); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,Cicada.class),0); notification.setLatestEventInfo(getApplicationContext(),notificationTitle,notificationBody,contentIntent); notification.flags|=Notification.FLAG_FOREGROUND_SERVICE; startForeground(1,notification); }
Example 37
From project Common-Sense-Net-2, under directory /RealFarm/src/com/commonsensenet/realfarm/sync/.
Source file: UpstreamTask.java

protected void sendMessage(ContextWrapper context,Model message){ Intent sentIntent=new Intent(SENT); sentIntent.putExtra("type",message.getModelTypeId()); sentIntent.putExtra("id",message.getId()); PendingIntent sentPI=PendingIntent.getBroadcast(context.getApplicationContext(),0,sentIntent,PendingIntent.FLAG_UPDATE_CURRENT); Intent deliveredIntent=new Intent(DELIVERED); deliveredIntent.putExtra("type",message.getModelTypeId()); deliveredIntent.putExtra("id",message.getId()); PendingIntent deliveredPI=PendingIntent.getBroadcast(context.getApplicationContext(),0,deliveredIntent,PendingIntent.FLAG_UPDATE_CURRENT); String sms=message.toSmsString(); ApplicationTracker.getInstance().logSyncEvent(EventType.SYNC,"UPSTREAM",sms); SmsManager sm=SmsManager.getDefault(); sm.sendTextMessage(SERVER_PHONE_NUMBER,null,sms,sentPI,deliveredPI); }
Example 38
From project conference-mobile-app, under directory /android-app/src/novoda/droidcon/homewidget/.
Source file: CountdownWidget.java

/** * Updates the counter */ private static void updateScore(final Context context){ final RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.widget_countdown); int remainingSec=(int)Math.max(0,(UIUtils.CONFERENCE_START_MILLIS - System.currentTimeMillis()) / 1000); final int secs=remainingSec % 86400; final int days=remainingSec / 86400; final String str=context.getResources().getQuantityString(R.plurals.widget_countdown_title,days,days,formatRemainingTime(secs)); views.setTextViewText(R.id.widget_title,str); final Intent appIntent=new Intent(context,HomeActivity.class); PendingIntent appStartPI=PendingIntent.getActivity(context,0,appIntent,0); views.setOnClickPendingIntent(R.id.countdown_widget,appStartPI); final ComponentName widget=new ComponentName(context,CountdownWidget.class); AppWidgetManager.getInstance(context).updateAppWidget(widget,views); }
Example 39
From project COSsettings, under directory /src/com/cyanogenmod/cmparts/provider/.
Source file: RenderFXWidgetProvider.java

private static PendingIntent getLaunchPendingIntent(Context context,int appWidgetId,int buttonId){ Intent launchIntent=new Intent(); launchIntent.setClass(context,RenderFXWidgetProvider.class); launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE); launchIntent.setData(Uri.parse("custom:" + appWidgetId + "/"+ buttonId)); PendingIntent pi=PendingIntent.getBroadcast(context,0,launchIntent,0); return pi; }
Example 40
From project creamed_glacier_app_settings, under directory /src/com/android/settings/.
Source file: ChooseLockGeneric.java

private Intent getBiometricSensorIntent(){ Intent fallBackIntent=new Intent().setClass(getActivity(),ChooseLockGeneric.class); fallBackIntent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK,true); fallBackIntent.putExtra(CONFIRM_CREDENTIALS,false); fallBackIntent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE,R.string.backup_lock_settings_picker_title); boolean showTutorial=ALWAY_SHOW_TUTORIAL || !mChooseLockSettingsHelper.utils().isBiometricWeakEverChosen(); Intent intent=new Intent(); intent.setClassName("com.android.facelock","com.android.facelock.SetupIntro"); intent.putExtra("showTutorial",showTutorial); PendingIntent pending=PendingIntent.getActivity(getActivity(),0,fallBackIntent,0); intent.putExtra("PendingIntent",pending); return intent; }
Example 41
From project cw-advandroid, under directory /AppWidget/LoremWidget/src/com/commonsware/android/appwidget/lorem/.
Source file: WidgetProvider.java

@Override public void onUpdate(Context ctxt,AppWidgetManager appWidgetManager,int[] appWidgetIds){ for (int i=0; i < appWidgetIds.length; i++) { Intent svcIntent=new Intent(ctxt,WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetIds[i]); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget=new RemoteViews(ctxt.getPackageName(),R.layout.widget); widget.setRemoteAdapter(appWidgetIds[i],R.id.words,svcIntent); Intent clickIntent=new Intent(ctxt,LoremActivity.class); PendingIntent clickPI=PendingIntent.getActivity(ctxt,0,clickIntent,PendingIntent.FLAG_UPDATE_CURRENT); widget.setPendingIntentTemplate(R.id.words,clickPI); appWidgetManager.updateAppWidget(appWidgetIds[i],widget); } super.onUpdate(ctxt,appWidgetManager,appWidgetIds); }
Example 42
From project cw-android, under directory /Notifications/FakePlayer/src/com/commonsware/android/fakeplayerfg/.
Source file: PlayerService.java

private void play(String playlist,boolean useShuffle){ if (!isPlaying) { Log.w(getClass().getName(),"Got to play()!"); isPlaying=true; Notification note=new Notification(R.drawable.stat_notify_chat,"Can you hear the music?",System.currentTimeMillis()); Intent i=new Intent(this,FakePlayer.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi=PendingIntent.getActivity(this,0,i,0); note.setLatestEventInfo(this,"Fake Player","Now Playing: \"Ummmm, Nothing\"",pi); note.flags|=Notification.FLAG_NO_CLEAR; startForeground(1337,note); } }
Example 43
From project cw-omnibus, under directory /AlarmManager/Scheduled/src/com/commonsware/android/schedsvc/.
Source file: PollReceiver.java

static void scheduleAlarms(Context ctxt){ AlarmManager mgr=(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(ctxt,ScheduledService.class); PendingIntent pi=PendingIntent.getService(ctxt,0,i,0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime() + PERIOD,PERIOD,pi); }
Example 44
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.
Source file: SearchView.java

/** * Create and return an Intent that can launch the voice search activity, perform a specific voice transcription, and forward the results to the searchable activity. * @param baseIntent The voice app search intent to start from * @return A completely-configured intent ready to send to the voice search activity */ private Intent createVoiceAppSearchIntent(Intent baseIntent,SearchableInfo searchable){ ComponentName searchActivity=searchable.getSearchActivity(); Intent queryIntent=new Intent(Intent.ACTION_SEARCH); queryIntent.setComponent(searchActivity); PendingIntent pending=PendingIntent.getActivity(getContext(),0,queryIntent,PendingIntent.FLAG_ONE_SHOT); Bundle queryExtras=new Bundle(); Intent voiceIntent=new Intent(baseIntent); String languageModel=RecognizerIntent.LANGUAGE_MODEL_FREE_FORM; String prompt=null; String language=null; int maxResults=1; Resources resources=getResources(); if (searchable.getVoiceLanguageModeId() != 0) { languageModel=resources.getString(searchable.getVoiceLanguageModeId()); } if (searchable.getVoicePromptTextId() != 0) { prompt=resources.getString(searchable.getVoicePromptTextId()); } if (searchable.getVoiceLanguageId() != 0) { language=resources.getString(searchable.getVoiceLanguageId()); } if (searchable.getVoiceMaxResults() != 0) { maxResults=searchable.getVoiceMaxResults(); } voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,languageModel); voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,prompt); voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,language); voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,maxResults); voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,searchActivity == null ? null : searchActivity.flattenToShortString()); voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT,pending); voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE,queryExtras); return voiceIntent; }
Example 45
From project adg-android, under directory /src/com/analysedesgeeks/android/os_service/.
Source file: PodcastPlaybackService.java

/** * Starts playback of a previously opened file. */ public void play(){ mAudioManager.registerMediaButtonEventReceiver(new ComponentName(this.getPackageName(),MediaButtonIntentReceiver.class.getName())); if (mPlayer.isInitialized()) { mPlayer.start(); final int icon=R.drawable.ic_notification; final CharSequence tickerText=description; final String title=getString(R.string.analyseDesGeeks); final long when=System.currentTimeMillis(); final Notification notification=new Notification(icon,tickerText,when); notification.flags|=Notification.FLAG_ONGOING_EVENT; final Intent contentIntent=new Intent(this,MainActivity.class); final PendingIntent appIntent=PendingIntent.getActivity(this,0,contentIntent,0); notification.setLatestEventInfo(this,title,description,appIntent); startForeground(PLAYBACKSERVICE_STATUS,notification); if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying=true; hasPlayed=true; } } }
Example 46
From project Airports, under directory /src/com/nadmm/airports/billing/.
Source file: BillingService.java

@Override protected long run() throws RemoteException { Bundle request=makeRequestBundle(Consts.BILLING_METHOD_REQUEST_PURCHASE); request.putString(ITEM_ID,mProductId); if (mDeveloperPayload != null) { request.putString(DEVELOPER_PAYLOAD,mDeveloperPayload); } Bundle response=mService.sendBillingRequest(request); PendingIntent pendingIntent=response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT); if (pendingIntent == null) { Log.e(TAG,"Error with requestPurchase"); return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID; } Intent intent=new Intent(); ResponseHandler.buyPageIntentResponse(pendingIntent,intent); return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID,Consts.BILLING_RESPONSE_INVALID_REQUEST_ID); }
Example 47
From project aksunai, under directory /src/org/androidnerds/app/aksunai/service/.
Source file: ChatManager.java

/** * MessageListeners */ public void onNewMessageList(String serverName,String messageListName){ if (AppConstants.DEBUG) Log.d(AppConstants.CHAT_TAG,"onNewMessageList(" + serverName + ", "+ messageListName+ ")"); mChatActivity.createChat(serverName,messageListName); Server s=mConnections.get(serverName); MessageList ml=s.mMessageLists.get(messageListName); ml.setOnNewMessageListener(this); boolean notify=mPrefs.getBoolean("pref_notification_bar",false); if (notify && ml.mType == MessageList.Type.PRIVATE) { Intent i=new Intent(this,ChatActivity.class); i.putExtra("server",serverName); i.putExtra("chat",messageListName); PendingIntent pending=PendingIntent.getActivity(this,0,i,0); Notification n=new Notification(android.R.drawable.stat_notify_chat,"New Message From " + messageListName,System.currentTimeMillis()); n.setLatestEventInfo(this,"Aksunai","New Message From " + messageListName,pending); String ringtone=mPrefs.getString("notification-ringtone",""); if (ringtone.equals("")) { n.defaults|=Notification.DEFAULT_SOUND; } else { n.sound=Uri.parse(ringtone); } if (mPrefs.getBoolean("pref_notification_vibrate",false)) { n.vibrate=new long[]{100,250,100,250}; } mNotificationManager.notify(R.string.notify_new_private_chat,n); } }
Example 48
From project alljoyn_java, under directory /ice/org/alljoyn/bus/.
Source file: AllJoynAndroidExt.java

public AllJoynAndroidExt(Context sContext){ ctx=sContext; wifiMgr=(WifiManager)ctx.getSystemService(Context.WIFI_SERVICE); try { if (!wifiMgr.startScan()) { Log.v(TAG,"startScan() returned error"); } if (tHandler == null) { tHandler=new Handler(); } tUpdateTimerRunnable=new Runnable(){ public void run(){ updateTimer(); } } ; tHandler.postDelayed(tUpdateTimerRunnable,0); if (alarmMgr == null) { alarmMgr=(AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent=new Intent(ctx,ScanResultsReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(ctx,0,alarmIntent,0); alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),1000 * 60 * 10,pi); } } catch ( SecurityException se) { Log.e(TAG,"Possible missing permissions needed to run ICE over AllJoyn. Discovery over ICE in AllJoyn may not work due to this"); se.printStackTrace(); } }
Example 49
From project Android-Battery-Widget, under directory /src/com/em/batterywidget/.
Source file: BatteryUpdateService.java

private RemoteViews getWidgetRemoteView(){ Preferences prefSettings=new Preferences(Constants.BATTERY_SETTINGS,this); Preferences prefBatteryInfo=new Preferences(Constants.BATTERY_INFO,this); level=prefBatteryInfo.getValue(Constants.LEVEL,0); status=prefBatteryInfo.getValue(Constants.STATUS,0); String color=prefSettings.getValue(Constants.TEXT_COLOUR_SETTINGS,Constants.DEFAULT_COLOUR); boolean charge=status == BatteryManager.BATTERY_STATUS_CHARGING; RemoteViews widgetView=new RemoteViews(this.getPackageName(),R.layout.widget_view); widgetView.setImageViewResource(R.id.battery_view,R.drawable.battery); widgetView.setViewVisibility(R.id.percent100,round(100) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent90,round(90) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent80,round(80) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent70,round(70) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent60,round(60) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent50,round(50) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent40,round(40) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent30,round(30) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent20,round(20) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.percent10,round(10) ? View.VISIBLE : View.INVISIBLE); widgetView.setViewVisibility(R.id.batterytext,View.VISIBLE); widgetView.setTextColor(R.id.batterytext,Color.parseColor(color)); widgetView.setTextViewText(R.id.batterytext,String.valueOf(level) + "%"); widgetView.setViewVisibility(R.id.charge_view,charge ? View.VISIBLE : View.INVISIBLE); NotificationsManager mNotificationsManager=new NotificationsManager(this); mNotificationsManager.updateNotificationIcon(prefSettings,prefBatteryInfo); Intent intent=new Intent(this,BatteryWidgetActivity.class); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); widgetView.setOnClickPendingIntent(R.id.widget_view,pendingIntent); return widgetView; }
Example 50
From project android-context, under directory /src/edu/fsu/cs/contextprovider/.
Source file: PrefsActivity.java

@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key){ if (key.equals(ContextConstants.PREFS_ACCURACY_POPUP_ENABLED) || key.equals(ContextConstants.PREFS_ACCURACY_POPUP_FREQ)) { if (DEBUG) { Toast.makeText(this,"ACCURACY_POPUP changed",Toast.LENGTH_SHORT).show(); } boolean accuracyPopupEnabled=prefs.getBoolean(ContextConstants.PREFS_ACCURACY_POPUP_ENABLED,true); String accuracyPopupPeriod=prefs.getString(ContextConstants.PREFS_ACCURACY_POPUP_FREQ,"45"); int period=Integer.parseInt(accuracyPopupPeriod); if (DEBUG) { Log.d(TAG,"accuracyPopupPeriod: " + accuracyPopupPeriod + " period: "+ period); } AlarmManager manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent intent=new Intent(getBaseContext(),edu.fsu.cs.contextprovider.wakeup.WakeupAlarmReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(getBaseContext(),0,intent,0); if (accuracyPopupEnabled) { manager.cancel(pi); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + 10000,period * 1000,pi); } else { manager.cancel(pi); } } }
Example 51
From project android-donations-lib, under directory /org_donations/src/org/donations/google/.
Source file: BillingService.java

@Override protected long run() throws RemoteException { Bundle request=makeRequestBundle("REQUEST_PURCHASE"); request.putString(Consts.BILLING_REQUEST_ITEM_ID,mProductId); if (mDeveloperPayload != null) { request.putString(Consts.BILLING_REQUEST_DEVELOPER_PAYLOAD,mDeveloperPayload); } try { Bundle response=mService.sendBillingRequest(request); PendingIntent pendingIntent=response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT); if (pendingIntent == null) { Log.e(TAG,"Error with requestPurchase"); return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID; } Intent intent=new Intent(); ResponseHandler.buyPageIntentResponse(pendingIntent,intent); return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID,Consts.BILLING_RESPONSE_INVALID_REQUEST_ID); } catch ( NullPointerException e) { initialiseMarket(); return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID; } }
Example 52
From project androidtracks, under directory /src/org/sfcta/cycletracks/.
Source file: RecordingService.java

public void remindUser(){ soundpool.play(bikebell,1.0f,1.0f,1,0,1.0f); NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); int icon=R.drawable.icon25; long when=System.currentTimeMillis(); int minutes=(int)(when - trip.startTime) / 60000; CharSequence tickerText=String.format("Still recording (%d min)",minutes); Notification notification=new Notification(icon,tickerText,when); notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_SHOW_LIGHTS; notification.ledARGB=0xffff00ff; notification.ledOnMS=300; notification.ledOffMS=3000; Context context=this; CharSequence contentTitle="CycleTracks - Recording"; CharSequence contentText="Tap to finish your trip"; Intent notificationIntent=new Intent(context,RecordingActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); final int RECORDING_ID=1; mNotificationManager.notify(RECORDING_ID,notification); }
Example 53
From project android_7, under directory /src/org/immopoly/android/c2dm/.
Source file: C2DMBaseReceiver.java

private void handleRegistration(final Context context,Intent intent){ final String registrationId=intent.getStringExtra(EXTRA_REGISTRATION_ID); String error=intent.getStringExtra(EXTRA_ERROR); String removed=intent.getStringExtra(EXTRA_UNREGISTERED); if (Log.isLoggable(TAG,Log.DEBUG)) { Log.d(TAG,"dmControl: registrationId = " + registrationId + ", error = "+ error+ ", removed = "+ removed); } if (removed != null) { C2DMessaging.clearRegistrationId(context); onUnregistered(context); return; } else if (error != null) { C2DMessaging.clearRegistrationId(context); Log.e(TAG,"Registration error " + error); onError(context,error); if ("SERVICE_NOT_AVAILABLE".equals(error)) { long backoffTimeMs=C2DMessaging.getBackoff(context); Log.d(TAG,"Scheduling registration retry, backoff = " + backoffTimeMs); Intent retryIntent=new Intent(C2DM_RETRY); PendingIntent retryPIntent=PendingIntent.getBroadcast(context,0,retryIntent,0); AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME,backoffTimeMs,retryPIntent); backoffTimeMs*=2; C2DMessaging.setBackoff(context,backoffTimeMs); } } else { try { onRegistered(context,registrationId); C2DMessaging.setRegistrationId(context,registrationId); } catch ( IOException ex) { Log.e(TAG,"Registration error " + ex.getMessage()); } } }
Example 54
From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.
Source file: CellBroadcastAlertService.java

/** * Display a full-screen alert message for emergency alerts. * @param message the alert to display */ private void openEmergencyAlertNotification(CellBroadcastMessage message){ acquireTimedWakelock(WAKE_LOCK_TIMEOUT); Intent closeDialogs=new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeDialogs); Intent audioIntent=new Intent(this,CellBroadcastAlertAudio.class); audioIntent.setAction(CellBroadcastAlertAudio.ACTION_START_ALERT_AUDIO); SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this); String duration=prefs.getString(CellBroadcastSettings.KEY_ALERT_SOUND_DURATION,CellBroadcastSettings.ALERT_SOUND_DEFAULT_DURATION); audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_DURATION_EXTRA,Integer.parseInt(duration)); int channelTitleId=CellBroadcastResources.getDialogTitleResource(message); CharSequence channelName=getText(channelTitleId); String messageBody=message.getMessageBody(); if (prefs.getBoolean(CellBroadcastSettings.KEY_ENABLE_ALERT_SPEECH,true)) { audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_BODY,messageBody); String language=message.getLanguageCode(); if (message.isEtwsMessage() && !"ja".equals(language)) { Log.w(TAG,"bad language code for ETWS - using Japanese TTS"); language="ja"; } else if (message.isCmasMessage() && !"en".equals(language)) { Log.w(TAG,"bad language code for CMAS - using English TTS"); language="en"; } audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_LANGUAGE,language); } startService(audioIntent); int notificationId=(int)message.getDeliveryTime(); Class c=CellBroadcastAlertDialog.class; KeyguardManager km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode()) { c=CellBroadcastAlertFullScreen.class; } Intent notify=createDisplayMessageIntent(this,c,message,notificationId); PendingIntent pi=PendingIntent.getActivity(this,notificationId,notify,0); Notification.Builder builder=new Notification.Builder(this).setSmallIcon(R.drawable.ic_notify_alert).setTicker(getText(CellBroadcastResources.getDialogTitleResource(message))).setWhen(System.currentTimeMillis()).setContentIntent(pi).setFullScreenIntent(pi,true).setContentTitle(channelName).setContentText(messageBody).setDefaults(Notification.DEFAULT_LIGHTS); NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId,builder.getNotification()); }
Example 55
From project android_packages_apps_phone, under directory /src/com/android/phone/.
Source file: EmergencyCallbackModeService.java

/** * Shows notification for Emergency Callback Mode */ private void showNotification(long millisUntilFinished){ Notification notification=new Notification(R.drawable.picture_emergency25x25,getText(R.string.phone_entered_ecm_text),0); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(EmergencyCallbackModeExitDialog.ACTION_SHOW_ECM_EXIT_DIALOG),0); String text=null; if (mInEmergencyCall) { text=getText(R.string.phone_in_ecm_call_notification_text).toString(); } else { int minutes=(int)(millisUntilFinished / 60000); String time=String.format("%d:%02d",minutes,(millisUntilFinished % 60000) / 1000); text=String.format(getResources().getQuantityText(R.plurals.phone_in_ecm_notification_time,minutes).toString(),time); } notification.setLatestEventInfo(this,getText(R.string.phone_in_ecm_notification_title),text,contentIntent); notification.flags=Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(R.string.phone_in_ecm_notification_title,notification); }
Example 56
/** * @see com.mexuar.corraleta.protocol.ProtocolEventListener#registered(com.mexuar.corraleta.protocol.Friend,boolean) */ public void registered(Friend f,boolean s){ final Intent intent=new Intent(this,AndroVoIP.class); final PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); final NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); final CharSequence mText=s ? "Registered" : "Unregistered"; final Notification notification=new Notification(R.drawable.icon,getString(R.string.app_name) + " " + mText,System.currentTimeMillis()); notification.setLatestEventInfo(this,getString(R.string.app_name) + " " + mText,f != null ? f.getStatus() : "",pendingIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0,notification); this.registered=s; if (s) { this.friend=f; } else if (this.friend != null) { this.friend.stop(); this.friend=null; } }
Example 57
From project ANE-In-App-Purchase, under directory /NativeAndroid/src/com/freshplanet/inapppurchase/.
Source file: BillingService.java

@Override protected long run() throws RemoteException { Log.d(TAG,"RequestPurchase response"); Bundle request=makeRequestBundle("REQUEST_PURCHASE"); request.putString(Consts.BILLING_REQUEST_ITEM_ID,mProductId); if (mDeveloperPayload != null) { request.putString(Consts.BILLING_REQUEST_DEVELOPER_PAYLOAD,mDeveloperPayload); } Bundle response=mService.sendBillingRequest(request); PendingIntent pendingIntent=response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT); if (pendingIntent == null) { Log.e(TAG,"Error with requestPurchase"); return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID; } Intent intent=new Intent(); ResponseHandler.buyPageIntentResponse(pendingIntent,intent); return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID,Consts.BILLING_RESPONSE_INVALID_REQUEST_ID); }
Example 58
From project Anki-Android, under directory /src/com/ichi2/anki/services/.
Source file: DownloadManagerService.java

/** * Show a notification informing the user when a deck is ready to be used */ private void showNotification(String deckTitle){ NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Resources res=getResources(); Notification notification=new Notification(R.drawable.anki,res.getString(R.string.download_finished),System.currentTimeMillis()); Intent loadDeckIntent=new Intent(Intent.ACTION_VIEW,Uri.parse(mDestination + "/" + deckTitle+ ".anki"),DownloadManagerService.this,StudyOptions.class); PendingIntent contentIntent=PendingIntent.getActivity(this,0,loadDeckIntent,0); notification.setLatestEventInfo(this,deckTitle,res.getString(R.string.deck_downloaded),contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notification.defaults|=Notification.DEFAULT_VIBRATE; notification.ledARGB=0xff0000ff; notification.ledOnMS=500; notification.ledOffMS=1000; notification.flags|=Notification.FLAG_SHOW_LIGHTS; Log.i(AnkiDroidApp.TAG,"Sending notification..."); mNotificationManager.notify(getNextNotificationId(),notification); }
Example 59
From project Apertiurm-Androind-app-devlopment, under directory /ApertiumAndroid/src/org/apertium/android/widget/.
Source file: WidgetProvider.java

void addClickListner(Context context,int widgetId){ Intent[] intent=new Intent[Modes.length]; PendingIntent[] pendingIntent=new PendingIntent[Modes.length]; for (int i=0; i < intent.length; i++) { intent[i]=new Intent(context,ApertiumActivity.class); intent[i].setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent[i].putExtra("Mode",Modes[i]); pendingIntent[i]=PendingIntent.getActivity(context,i,intent[i],PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(ButtonCode[i],pendingIntent[i]); } Intent ConfigIntent=new Intent(context,WidgetConfigActivity.class); ConfigIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); ConfigIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,widgetId); PendingIntent ConfigpendingIntent=PendingIntent.getActivity(context,0,ConfigIntent,PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.WidgetConfigButton,ConfigpendingIntent); }
Example 60
From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.
Source file: CheckUpdateService.java

static void schedule(Context context){ final Intent intent=new Intent(context,CheckUpdateService.class); final PendingIntent pending=PendingIntent.getService(context,0,intent,0); Calendar c=new GregorianCalendar(); c.add(Calendar.DAY_OF_YEAR,1); c.set(Calendar.HOUR_OF_DAY,0); c.set(Calendar.MINUTE,0); c.set(Calendar.SECOND,0); c.set(Calendar.MILLISECOND,0); final AlarmManager alarm=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pending); if (DEBUG) { alarm.setRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime(),30 * 1000,pending); } else { alarm.setRepeating(AlarmManager.RTC,c.getTimeInMillis(),UPDATES_CHECK_INTERVAL,pending); } }
Example 61
From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/.
Source file: ResourceService.java

void updateSettings(){ AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE); Intent intent=new Intent(ACTION_LOAD); PendingIntent pendingIntent=PendingIntent.getService(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); if (settings.getBoolean(ReaderActivity.PREFKEY_LOAD_IN_BACKGROUND,ReaderActivity.DEFAULT_LOAD_IN_BACKGROUND)) { String loadIntervalString=settings.getString(ReaderActivity.PREFKEY_LOAD_INTERVAL,ReaderActivity.DEFAULT_LOAD_INTERVAL); long loadInterval; if (loadIntervalString.equals("15_mins")) { loadInterval=AlarmManager.INTERVAL_FIFTEEN_MINUTES; } else if (loadIntervalString.equals("30_mins")) { loadInterval=AlarmManager.INTERVAL_HALF_HOUR; } else if (loadIntervalString.equals("1_hour")) { loadInterval=AlarmManager.INTERVAL_HOUR; } else if (loadIntervalString.equals("half_day")) { loadInterval=AlarmManager.INTERVAL_HALF_DAY; } else { loadInterval=AlarmManager.INTERVAL_HOUR; } long startingTime=System.currentTimeMillis() + loadInterval; if (settings.getBoolean(ReaderActivity.PREFKEY_RTC_WAKEUP,ReaderActivity.DEFAULT_RTC_WAKEUP)) { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,startingTime,loadInterval,pendingIntent); } else { alarmManager.setInexactRepeating(AlarmManager.RTC,startingTime,loadInterval,pendingIntent); } } else { alarmManager.cancel(pendingIntent); } }
Example 62
From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/activity/.
Source file: SettingsActivity.java

@Override public boolean onKeyDown(int keyCode,KeyEvent event){ if (keyCode == KeyEvent.KEYCODE_BACK) { if (mOriginalInterval != mSharedPreferences.getInt(Constants.SP_BL_INTERVAL_SERVICE,0)) { int serviceInterval=mSharedPreferences.getInt(Constants.SP_BL_INTERVAL_SERVICE,(Constants.HOUR_IN_SECONDS / 2)) * 1000; AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent=PendingIntent.getService(this,0,new Intent(this,BattlelogService.class),0); alarmManager.cancel(pendingIntent); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,0,serviceInterval,pendingIntent); Log.d(Constants.DEBUG_TAG,"Setting the service to update every " + serviceInterval / 60000 + " minutes"); } startActivity(new Intent(this,DashboardActivity.class)); finish(); return true; } return super.onKeyDown(keyCode,event); }
Example 63
From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/service/.
Source file: AutosyncReceiver.java

@Override public void onReceive(final Context context,final Intent intent){ final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context); final boolean prefsAutosync=prefs.getBoolean(Constants.PREFS_KEY_AUTOSYNC,false); final long prefsLastUsed=prefs.getLong(Constants.PREFS_KEY_LAST_USED,0); final Intent batteryChanged=context.getApplicationContext().registerReceiver(null,new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); final int batteryStatus=batteryChanged.getIntExtra(BatteryManager.EXTRA_STATUS,-1); boolean isPowerConnected=batteryStatus == BatteryManager.BATTERY_STATUS_CHARGING || batteryStatus == BatteryManager.BATTERY_STATUS_FULL; final boolean running=prefsAutosync && isPowerConnected; final AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); final Intent serviceIntent=new Intent(BlockchainService.ACTION_HOLD_WIFI_LOCK,null,context,BlockchainServiceImpl.class); final PendingIntent alarmIntent=PendingIntent.getService(context,0,serviceIntent,0); if (running) { context.startService(serviceIntent); final long now=System.currentTimeMillis(); final long lastUsedAgo=now - prefsLastUsed; final long alarmInterval; if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS) alarmInterval=AlarmManager.INTERVAL_FIFTEEN_MINUTES; else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS) alarmInterval=AlarmManager.INTERVAL_HOUR; else alarmInterval=AlarmManager.INTERVAL_HALF_DAY; alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,now,alarmInterval,alarmIntent); } else { alarmManager.cancel(alarmIntent); } }
Example 64
From project CHMI, under directory /src/org/kaldax/app/chmi/.
Source file: CHMIWidgetProvider.java

private void setNextAlarm(Context context,boolean bSooner){ Intent intentAlarm=new Intent(CHMIWidgetProvider.MY_WIDGET_UPDATE); PendingIntent pendingIntentAlarm=PendingIntent.getBroadcast(context,0,intentAlarm,0); AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Calendar calendar=Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int iCurrentMinutes=calendar.getTime().getMinutes(); int iMinutesToAdd=0; if (bSooner) { iMinutesToAdd=3; } else { if (iCurrentMinutes <= 30) { iMinutesToAdd=30 - iCurrentMinutes; } else { iMinutesToAdd=60 - iCurrentMinutes; } iMinutesToAdd+=1; } calendar.add(Calendar.MINUTE,iMinutesToAdd); alarmManager.setRepeating(AlarmManager.RTC,calendar.getTimeInMillis(),3600 * 1000,pendingIntentAlarm); }
Example 65
From project com.juick.android, under directory /src/com/juick/android/.
Source file: CheckUpdatesReceiver.java

@Override public void onReceive(Context context,Intent intent){ final String jsonStr=Utils.getJSON(context,"http://api.juick.com/notifications"); if (jsonStr != null && jsonStr.length() > 4) { try { JSONObject json=new JSONObject(jsonStr); int messages=json.getInt("messages"); String str="New messages: " + messages; Intent i=new Intent(context,MainActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT); Notification notification=new Notification(R.drawable.ic_notification,str,System.currentTimeMillis()); notification.setLatestEventInfo(context.getApplicationContext(),str,str,contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notification.defaults|=Notification.DEFAULT_LIGHTS; ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(1,notification); } catch ( JSONException e) { Log.e("CheckUpdatesReceiver",e.toString()); } } }
Example 66
From project connectbot, under directory /src/sk/vx/connectbot/service/.
Source file: ConnectionNotifier.java

protected Notification newActivityNotification(Context context,HostBean host){ Notification notification=newNotification(context); Resources res=context.getResources(); String contentText=res.getString(R.string.notification_text,host.getNickname()); Intent notificationIntent=new Intent(context,ConsoleActivity.class); notificationIntent.setAction("android.intent.action.VIEW"); notificationIntent.setData(host.getUri()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,res.getString(R.string.app_name),contentText,contentIntent); notification.flags=Notification.FLAG_AUTO_CANCEL; notification.flags|=Notification.DEFAULT_LIGHTS; if (HostDatabase.COLOR_RED.equals(host.getColor())) notification.ledARGB=Color.RED; else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) notification.ledARGB=Color.GREEN; else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) notification.ledARGB=Color.BLUE; else notification.ledARGB=Color.WHITE; notification.ledOnMS=300; notification.ledOffMS=1000; notification.flags|=Notification.FLAG_SHOW_LIGHTS; return notification; }
Example 67
From project agit, under directory /agit/src/main/java/com/madgag/agit/operation/lifecycle/.
Source file: RepoNotifications.java

@Inject public RepoNotifications(Context context,@Named("gitdir") File gitdir,PendingIntent manageGitRepo){ this.context=context; this.manageGitRepo=manageGitRepo; this.ongoingOpNotificationId=gitdir.hashCode(); this.completionNotificationId=ongoingOpNotificationId + 1; this.promptNotificationId=completionNotificationId + 1; notificationManager=(NotificationManager)context.getSystemService(NOTIFICATION_SERVICE); }
Example 68
From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/synchronisation/tracks/service/.
Source file: SynchronizationService.java

private void createNotification(){ int icon=R.drawable.shuffle_icon; CharSequence tickerText=this.getText(R.string.app_name); long when=System.currentTimeMillis(); Notification notification=new Notification(icon,tickerText,when); Intent notificationIntent=new Intent(this,SynchronizeActivity.class); notification.contentIntent=PendingIntent.getActivity(this,0,notificationIntent,0); notification.contentView=contentView; mNotificationManager.notify(NOTIFICATION_ID,notification); }
Example 69
From project android-voip-service, under directory /src/main/java/org/linphone/.
Source file: LinphoneService.java

@Override public void onCreate(){ super.onCreate(); instance=this; LinphonePreferenceManager.getInstance(this); PreferenceManager.setDefaultValues(this,R.xml.linphone_preferences,true); notificationTitle=getString(R.string.app_name); Hacks.dumpDeviceInformation(); dumpInstalledLinphoneInformation(); mNotificationMgr=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); mNotif=new Notification(R.drawable.status_level,"",System.currentTimeMillis()); mNotif.iconLevel=IC_LEVEL_ORANGE; mNotif.flags|=Notification.FLAG_ONGOING_EVENT; Intent notifIntent=new Intent(this,LinphoneActivity.class); mNotifContentIntent=PendingIntent.getActivity(this,0,notifIntent,0); mNotif.setLatestEventInfo(this,notificationTitle,"",mNotifContentIntent); mNotificationMgr.notify(NOTIF_ID,mNotif); LinphoneManager.createAndStart(this,this); }
Example 70
From project AndroidBillingLibrary, under directory /AndroidBillingLibrary/src/net/robotmedia/billing/.
Source file: BillingController.java

/** * Starts the specified purchase intent with the specified activity. * @param activity * @param purchaseIntent purchase intent. * @param intent */ public static void startPurchaseIntent(Activity activity,PendingIntent purchaseIntent,Intent intent){ if (Compatibility.isStartIntentSenderSupported()) { Compatibility.startIntentSender(activity,purchaseIntent.getIntentSender(),intent); } else { try { purchaseIntent.send(activity,0,intent); } catch ( CanceledException e) { Log.e(LOG_TAG,"Error starting purchase intent",e); } } }
Example 71
@SuppressLint("NewApi") public void setupNFC(){ mNfcAdapter=NfcAdapter.getDefaultAdapter(this); checkNfcEnabled(); Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android.cursor.dir/com.codebutler.farebot.card"); mPendingIntent=PendingIntent.getActivity(this,0,intent,0); mTechLists=new String[][]{new String[]{IsoDep.class.getName()},new String[]{MifareClassic.class.getName()},new String[]{MifareUltralight.class.getName()},new String[]{NfcF.class.getName()}}; }
Example 72
From project Birthdays, under directory /src/com/rexmenpara/birthdays/.
Source file: BirthdaysActivity.java

private void calendarSynced(){ NotificationManager.getInstance().cancel(Constants.APP_ID); Notification notification=new Notification(R.drawable.toolbar,"Calendar Sync complete.",System.currentTimeMillis()); Intent intent=new Intent(getApplicationContext(),BirthdaysActivity.class); notification.setLatestEventInfo(BirthdaysActivity.this,"Birthdays","Calendar synchronization complete",PendingIntent.getActivity(BirthdaysActivity.this.getBaseContext(),0,intent,PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags=Notification.FLAG_AUTO_CANCEL; NotificationManager.getInstance().notify(Constants.APP_ID,notification); }
Example 73
From project cornerstone, under directory /frameworks/base/services/java/com/android/server/am/.
Source file: ActivityManagerService.java

public PendingIntent getRunningServiceControlPanel(ComponentName name){ synchronized (this) { ServiceRecord r=mServices.get(name); if (r != null) { for ( ArrayList<ConnectionRecord> conn : r.connections.values()) { for (int i=0; i < conn.size(); i++) { if (conn.get(i).clientIntent != null) { return conn.get(i).clientIntent; } } } } } return null; }