本文整理了Java中org.apache.flume.Context
类的一些代码示例,展示了Context
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context
类的具体详情如下:
包路径:org.apache.flume.Context
类名称:Context
[英]The context is a key-value store used to pass configuration information throughout the system.
[中]上下文是一个键值存储,用于在整个系统中传递配置信息。
代码示例来源:origin: stackoverflow.com
private static void generateNotification(Context context, String message){
Intent notificationIntent = new Intent(context, YOUR_ACTIVITY.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.app_name))
.setContentIntent(intent)
.setPriority(PRIORITY_HIGH) //private static final PRIORITY_HIGH = 5;
.setContentText(message)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
代码示例来源:origin: apache/flume
@Override
public void configure(Context context) {
this.pollFrequency = context.getInteger(this.CONF_POLL_FREQUENCY, 60);
String localHosts = context.getString(this.CONF_HOSTS);
if (localHosts == null || localHosts.isEmpty()) {
throw new ConfigurationException("Hosts list cannot be empty.");
}
this.hosts = this.getHostsFromString(localHosts);
this.isGanglia3 = context.getBoolean(this.CONF_ISGANGLIA3, false);
}
代码示例来源:origin: apache/flume
@Override
public void configure(Context context) {
super.configure(context);
serializerType = context.getString("serializer", "TEXT");
useRawLocalFileSystem = context.getBoolean("hdfs.useRawLocalFileSystem",
false);
serializerContext =
new Context(context.getSubProperties(EventSerializer.CTX_PREFIX));
logger.info("Serializer = " + serializerType + ", UseRawLocalFileSystem = "
+ useRawLocalFileSystem);
}
代码示例来源:origin: stackoverflow.com
public static String getApplicationName(Context context) {
ApplicationInfo applicationInfo = context.getApplicationInfo();
int stringId = applicationInfo.labelRes;
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
}
代码示例来源:origin: apache/flume
protected UUIDInterceptor(Context context) {
headerName = context.getString(HEADER_NAME, "id");
preserveExisting = context.getBoolean(PRESERVE_EXISTING_NAME, true);
prefix = context.getString(PREFIX_NAME, "");
}
代码示例来源:origin: apache/flume
@Override
public void configure(Context context) {
syncIntervalBytes =
context.getInteger(SYNC_INTERVAL_BYTES, DEFAULT_SYNC_INTERVAL_BYTES);
compressionCodec =
context.getString(COMPRESSION_CODEC, DEFAULT_COMPRESSION_CODEC);
staticSchemaURL = context.getString(STATIC_SCHEMA_URL, DEFAULT_STATIC_SCHEMA_URL);
}
代码示例来源:origin: stackoverflow.com
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
代码示例来源:origin: stackoverflow.com
public class ExternalReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("ExternalReceiver","onReceive");
Bundle extras = intent.getExtras();
StringBuilder payload = new StringBuilder();
for(String key : extras.keySet()){
payload.append(String.format("%s=%s", key, extras.getString(key)) + '\n');
}
Intent newIntent = new Intent();
newIntent.setClass(context, AndroidMobilePushApp.class);
newIntent.putExtra(context.getString(R.string.msg_field), payload.toString());
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(newIntent);
}
}
代码示例来源:origin: stackoverflow.com
public static void StartEmailIntent (Context cx, String EmailAddress){
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAddress});
cx.startActivity(Intent.createChooser(email, cx.getString(R.string.dlg_sendmail_selectortitle)));
}
代码示例来源:origin: stackoverflow.com
private void generateNotification(Context context, String message ) {
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message);
String title = context.getString(R.string.app_name);
Intent notificationIntent;
notificationIntent = new Intent(context, ActivityName.class);
notificationIntent.putExtra("From", "notifyFrag");
notificationIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notificationIntent .setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
代码示例来源:origin: stackoverflow.com
public static void writeReviewMail(Context context) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "youremail@example.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.yoursubject));
context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.contact_us)));
}
代码示例来源:origin: stackoverflow.com
public Notification buildNotification(Context context) {
Intent displayIntent = new Intent(context, AnimatedNotificationDisplayActivity.class);
displayIntent.putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE, context.getString(nameResId));
PendingIntent displayPendingIntent = PendingIntent.getActivity(context, 0, displayIntent, 0);
return buildBasicNotification(context)
.extend(new Notification.WearableExtender()
.setDisplayIntent(displayPendingIntent))
.build();
}
代码示例来源:origin: stackoverflow.com
@Override
public void onReceive(Context context, Intent intent) {
String medName = intent.getStringExtra(ReminderActivity.INTENT_MEDICINE_KEY);
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher_notification, context.getString(R.string.medication_alarm),
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MedicationActivity.class), 0);
notification.setLatestEventInfo(context, context.getString(R.string.app_name), context.getString(R.string.notification_message)+" "+medName,
contentIntent);
notificationManager.notify(R.string.alarm_tag, notification);
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
}
代码示例来源:origin: stackoverflow.com
//Create and register receiver
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(context.getString(R.string.intent_message_location_fetched))
&& intent.getExtras().getBoolean(LocationManager.KEY_PROXIMITY_ENTERING))
{
Toast.makeText(activityContext, "LOCATION INTENT WORKS!", Toast.LENGTH_SHORT).show();
}
}
};
activityContext.registerReceiver(mReceiver, new IntentFilter(activityContext.getString(R.string.intent_message_location_fetched)));
代码示例来源:origin: stackoverflow.com
public static void shareMultiple(List<File> files, Context context){
ArrayList<Uri> uris = new ArrayList<>();
for(File file: files){
uris.add(Uri.fromFile(file));
}
final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("*/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.ids_msg_share)));
}
代码示例来源:origin: stackoverflow.com
public static void goToMarket(Context context){
Intent it = new Intent(Intent.ACTION_VIEW);
it.setData(Uri.parse(context.getString(R.string.playstorelink)));
context.startActivity(it);
}
代码示例来源:origin: stackoverflow.com
public class BroadcastTimer extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TimeSet timeSet = (TimeSet) context;
int time = intent.getExtras().getInt(Constants.INTENT_BROADCAST_TIME);
int min = (time) / 60;
int sec = time % 60;
timeSet.FinalResult(min + context.getString(R.string.str_mins) + sec + context.getString(R.string.str_secs));
}
}
代码示例来源:origin: stackoverflow.com
public class MyActivity extends Activity {
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final boolean connected = intent.getBooleanExtra(context.getString(R.string.connected), false);
if (connected) {
// Do something.
}
}
};
}
代码示例来源:origin: stackoverflow.com
public static void notify(Context context, int id, int titleResId, int textResId, PendingIntent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(titleResId);
String text = context.getString(textResId);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setTicker(title)
.setContentIntent(intent);
notificationManager.notify(id, builder.build());
代码示例来源:origin: apache/flume
@Override
public void configure(Context context) {
Configurables.ensureRequiredNonNull(
context, SyslogSourceConfigurationConstants.CONFIG_PORT);
port = context.getInteger(SyslogSourceConfigurationConstants.CONFIG_PORT);
host = context.getString(SyslogSourceConfigurationConstants.CONFIG_HOST);
formaterProp = context.getSubProperties(
SyslogSourceConfigurationConstants.CONFIG_FORMAT_PREFIX);
keepFields = SyslogUtils.chooseFieldsToKeep(
context.getString(
SyslogSourceConfigurationConstants.CONFIG_KEEP_FIELDS,
SyslogSourceConfigurationConstants.DEFAULT_KEEP_FIELDS));
clientIPHeader =
context.getString(SyslogSourceConfigurationConstants.CONFIG_CLIENT_IP_HEADER);
clientHostnameHeader =
context.getString(SyslogSourceConfigurationConstants.CONFIG_CLIENT_HOSTNAME_HEADER);
if (sourceCounter == null) {
sourceCounter = new SourceCounter(getName());
}
}
内容来源于网络,如有侵权,请联系作者删除!