예제 #1
1
  private void noticeNewBlog(Context context) {
    NotificationManager notiManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notiManager.cancel(Constants.NOTIFICATION_NEW_MICRO_BLOG); // 先清除上一次提醒;

    Intent intent = new Intent();
    // 粉丝
    if (entity.getContentType() == Skeleton.TYPE_MORE) {
      intent.setAction("com.shejiaomao.weibo.SOCIAL_GRAPH");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.putExtra("SOCIAL_GRAPH_TYPE", SocialGraphTask.TYPE_FOLLOWERS);
      intent.putExtra("USER", account.getUser());
    } else {
      intent.setAction("com.shejiaomao.weibo.MAIN");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    intent.putExtra("CONTENT_TYPE", entity.getContentType());
    intent.putExtra("ACCOUNT", account);

    Notification notification = new Notification();
    notification.icon = R.drawable.icon_notification;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.tickerText = entity.getTickerText();

    if (sheJiaoMao.isVibrateNotification()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (sheJiaoMao.isRingtoneNotification()) {
      if (StringUtil.isNotEmpty(sheJiaoMao.getRingtoneUri())) {
        notification.sound = Uri.parse(sheJiaoMao.getRingtoneUri());
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    if (sheJiaoMao.isFlashingLEDNotification()) {
      notification.ledARGB = Color.GREEN;
      notification.ledOffMS = 1000;
      notification.ledOnMS = 1000;
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    int requestCode = account.getAccountId().intValue() * 100 + entity.getContentType();
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(
        context, entity.getContentTitle(), entity.getContentText(), pendingIntent);

    notiManager.notify(requestCode, notification);
  }
예제 #2
0
  // Prepare notification data and display it.
  private void doNotification(Context context, Long messageId, Bitmap srcPhoto) {

    ChatMsgBaseInfo message = WalkArroundMsgManager.getInstance(context).getMessageById(messageId);

    if (message == null) {
      return;
    }

    ContactInfo contact =
        ContactsManager.getInstance(context).getContactByUsrObjId(message.getContact());

    Intent intent = new Intent();
    intent.setClass(context.getApplicationContext(), BuildMessageActivity.class);
    intent.putExtra(BuildMessageActivity.INTENT_RECEIVER_EDITABLE, false);
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_RECEIVER, message.getContact());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_THREAD_ID, message.getMsgThreadId());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_TYPE, message.getChatType());

    // TODO: contact should write to DB & we should crate a content provider for those contacts.
    if (contact != null) {
      intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_DISPLAY_NAME, contact.getUsername());
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // If the contact is null, set the user name as empty.
    String displayName = (contact == null ? "" : contact.getUsername());
    message.setData(MessageUtil.getDisplayStr(context, displayName, message));
    Notification notification = new Notification();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.icon = R.drawable.msg_notify_icon;

    // TODO: Add Emoji parser later.
    notification.tickerText = EmojiParser.getInstance(context).getSmileyText(message.getData());
    notification.tickerText = message.getData();

    if (Build.VERSION.SDK_INT == 19) {
      contentIntent.cancel();
      contentIntent =
          PendingIntent.getActivity(
              context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    notification.contentIntent = contentIntent;
    notification.contentView = new RemoteViews(context.getPackageName(), R.layout.msg_notify_panel);
    //        notification.defaults=Notification.DEFAULT_SOUND;
    initNotifyView(context, notification.contentView, message, contact, srcPhoto);
    try {
      String number = (contact == null ? DEFAULT_NOTIFICATION_ID : contact.getMobilePhoneNumber());
      int startPos = number.length() > 5 ? number.length() - 5 : 0;
      int id = Integer.parseInt(number.substring(startPos));
      NotificationManager manager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      manager.notify(number, id, notification);
    } catch (NumberFormatException e) {
      sLogger.e("notification NumberFormatException:" + e.getMessage());
    }
  }
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  public static void showNotification(Intent intent, Context c) {
    if (context == null) {
      context = c;
    }
    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent _intent = new Intent();

    /*if (hasAction) {
    	if (action.equalsIgnoreCase("View")) {
    		_intent = context.getPackageManager()
    				.getLaunchIntentForPackage(context.getPackageName());
    	}
    }*/
    _intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());

    int _icon = icon;
    String _message = message;
    int _badge = badge;
    long _time = time;
    String _action = action;

    if (intent != null) {
      _icon = intent.getIntExtra("icon", 0);
      _message = intent.getStringExtra("message");
      _badge = intent.getIntExtra("badge", 0);
      _time = intent.getLongExtra("time", new Date().getTime());
      _action = intent.getStringExtra("action");
    }

    Notification n = null;
    PendingIntent pi = PendingIntent.getActivity(context, 0, _intent, 0);
    if (Build.VERSION.SDK_INT >= 11) {
      Notification.Builder builder = new Notification.Builder(context);
      builder
          .setContentIntent(pi)
          .setSmallIcon(_icon)
          .setTicker(_message)
          .setNumber(_badge)
          .setWhen(_time)
          .setAutoCancel(true)
          .setContentTitle(_action)
          .setContentText(_message);
      n = builder.getNotification();
    } else {
      n = new Notification();
      n.contentIntent = pi;
      n.icon = android.R.drawable.ic_dialog_info;
      n.tickerText = _message;
      n.number = _badge;
      n.when = _time;
      n.flags |= Notification.FLAG_AUTO_CANCEL;
      n.setLatestEventInfo(context, _action, _message, pi);
    }

    nm.notify((int) (_time / 1000), n);
    showStatusBar();
  }
 @Override
 public void onFail(DownloadTask task) throws RemoteException {
   // TODO Auto-generated method stub
   if (mContext != null && task != null) {
     if (mNotificationManager != null) {
       // 移除之前的通知
       mNotificationManager.cancel(NOTIFY_TAG, (int) task.getId());
       // 更新下载信息
       if (mShowNotification && mNotification != null) {
         mNotification.tickerText = mFailTickerText;
         mNotification.contentIntent = mPendingIntent;
         //					mNotificationRemoteViews.setTextViewText(R.id.downloadTextView, mFailText);
         //					mNotification.contentView = mNotificationRemoteViews;
         mNotification.setLatestEventInfo(
             mContext,
             mFailText,
             mProgressText + " " + task.getAlreadyDownloadPercent() + "%",
             mPendingIntent);
         mNotification.flags = Notification.FLAG_AUTO_CANCEL;
         //					mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         if (mNotification.contentView != null) {
           mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         }
       }
     }
   }
 }
  private void showNotification(String title, String note, boolean isTaskComplete) {

    Notification notification =
        new Notification(R.drawable.liltomato, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_ONGOING_EVENT;

    if (isTaskComplete) {

      notification = new Notification(R.drawable.liltomato_red, null, System.currentTimeMillis());
      notification.flags = Notification.FLAG_ONGOING_EVENT;
      String ringtone = taskDatabaseMap.getPreferences().getRingtone();
      if (ringtone == null) {
        ringtone =
            "android.resource://"
                + getApplication().getPackageName()
                + "/"
                + R.raw.freesoundprojectdotorg_32568__erh__indian_brass_pestle;
      }

      notification.sound = Uri.parse(ringtone);

      if (taskDatabaseMap.getPreferences().notifyPhoneVibrate()) {
        notification.vibrate = new long[] {0, 100, 200, 300};
      }

      notification.tickerText = title;
      notification.defaults |= Notification.DEFAULT_LIGHTS;
    }

    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, new Intent(this, TaskBrowserActivity.class), 0);
    notification.setLatestEventInfo(this, title, note, contentIntent);
    notificationManager.notify(NOTIFICATION_ID, notification);
  }
예제 #6
0
  // 在onStartCommand()方法中准备相关的下载工作:
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    appName_en = getResources().getString(R.string.app_name_en);
    appName_cn = getResources().getString(R.string.app_name);
    // 获取传值
    appDownLoadURL = intent.getStringExtra(ConstantStrUtil.STR_APPDOWNLOADURL);
    // 创建文件
    if (android.os.Environment.MEDIA_MOUNTED.equals(
        android.os.Environment.getExternalStorageState())) {
      updateDir = new File(Environment.getExternalStorageDirectory(), "");
      updateFile = new File(updateDir.getPath(), appName_en + ".apk");
    }

    this.updateNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    this.updateNotification = new Notification();

    // 设置下载过程中,点击通知栏,回到主界面
    updateIntent = new Intent(this, AppStart.class);
    updatePendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);
    // 设置通知栏显示内容
    updateNotification.icon = R.drawable.logo1;
    updateNotification.tickerText = "开始下载";
    updateNotification.setLatestEventInfo(this, appName_cn, "0%", updatePendingIntent);
    // 发出通知
    updateNotificationManager.notify(0, updateNotification);

    // 开启一个新的线程下载,如果使用Service同步下载,会导致ANR问题,Service本身也会阻塞
    new Thread(new updateRunnable()).start(); // 这个是下载的重点,是下载的过程

    return super.onStartCommand(intent, flags, startId);
  }
 /**
  * This method sends a notification to NotificationManager to display an error dialog indicating
  * low disk space and launch the Installer application
  */
 private final void sendNotification() {
   if (localLOGV) Slog.i(TAG, "Sending low memory notification");
   // log the event to event log with the amount of free storage(in bytes) left on the device
   EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
   //  Pack up the values and broadcast them to everyone
   Intent lowMemIntent =
       new Intent(
           Environment.isExternalStorageEmulated()
               ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS
               : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
   lowMemIntent.putExtra("memory", mFreeMem);
   lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   NotificationManager mNotificationMgr =
       (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
   CharSequence title =
       mContext.getText(com.android.internal.R.string.low_internal_storage_view_title);
   CharSequence details =
       mContext.getText(com.android.internal.R.string.low_internal_storage_view_text);
   PendingIntent intent =
       PendingIntent.getActivityAsUser(mContext, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
   Notification notification = new Notification();
   notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
   notification.tickerText = title;
   notification.flags |= Notification.FLAG_NO_CLEAR;
   notification.setLatestEventInfo(mContext, title, details, intent);
   mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
   mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
 }
예제 #8
0
  public void createNotification() {
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    // // 这个参数是通知提示闪出来的值.
    notification.tickerText = "开始下载";
    //
    updateIntent = new Intent(this, MainActivity.class);
    pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);
    //
    // // 这里面的参数是通知栏view显示的内容
    notification.setLatestEventInfo(this, app_name, "下载:0%", pendingIntent);
    //
    notificationManager.notify(notification_id, notification);

    /** * 在这里我们用自定的view来显示Notification */
    contentView = new RemoteViews(getPackageName(), R.layout.notification_item);
    contentView.setTextViewText(R.id.notificationTitle, "正在下载");
    contentView.setTextViewText(R.id.notificationPercent, "0%");
    contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);

    notification.contentView = contentView;

    updateIntent = new Intent(this, MainActivity.class);
    updateIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);

    notification.contentIntent = pendingIntent;

    notificationManager.notify(notification_id, notification);
  }
