本文整理匯總了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();
}
});
}