本文整理汇总了Java中android.content.Context.NOTIFICATION_SERVICE属性的典型用法代码示例。如果您正苦于以下问题:Java Context.NOTIFICATION_SERVICE属性的具体用法?Java Context.NOTIFICATION_SERVICE怎么用?Java Context.NOTIFICATION_SERVICE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Context
的用法示例。
在下文中一共展示了Context.NOTIFICATION_SERVICE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNewIntent
@Override
public void onNewIntent(Intent intent){
//Log.i(TAG, "onNewIntent début");
startService(new Intent(DetailsActivity.this, LogReader.class));
Bundle extras = getIntent().getExtras();
int page;
String from;
if (extras != null)
{
page = extras.getInt("level");
from = extras.getString("title");
if (from.equals("notif")){
actionBar.setSelectedNavigationItem(page);
/*getIntent().removeExtra("level");
getIntent().removeExtra("title");*/
getIntent().putExtra("level", 0);
getIntent().putExtra("title", "");
//Log.i(TAG, "onCreate go to page " + page);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
nMgr.cancel(page * 10 + 1);
nMgr.cancel(page * 10 + 2);
nMgr.cancel(page * 10 + 3);
}
} else {
//Log.i(TAG, "onCreate extra is null");
}
}
示例2: onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
DbClear dbClear = new DbClear();
int size;
float fontSize;
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
switch (item.getItemId()) {
case R.id.action_flattr:
Intent intentFlattr = new Intent(Intent.ACTION_VIEW, Uri.parse(FLATTR_LINK));
startActivity(intentFlattr);
break;
case R.id.action_project:
Intent intentProj= new Intent(Intent.ACTION_VIEW, Uri.parse(PROJECT_LINK));
startActivity(intentProj);
break;
case R.id.action_feedsources:
Intent intentfs = new Intent(MainActivity.this, FeedSourcesActivity.class);
intentfs.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intentfs);
break;
case R.id.action_regex:
Intent intentreg = new Intent(MainActivity.this, PrefRegexActivity.class);
intentreg.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intentreg);
break;
case R.id.action_preferences:
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
break;
case R.id.action_delNotifies:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) ctx.getSystemService(ns);
nMgr.cancelAll();
break;
case R.id.action_readedFeeds:
dbClear.execute(R.id.action_readedFeeds);
break;
case R.id.action_delFeeds:
dbClear.execute(R.id.action_delFeeds);
break;
case R.id.action_biggerText:
fontSize = mPreferences.getFloat("font_size", AnotherRSS.Config.DEFAULT_FONT_SIZE);
fontSize = fontSize * 1.1f;
mPreferences.edit().putFloat("font_size", fontSize).apply();
break;
case R.id.action_smallerText:
fontSize = mPreferences.getFloat("font_size", AnotherRSS.Config.DEFAULT_FONT_SIZE);
fontSize = fontSize * 0.9f;
if (fontSize < 3.0f) fontSize = 3.0f;
mPreferences.edit().putFloat("font_size", fontSize).apply();
break;
case R.id.action_biggerImageSize:
size = mPreferences.getInt("image_width", AnotherRSS.Config.DEFAULT_MAX_IMG_WIDTH);
size = size + 20;
mPreferences.edit().putInt("image_width", size).apply();
break;
case R.id.action_smallerImageSize:
size = mPreferences.getInt("image_width", AnotherRSS.Config.DEFAULT_MAX_IMG_WIDTH);
size = size - 10;
if (size < 0) size = 0;
mPreferences.edit().putInt("image_width", size).apply();
break;
default:
break;
}
return true;
}
示例3: showNotification
public static void showNotification(final Context context, final String contentText){
//创建一个NotificationManager的引用
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager)context.getSystemService(ns);
// 定义Notification的各种属性
int icon = R.mipmap.ic_launcher; //notification icon
CharSequence tickerText = "the class name of current activity"; //状态栏显示的通知文本提示
long when = System.currentTimeMillis(); //通知产生的时间,会在通知信息里显示
//用上面的属性初始化 Nofification
mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(icon);
mBuilder.setTicker(tickerText);
mBuilder.setWhen(when);
/*
* 添加声音
* notification.defaults |=Notification.DEFAULT_SOUND;
* 或者使用以下几种方式
* notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
* notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
* 如果想要让声音持续重复直到用户对通知做出反应,则可以在notification的flags字段增加"FLAG_INSISTENT"
* 如果notification的defaults字段包括了"DEFAULT_SOUND"属性,则这个属性将覆盖sound字段中定义的声音
*/
/*
* 添加振动
* notification.defaults |= Notification.DEFAULT_VIBRATE;
* 或者可以定义自己的振动模式:
* long[] vibrate = {0,100,200,300}; //0毫秒后开始振动,振动100毫秒后停止,再过200毫秒后再次振动300毫秒
* notification.vibrate = vibrate;
* long数组可以定义成想要的任何长度
* 如果notification的defaults字段包括了"DEFAULT_VIBRATE",则这个属性将覆盖vibrate字段中定义的振动
*/
/*
* 添加LED灯提醒
* notification.defaults |= Notification.DEFAULT_LIGHTS;
* 或者可以自己的LED提醒模式:
* notification.ledARGB = 0xff00ff00;
* notification.ledOnMS = 300; //亮的时间
* notification.ledOffMS = 1000; //灭的时间
* notification.flags |= Notification.FLAG_SHOW_LIGHTS;
*/
/*
* 更多的特征属性
* notification.flags |= FLAG_AUTO_CANCEL; //在通知栏上点击此通知后自动清除此通知
* notification.flags |= FLAG_INSISTENT; //重复发出声音,直到用户响应此通知
* notification.flags |= FLAG_ONGOING_EVENT; //将此通知放到通知栏的"Ongoing"即"正在运行"组中
* notification.flags |= FLAG_NO_CLEAR; //表明在点击了通知栏中的"清除通知"后,此通知不清除,
* //经常与FLAG_ONGOING_EVENT一起使用
* notification.number = 1; //number字段表示此通知代表的当前事件数量,它将覆盖在状态栏图标的顶部
* //如果要使用此字段,必须从1开始
* notification.iconLevel = ; //
*/
//设置通知的事件消息
// CharSequence contentTitle = "当前界面的全限定类名"; //通知栏标题
Intent notificationIntent = new Intent(context,MainActivity.class); //点击该通知后要跳转的Activity
PendingIntent contentIntent = PendingIntent.getActivity(context,0,notificationIntent,0);
RemoteViews view_custom = getRemoteViews(context, contentText);
PendingIntent pendButtonIntent = getPendingIntent(context, contentText);
view_custom.setOnClickPendingIntent(R.id.btn, pendButtonIntent);
mBuilder.setCustomContentView(view_custom);
mBuilder.setContentIntent(contentIntent);
mBuilder.setOngoing(true);
//把Notification传递给 NotificationManager
mNotificationManager.notify(0,mBuilder.build());
}
示例4: showNotification
@SuppressLint("StringFormatInvalid")
private void showNotification(final String msg, String tickerText, boolean lowpriority, long when, ConnectionStatus status) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = getIconByConnectionStatus(status);
Notification.Builder nbuilder = new Notification.Builder(this);
if (mProfile != null) nbuilder.setContentTitle(getString(R.string.notifcation_title, mProfile.mName));
else nbuilder.setContentTitle(getString(R.string.notifcation_title_notconnect));
nbuilder.setContentText(msg);
nbuilder.setOnlyAlertOnce(true);
nbuilder.setOngoing(true);
nbuilder.setContentIntent(getLogPendingIntent());
nbuilder.setSmallIcon(icon);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
nbuilder.setColor(Color.GREEN);
}
if (when != 0) nbuilder.setWhen(when);
// Try to set the priority available since API 16 (Jellybean)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
jbNotificationExtras(lowpriority, nbuilder);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
lpNotificationExtras(nbuilder);
}
if (tickerText != null && !tickerText.equals("")){
nbuilder.setTicker(tickerText);
}
@SuppressWarnings("deprecation") Notification notification = nbuilder.getNotification();
mNotificationManager.notify(OPENVPN_STATUS, notification);
startForeground(OPENVPN_STATUS, notification);
// Check if running on a TV
if (runningOnAndroidTV() && !lowpriority) guiHandler.post(new Runnable() {
@Override
public void run() {
if (mlastToast != null) mlastToast.cancel();
String toastText = String.format(Locale.getDefault(), "%s - %s", mProfile.mName, msg);
mlastToast = Toast.makeText(getBaseContext(), toastText, Toast.LENGTH_SHORT);
mlastToast.show();
}
});
}