예제 #9
0
  @Override
  protected void onHandleIntent(Intent intent) {
    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification.Builder builder = new Notification.Builder(this);

    builder
        .setContent(buildContent(0))
        .setTicker(getText(R.string.ticker), buildTicker())
        .setContentIntent(buildContentIntent())
        .setLargeIcon(buildLargeIcon())
        .setSmallIcon(R.drawable.ic_stat_notif_small_icon)
        .setOngoing(true);

    Notification notif = builder.getNotification();

    for (int i = 0; i < 20; i++) {
      notif.contentView.setProgressBar(android.R.id.progress, 100, i * 5, false);
      mgr.notify(NOTIFICATION_ID, notif);

      if (i == 0) {
        notif.tickerText = null;
        notif.tickerView = null;
      }

      SystemClock.sleep(1000);
    }

    mgr.cancel(NOTIFICATION_ID);
  }
 @Override
 public void onCancel(DownloadTask task) throws RemoteException {
   if (task != null) {
     sendBroadcastingToAppCenter(task);
     stopAppGameNetLog(task);
     if (mNotificationManager != null) {
       if (mShowNotification && mNotification != null) {
         // 更新下载信息
         mNotification.tickerText = mCancelTickerText;
         mNotification.contentIntent = mPendingIntent;
         mNotification.flags = Notification.FLAG_AUTO_CANCEL;
         //					mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         if (mNotification.contentView != null) {
           mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         }
       }
     }
     String filePath = task.getSaveFilePath();
     if (TextUtils.isEmpty(filePath)) {
       return;
     }
     File saveFile = new File(filePath);
     if (saveFile.exists()) {
       saveFile.delete();
     }
   }
 }
 @Override
 public void onStop(DownloadTask task) throws RemoteException {
   if (mNotificationManager != null && mNotification != null) {
     mNotification.tickerText = mStopTickerText;
     mNotification.flags = Notification.FLAG_AUTO_CANCEL;
     mNotification.contentIntent = mPendingIntent;
     //			if (RecommAppsUtils.isZh()) {
     mNotification.setLatestEventInfo(
         mContext,
         mPauseText,
         mProgressText + " " + task.getAlreadyDownloadPercent() + "%",
         mPendingIntent);
     //			} else {
     //				mNotification.setLatestEventInfo(mContext, mPauseText,
     //						task.getAlreadyDownloadPercent() + "%",
     //						mPendingIntent);
     //			}
     //			mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
     if (mNotification.contentView != null) {
       mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
     }
   }
   if (task != null) {
     // add by xiedezhi
     sendBroadcastingToAppCenter(task);
   }
 }
