Пример #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
  // 在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);
  }
Пример #3
0
  private void setupView() {
    progressBar = (ProgressBar) findViewById(R.id.download_progress);
    //		btn_confirm = (Button)findViewById(R.id.btn_confirm);
    btn_cancel = (Button) findViewById(R.id.btn_cancel);
    //		btn_confirm.setOnClickListener(buttonclick);
    btn_cancel.setOnClickListener(buttonclick);

    if ("0".equals(mInfo.updateForce)) {
      btn_cancel.setVisibility(View.GONE);
    }

    server_des = (TextView) findViewById(R.id.server_des);
    progress_text = (TextView) findViewById(R.id.progress_text);
    TextView updateDesc = (TextView) findViewById(R.id.updateDesc);
    StringBuilder desc = new StringBuilder("当前版本:").append(mInfo.localVersion).append("\n");
    desc.append("服务器版本:").append(mInfo.latestVersion);
    updateDesc.setText(desc);
    server_des.setText(mInfo.updateDesc);

    manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    view = new RemoteViews(getPackageName(), R.layout.upgrade_progress_notice);
    Intent intent = new Intent(this, DownloadView.class);
    pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.contentView = view;
    notification.contentIntent = pIntent;
    // 通知的图标必须设置(其他属性为可选设置),否则通知无法显示
    notification.icon = R.drawable.ic_launcher;
    view.setImageViewResource(R.id.image, R.drawable.ic_launcher); // 起一个线程用来更新progress
  }
Пример #4
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);
  }