예제 #12
0
  @SuppressWarnings("deprecation")
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = android.R.drawable.stat_sys_download;
    // notification.icon=android.R.drawable.stat_sys_download_done;
    notification.tickerText = getString(R.string.app_name) + "下载";
    notification.when = System.currentTimeMillis();
    notification.defaults = Notification.DEFAULT_LIGHTS;
    // 设置任务栏中下载进程显示的views
    views = new RemoteViews(getPackageName(), R.layout.version_update);
    notification.contentView = views;
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    notification.setLatestEventInfo(this, "", "", contentIntent);
    // 将下载任务添加到任务栏中
    nm.notify(notificationId, notification);

    myHandler = new MyHandler(Looper.myLooper(), this);

    // 初始化下载任务内容views
    Message message = myHandler.obtainMessage(3, 0);
    myHandler.sendMessage(message);

    // 启动线程�?��执行下载任务
    downFile(intent.getStringExtra("url"));
    return super.onStartCommand(intent, flags, startId);
  }
  public void update(int dockLevel, boolean charging) {
    int icon =
        charging
            ? R.drawable
                .stat_sys_battery_charge // local copy of android.R.drawable.stat_sys_battery_charge
            : R.drawable.stat_sys_battery; // local copy of android.R.drawable.stat_sys_battery

    // Notification Builder straight up refuses to create a notification without a ticker :(
    /*Notification notification = new Notification.Builder(mContext)
    .setSmallIcon(icon, dockLevel)
    .setContentTitle(title)
    .setContentText("Dock battery level: " + dockLevel + "%")
    //.setNumber(dockLevel)
    .setAutoCancel(false)
    .setOngoing(true)
    .setOnlyAlertOnce(true)
    .setTicker(null)
    .getNotification();*/

    Notification notification = new Notification(icon, null, System.currentTimeMillis());
    notification.iconLevel = dockLevel;
    notification.flags =
        Notification.FLAG_ONGOING_EVENT
            | Notification.FLAG_ONLY_ALERT_ONCE
            | Notification.FLAG_NO_CLEAR;
    notification.setLatestEventInfo(
        mContext, title, "Dock battery level: " + dockLevel + "%", null);

    notification.tickerText = null;
    notification.contentView.setInt(android.R.id.icon, "setImageLevel", dockLevel);
    mNotificationManager.notify(NOTIFICATION_DOCK, notification);
  }
예제 #14
0
  @Override
  public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);

    boolean visible;
    int iconId, textResId;

    if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
      // GPS is getting fixes
      iconId = com.android.internal.R.drawable.stat_sys_gps_on;
      textResId = R.string.gps_notification_found_text;
      visible = true;
    } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
      // GPS is off
      visible = false;
      iconId = textResId = 0;
    } else {
      // GPS is on, but not receiving fixes
      iconId = R.drawable.stat_sys_gps_acquiring_anim;
      textResId = R.string.gps_notification_searching_text;
      visible = true;
    }

    try {
      if (visible) {
        Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, gpsIntent, 0);

        Notification n =
            new Notification.Builder(mContext)
                .setSmallIcon(iconId)
                .setContentTitle(mContext.getText(textResId))
                .setOngoing(true)
                .setContentIntent(pendingIntent)
                .getNotification();

        // Notification.Builder will helpfully fill these out for you no matter what you do
        n.tickerView = null;
        n.tickerText = null;

        n.priority = Notification.PRIORITY_HIGH;

        int[] idOut = new int[1];
        mNotificationService.enqueueNotificationWithTag(
            mContext.getPackageName(), null, GPS_NOTIFICATION_ID, n, idOut);
      } else {
        mNotificationService.cancelNotification(mContext.getPackageName(), GPS_NOTIFICATION_ID);
      }
    } catch (android.os.RemoteException ex) {
      // well, it was worth a shot
    }
  }