Пример #5
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);
  }
 /**
  * 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);
 }
Пример #7
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());
    }
  }
Пример #8
0
  private void setNotification(CamcorderNodeService.State state) {
    boolean isStreaming = state == CamcorderNodeService.State.STREAMING;

    Intent intent = new Intent(getContext(), ControllerActivity.class);

    int notifTitle;
    int notifText;
    int iconId;
    if (isStreaming) {
      notifTitle = R.string.recording_notif_title;
      notifText = R.string.recording_notif_text;
      iconId = android.R.drawable.stat_sys_phone_call;
    } else {
      notifTitle = R.string.running_notif_title;
      notifText = R.string.running_notif_text;
      iconId = android.R.drawable.stat_sys_upload;
    }

    Notification notif = new Notification();
    notif.icon = iconId;
    notif.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    notif.setLatestEventInfo(
        getContext(),
        getContext().getString(notifTitle),
        getContext().getString(notifText),
        PendingIntent.getActivity(getContext(), 0, intent, 0));

    mNotifMgr.notify(NOTIF_ID, notif);
  }
  @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();
  }
 private void setUpNotificationRelative() {
   notification = new Notification();
   notification.when = System.currentTimeMillis();
   notification.defaults = Notification.DEFAULT_LIGHTS;
   notification.icon = android.R.drawable.stat_sys_download;
   notification.contentIntent =
       PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_CANCEL_CURRENT);
   notificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
 }
Пример #11
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;
 }
Пример #12
0
  private void initSoundVibrateLights(Notification notification) {
    final String ringtone = settings.getString("settings_key_notif_ringtone", null);
    AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
      notification.sound = null;
    } else if (ringtone != null) notification.sound = Uri.parse(ringtone);
    else notification.defaults |= Notification.DEFAULT_SOUND;

    if (settings.getBoolean("settings_key_notif_icon", true)) {
      notification.icon = R.drawable.ic_stat;
    } else {
      notification.icon = R.drawable.ic_stat_trans;
    }

    if (settings.getBoolean("settings_key_notif_vibrate", false)) {
      long[] vibrate = {0, 1000, 500, 1000, 500, 1000};
      notification.vibrate = vibrate;
    }

    notification.defaults |= Notification.DEFAULT_LIGHTS;
  }
Пример #13
0
  private Notification getDownFinishedNotification(File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);

    Notification noti = new Notification();
    noti.setLatestEventInfo(mContext, mPackageHelper.getAppName(), "下载完成,点击安装", pendingIntent);
    noti.icon = android.R.drawable.stat_sys_download_done;
    noti.flags =
        Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
    return noti;
  }
Пример #14
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);
 }
  public void updateNotification() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean hideNotificationIcon = sharedPreferences.getBoolean("HideNotificationIcon", false);
    if (Preferences.logging)
      Log.d(
          MetaWatch.TAG,
          "MetaWatchService.updateNotification(): hideNotificationIcon=" + hideNotificationIcon);
    switch (connectionState) {
      case ConnectionState.CONNECTING:
        notification.icon =
            (hideNotificationIcon ? R.drawable.transparent_square : R.drawable.disconnected);
        notification.setLatestEventInfo(
            this, "MetaWatch Manager", "Connecting", createNotificationPendingIntent());
        broadcastConnection(false);
        break;
      case ConnectionState.CONNECTED:
        notification.icon =
            (hideNotificationIcon ? R.drawable.transparent_square : R.drawable.connected);
        notification.setLatestEventInfo(
            this,
            getResources().getString(R.string.app_name),
            getResources().getString(R.string.connection_connected),
            createNotificationPendingIntent());
        broadcastConnection(true);
        break;
      default:
        notification.icon =
            (hideNotificationIcon ? R.drawable.transparent_square : R.drawable.disconnected);
        notification.setLatestEventInfo(
            this,
            getResources().getString(R.string.app_name),
            getResources().getString(R.string.connection_disconnected),
            createNotificationPendingIntent());
        broadcastConnection(false);
        break;
    }

    startForeground(1, notification);
    notifyClients();
  }
    @Override
    protected void onPostExecute(Boolean postUploadedSuccessfully) {
      if (postUploadedSuccessfully) {
        WordPress.postUploaded(post.getRemotePostId());
        nm.cancel(notificationID);
        WordPress.wpDB.deleteMediaFilesForPost(post);
      } else {
        String postOrPage =
            (String)
                (post.isPage()
                    ? context.getResources().getText(R.string.page_id)
                    : context.getResources().getText(R.string.post_id));
        Intent notificationIntent =
            new Intent(context, post.isPage() ? PagesActivity.class : PostsActivity.class);
        notificationIntent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK
                | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.setData(
            (Uri.parse("custom://wordpressNotificationIntent" + post.getLocalTableBlogId())));
        notificationIntent.putExtra(PostsActivity.EXTRA_VIEW_PAGES, post.isPage());
        notificationIntent.putExtra(PostsActivity.EXTRA_ERROR_MSG, mErrorMessage);
        if (mErrorUnavailableVideoPress) {
          notificationIntent.putExtra(
              PostsActivity.EXTRA_ERROR_INFO_TITLE, getString(R.string.learn_more));
          notificationIntent.putExtra(PostsActivity.EXTRA_ERROR_INFO_LINK, Constants.videoPressURL);
        }
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent =
            PendingIntent.getActivity(
                context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        n.flags |= Notification.FLAG_AUTO_CANCEL;
        n.icon = android.R.drawable.stat_notify_error;
        String errorText = context.getResources().getText(R.string.upload_failed).toString();
        if (mIsMediaError)
          errorText =
              context.getResources().getText(R.string.media)
                  + " "
                  + context.getResources().getText(R.string.error);
        n.setLatestEventInfo(
            context,
            (mIsMediaError) ? errorText : context.getResources().getText(R.string.upload_failed),
            (mIsMediaError) ? mErrorMessage : postOrPage + " " + errorText + ": " + mErrorMessage,
            pendingIntent);

        nm.notify(notificationID, n); // needs a unique id
      }

      postUploaded();
    }
Пример #17
0
 /**
  * 下载中 这个是不支持断点下载的 所以无法显示进度
  *
  * @author [email protected] 2014-3-2 下午11:33:43
  * @return Notification
  */
 public void downNotification(String text) {
   Notification notfi = new Notification();
   notfi.icon = android.R.drawable.stat_sys_download;
   notfi.flags |= Notification.FLAG_ONGOING_EVENT;
   Intent intent = null;
   if (clazz != null) {
     intent = new Intent(ApplicationBean.getApplication(), clazz);
   }
   PendingIntent pendingIntent =
       PendingIntent.getService(mContext, 0, intent == null ? new Intent() : intent, 0);
   notfi.setLatestEventInfo(mContext, mPackageHelper.getAppName(), text, pendingIntent);
   mContextNotificationManager.notify(id, notfi);
 }