예제 #15
0
 private void notifyAlert(String title, String info, int flags) {
   notification.tickerText = title;
   notification.flags = flags;
   initSoundVibrateLights(notification);
   notification.setLatestEventInfo(
       this,
       getString(R.string.app_name) + " | " + Utils.getProfileName(profile),
       info,
       pendIntent);
   notificationManager.cancel(0);
   notificationManager.notify(0, notification);
 }
예제 #16
0
 /*
 	@Override
 	public void onBackPressed() {
 		super.onBackPressed();
 		// XmppConnection.closeConnection();
 		System.exit(0);
 	}
 */
 protected void setNotiType(int iconId, String s) {
   Intent intent = new Intent();
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   PendingIntent appIntent = PendingIntent.getActivity(this, 0, intent, 0);
   Notification myNoti = new Notification();
   myNoti.icon = iconId;
   myNoti.tickerText = s;
   myNoti.defaults = Notification.DEFAULT_SOUND;
   myNoti.flags |= Notification.FLAG_AUTO_CANCEL;
   myNoti.setLatestEventInfo(this, "QQ消息", s, appIntent);
   mNotificationManager.notify(0, myNoti);
 }
예제 #17
0
 private void notifyAlert(String title, String info) {
   notification.tickerText = title;
   notification.flags = Notification.FLAG_ONGOING_EVENT;
   // notification.defaults = Notification.DEFAULT_SOUND;
   initSoundVibrateLights(notification);
   notification.setLatestEventInfo(
       this,
       getString(R.string.app_name) + " | " + Utils.getProfileName(profile),
       info,
       pendIntent);
   notificationManager.cancel(1);
   startForegroundCompat(1, notification);
 }
예제 #18
0
파일: U.java 프로젝트: tangbotony/Android
 private void initNofication() {
   notificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   notification = new Notification();
   notification.icon = R.drawable.ic_launcher; //
   notification.tickerText = "正在下载,请稍后!"; //
   Intent intent = new Intent();
   intent.setClass(context, Ri.class);
   PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
   notification.contentIntent = contentIntent;
   notificationViews = new RemoteViews(context.getPackageName(), R.layout.down_notification);
   notificationViews.setImageViewResource(R.id.download_icon, R.drawable.ic_launcher);
 }
    private void updateUsbNotification() {
      if (mNotificationManager == null || !mUseUsbNotification) return;
      int id = 0;
      Resources r = mContext.getResources();
      if (mConnected) {
        if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
          id = com.android.internal.R.string.usb_mtp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
          id = com.android.internal.R.string.usb_ptp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MASS_STORAGE)) {
          id = com.android.internal.R.string.usb_cd_installer_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
          id = com.android.internal.R.string.usb_accessory_notification_title;
        } else {
          // There is a different notification for USB tethering so we don't need one here
          // if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
          //    Slog.e(TAG, "No known USB function in updateUsbNotification");
          // }
        }
      }
      if (id != mUsbNotificationId) {
        // clear notification if title needs changing
        if (mUsbNotificationId != 0) {
          mNotificationManager.cancelAsUser(null, mUsbNotificationId, UserHandle.ALL);
          mUsbNotificationId = 0;
        }
        if (id != 0) {
          CharSequence message = r.getText(com.android.internal.R.string.usb_notification_message);
          CharSequence title = r.getText(id);

          Notification notification = new Notification();
          notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
          notification.when = 0;
          notification.flags = Notification.FLAG_ONGOING_EVENT;
          notification.tickerText = title;
          notification.defaults = 0; // please be quiet
          notification.sound = null;
          notification.vibrate = null;
          notification.priority = Notification.PRIORITY_MIN;

          Intent intent =
              Intent.makeRestartActivityTask(
                  new ComponentName("com.android.settings", "com.android.settings.UsbSettings"));
          PendingIntent pi =
              PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
          notification.setLatestEventInfo(mContext, title, message, pi);
          mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
          mUsbNotificationId = id;
        }
      }
    }
예제 #20
0
 /**
  * Configures service as a foreground service. A foreground service is a service that's doing
  * something the user is actively aware of (such as playing music), and must appear to the user as
  * a notification. That's why we create the notification here.
  */
 void setUpAsForeground(String text) {
   PendingIntent pi =
       PendingIntent.getActivity(
           getApplicationContext(),
           0,
           new Intent(getApplicationContext(), MainActivity.class),
           PendingIntent.FLAG_UPDATE_CURRENT);
   mNotification = new Notification();
   mNotification.tickerText = text;
   mNotification.icon = R.drawable.ic_stat_playing;
   mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
   mNotification.setLatestEventInfo(getApplicationContext(), "RandomMusicPlayer", text, pi);
   startForeground(NOTIFICATION_ID, mNotification);
 }
 private void showNotify() {
   NotificationManager manager =
       (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification notification = new Notification();
   notification.icon = R.drawable.notify_icon;
   notification.tickerText = "天天价会员特权";
   notification.defaults = Notification.DEFAULT_SOUND;
   notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;
   notification.flags = Notification.FLAG_AUTO_CANCEL;
   Intent intent = new Intent(this, Member_Aty.class);
   PendingIntent pendingIntent =
       PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
   notification.setLatestEventInfo(this, "天天价会员特权", "点击查看详情", pendingIntent);
   manager.notify(10, notification);
 }
예제 #22
0
  public void createNotification() {
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = R.drawable.ic_launcher;

    notification.tickerText = "正在下载";

    updateIntent = new Intent(this, SplashActivity.class);
    updateIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);

    notification.setLatestEventInfo(this, "锁锁应用", "下载:0%", pendingIntent);

    notificationManager.notify(notification_id, notification);
  }