Пример #18
0
 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;
        }
      }
    }
        @Override
        public void dispatchMessage(Message msg) {
          SharedPreferences sp = mContext.getSharedPreferences(HConst.UPDATE_FLAG, 0);
          switch (msg.what) {
            case 0:
              if (sp.getBoolean(HConst.ISSHOW_NOTIFA, true)) {
                Editor editor = sp.edit();
                editor.putString(HConst.P, p);
                editor.putString(HConst.URL, url);
                editor.commit();

                NotificationManager notificationManager =
                    (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.cancel(0);
                Notification notification = new Notification();
                notification.icon = R.drawable.icon;
                notification.defaults = Notification.DEFAULT_SOUND;
                notification.flags = Notification.FLAG_AUTO_CANCEL;

                Intent notificationIntent = new Intent(mContext, HUpdateDialog.class);
                notificationIntent.putExtra("showNotification", "show");
                // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

                sp.edit().putBoolean(HConst.ISSHOW_NOTIFA, false).commit();

                PendingIntent contentIntent =
                    PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
                notification.setLatestEventInfo(
                    mContext,
                    mContext.getString(R.string.havenewTitle),
                    mContext.getString(R.string.normal_update_content),
                    contentIntent);
                notificationManager.notify(0, notification);
              }
              break;

            case 1:
              // 首次检查出强制更新,点击取消按钮之后,之后就不再提醒
              if (sp.getBoolean(HConst.ISSHOW_FORCEUPDATE, true)) {
                Intent intent = new Intent();
                intent.setAction(HConst.ACTION_UPDATE_DIALOG);
                mContext.sendBroadcast(intent);
              }
              break;
            case 2:
              // Toast.makeText(mContext, mContext.getString(R.string.nonew),
              // Toast.LENGTH_SHORT).show();
              break;
          }
        }
Пример #21
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);
 }
 public void doAction(View view) {
   RemoteViews remoteview = new RemoteViews(this.getPackageName(), R.layout.item);
   Intent intent = new Intent(this, nz.kapsy.sampleappnotification2.SampleAppNotification2.class);
   PendingIntent pending =
       PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
   Notification notify = new Notification();
   notify.contentView = remoteview;
   notify.flags = Notification.FLAG_AUTO_CANCEL;
   notify.icon = R.drawable.ic_launcher;
   notify.contentIntent = pending;
   NotificationManager manager =
       (NotificationManager) this.getSystemService(Activity.NOTIFICATION_SERVICE);
   manager.notify(0, notify);
 }
Пример #23
0
 /**
  * 下载成功或者失败以后 刷新顶部通知栏
  *
  * @author [email protected] 2014-3-2 下午11:33:43
  * @return Notification
  */
 public void downShowNotification(String text) {
   Intent intent = new Intent();
   if (clazz != null) {
     intent = new Intent(ApplicationBean.getApplication(), clazz);
     intent.addCategory(Intent.CATEGORY_LAUNCHER);
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
   }
   PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
   Notification noti = new Notification();
   noti.setLatestEventInfo(mContext, mPackageHelper.getAppName(), text, pendingIntent);
   noti.icon = android.R.drawable.stat_sys_download_done;
   noti.flags =
       Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
   mContextNotificationManager.notify(id, noti);
 }
Пример #24
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);
  }
 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);
 }
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     method = "setLatestEventInfo",
     args = {
       android.content.Context.class, java.lang.CharSequence.class,
       java.lang.CharSequence.class, android.app.PendingIntent.class
     })
 public void testSetLatestEventInfo() {
   mNotification = new Notification();
   mNotification.icon = 1;
   final Intent intent = new Intent();
   final PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
   mNotification.setLatestEventInfo(mContext, CONTENT_TITLE, CONTENT_TEXT, contentIntent);
   assertTrue(mNotification.contentView instanceof RemoteViews);
   assertNotNull(mNotification.contentView);
 }
Пример #27
0
  private Notification createDownloadProgressNotification(String title) {
    final RemoteViews contentView =
        new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setTextViewText(R.id.download_notification_title, title);
    contentView.setTextViewText(R.id.download_notification_progress_text, "");
    contentView.setProgressBar(R.id.download_notification_progress_bar, 100, 0, true);

    final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);

    final Notification notification = new Notification();
    notification.icon = android.R.drawable.stat_sys_download;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;
    notification.contentIntent = contentIntent;

    return notification;
  }
Пример #28
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);
  }
Пример #29
0
  public void initNotif() {
    mDownProgrNotif = new Notification();
    mDownProgrNotif.icon = android.R.drawable.stat_sys_download;
    mDownProgrNotif.flags |= Notification.FLAG_ONGOING_EVENT;

    mRemoteViews = new RemoteViews(mPackageHelper.getPackageName(), layout_id);
    mRemoteViews.setImageViewResource(icon_id, mPackageHelper.getAppIcon());

    mDownProgrNotif.contentView = mRemoteViews;
    Intent intent = null;
    if (clazz != null) {
      intent = new Intent(ApplicationBean.getApplication(), clazz);
    }
    mDownProgrNotif.contentIntent =
        PendingIntent.getService(mContext, 0, intent == null ? new Intent() : intent, 0);
    //		mContextNotificationManager.notify(id, mDownProgrNotif);
  }
  @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);
    }
  }