예제 #23
0
파일: U.java 프로젝트: tangbotony/Android
        @Override
        public void handleMessage(Message msg) {
          if (msg.what == updateProgress) { // 更新下载进度
            int fileSize = downLoadUtil.getRealSize();
            int totalReadSize = downLoadUtil.getTotalSize();
            if (totalReadSize > 0) {
              float size = (float) totalReadSize * 100 / (float) fileSize;
              DecimalFormat format = new DecimalFormat("0.00");
              String progress = format.format(size);
              notificationViews.setTextViewText(R.id.progressTv, "已下了" + progress + "%");
              notificationViews.setProgressBar(R.id.progressBar, 100, (int) size, false);
              notification.contentView = notificationViews;
              notificationManager.notify(notificationID, notification);
            }
          } else if (msg.what == downloadSuccess) { // 下载完成
            notificationViews.setTextViewText(R.id.progressTv, "下载完成");
            notificationViews.setProgressBar(R.id.progressBar, 100, 100, false);
            notification.contentView = notificationViews;
            notification.tickerText = "下载完成";
            notificationManager.notify(notificationID, notification);
            if (timer != null && task != null) {
              timer.cancel();
              task.cancel();
              timer = null;
              task = null;
            }
            // 安装apk
            Uri uri = Uri.fromFile(new File(saveFile + "/" + fileName));
            Intent installIntent = new Intent(Intent.ACTION_VIEW);
            installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
            // PendingIntent 通知栏跳转
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, installIntent, 0);
            notification.flags = Notification.FLAG_AUTO_CANCEL;
            notification.contentIntent = pendingIntent;
            notification.contentView.setTextViewText(R.id.progressTv, "下载完成,点击安装!");
            notificationManager.notify(notificationID, notification);

          } else if (msg.what == downloadError) { // 下载失败
            if (timer != null && task != null) {
              timer.cancel();
              task.cancel();
              timer = null;
              task = null;
            }
            notificationManager.cancel(notificationID);
          }
        }
예제 #24
0
  // 通知バーにお知らせを表示する関数
  public void showNotification(int image, String title, String text, int id) {
    Notification notification = new Notification();
    notification.icon = image;
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    PendingIntent pendingIntent;
    pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

    notification.setLatestEventInfo(getApplicationContext(), title, text, pendingIntent);

    notification.tickerText = text;

    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, notification);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0)
            == 1
        && Telephony.Sms.Intents.SMS_REJECTED_ACTION.equals(intent.getAction())) {

      int reason = intent.getIntExtra("result", -1);
      boolean outOfMemory = reason == Telephony.Sms.Intents.RESULT_SMS_OUT_OF_MEMORY;
      if (!outOfMemory) {
        // Right now, the only user-level rejection we show to the user is out-of-memory.
        return;
      }

      NotificationManager nm =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

      Intent viewConvIntent = new Intent(context, ConversationList.class);
      viewConvIntent.setAction(Intent.ACTION_VIEW);
      viewConvIntent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK
              | Intent.FLAG_ACTIVITY_SINGLE_TOP
              | Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, viewConvIntent, 0);

      Notification notification = new Notification();

      // TODO: need appropriate icons
      notification.icon = R.drawable.stat_sys_no_sim;
      int titleId;
      int bodyId;
      if (outOfMemory) {
        titleId = R.string.sms_full_title;
        bodyId = R.string.sms_full_body;
      } else {
        titleId = R.string.sms_rejected_title;
        bodyId = R.string.sms_rejected_body;
      }
      notification.tickerText = context.getString(titleId);
      notification.defaults = Notification.DEFAULT_ALL;

      notification.setLatestEventInfo(
          context, context.getString(titleId), context.getString(bodyId), pendingIntent);
      nm.notify(SMS_REJECTED_NOTIFICATION_ID, notification);
    }
  }
  private Notification createNotification(String text) {
    Notification notification = new Notification();

    notification.icon = R.drawable.logo;
    notification.when = System.currentTimeMillis();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.ledARGB = Color.WHITE;
    notification.ledOnMS = 1500;
    notification.ledOffMS = 1500;
    notification.tickerText = text;

    return notification;
  }
예제 #27
0
 public void sendNote(String title, String text, String dia_show) {
   // 通知显示
   NotificationManager noteman1 =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification note1 = new Notification();
   note1.icon = R.mipmap.ic_launcher;
   note1.tickerText = title; // 翻动显示
   note1.when = System.currentTimeMillis();
   note1.defaults = Notification.DEFAULT_ALL; // 访问灯光、震动需要权限
   note1.flags = Notification.FLAG_AUTO_CANCEL; // 点击消失
   Intent intent = new Intent(context, ClockDialog.class); // 点击启动主程序
   // 添加数据//此处不必理会记录写入等问题,因为我已经取消了它的显示//使用它需要修改AnRing存储的传递模式
   intent.putExtra("method", ClockDialog.METHOD_NOTE_CLICK);
   intent.putExtra("text", dia_show);
   PendingIntent pend = PendingIntent.getActivity(context, 0, intent, 0);
   note1.setLatestEventInfo(context, title, text, pend); // 固定显示
   noteman1.notify(0, note1);
 }
예제 #28
0
  @SuppressWarnings("deprecation")
  public void playNotification(
      Context context,
      Class<?> cls,
      String textNotification,
      String titleNotification,
      int drawable) {
    /* NOTIFICATION VARS */
    NotificationManager nm;
    int SIMPLE_NOTIFICATION_ID = 1;
    Notification notifyDetails;
    /* NOTIFICATION INICIO */
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notifyDetails = new Notification(drawable, titleNotification, System.currentTimeMillis());
    // long[] vibrate = { 100, 100, 200, 300 };
    // notifyDetails.vibrate = vibrate;
    notifyDetails.defaults = Notification.DEFAULT_ALL;
    notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
    /* NOTIFICATION FIN */

    CharSequence contentTitle = titleNotification;
    CharSequence contentText = textNotification;

    Intent notifyIntent = new Intent(context, cls);

    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent intent =
        PendingIntent.getActivity(
            context, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

    notifyDetails.tickerText = textNotification;
    notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);

    try {

      nm.notify(SIMPLE_NOTIFICATION_ID, notifyDetails);

    } catch (Exception e) {
      System.out.println("ERROR NOTIFI MANAGER: " + e.toString() + "  " + e.getMessage());
    }
  }
 public static Notification createNotification(
     Context context,
     int iconId,
     int tickerTextResId,
     int contentTextResId,
     PendingIntent pendingIntent) {
   String tickerText = context.getString(tickerTextResId);
   String contentText = context.getString(contentTextResId);
   if (ApiHelper.getAPILevel() < 11) {
     Notification notification = new Notification();
     notification.tickerText = tickerText;
     notification.when = System.currentTimeMillis();
     //noinspection deprecation
     notification.icon = iconId;
     notification.contentIntent = pendingIntent;
     // Google removed setLatestEventInfo in sdk 23.
     //noinspection TryWithIdenticalCatches
     try {
       Method method =
           Notification.class.getMethod(
               "setLatestEventInfo",
               Context.class,
               CharSequence.class,
               CharSequence.class,
               PendingIntent.class);
       method.invoke(notification, context, tickerText, contentText, pendingIntent);
     } catch (NoSuchMethodException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (IllegalAccessException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (InvocationTargetException e) {
       Log.v(TAG, e.getMessage(), e);
     }
     return notification;
   } else if (ApiHelper.getAPILevel() < 16) {
     return Api11Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   } else {
     return Api16Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   }
 }
예제 #30
0
 /**
  * This method can be overriden in order to create a foreground SpiceService. By default, it will
  * create a notification that can be used to set a spiceService to foreground (depending on the
  * versions of Android, the behavior is different : before ICS, no notification is shown, on ICS+,
  * a notification is shown with app icon). On Jelly Bean+, the notifiation only appears when
  * notification bar is expanded / pulled down.
  *
  * @return a notification used to tell user that the SpiceService is still running and processing
  *     requests.
  */
 @SuppressWarnings("deprecation")
 public Notification createDefaultNotification() {
   Notification notification = new Notification();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
       && android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
     notification.icon = getApplicationInfo().icon;
     // temporary fix https://github.com/octo-online/robospice/issues/200
     PendingIntent pendingIntent =
         PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
     notification.setLatestEventInfo(this, "", "", pendingIntent);
   } else {
     notification.icon = 0;
   }
   notification.tickerText = null;
   notification.when = System.currentTimeMillis();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
     notification.priority = Notification.PRIORITY_MIN;
   }
   return notification;
 }