| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
8年前发布

Notification最佳实践

长按通知以后进入自定义设置页面

<activity android:name="SettingsActivity"          android:label="@string/app_name">      <intent-filter>          <action android:name="android.intent.action.MAIN" />          <category android:name=              "android.intent.category.DEFAULT" />          <category android:anme=              "android.intent.category.NOTIFICATION_PREFERENCES" />      </intent-filter>  </activity>
</div>

作者顺便推广了一把通过 PreferenceFragment 与 Preference xml 很简单就实现一个设置页面.

Add more actionable button on Notification

new NotificationCompat.Builder(this)      .setSamllIcon(...)      .setContentTitle(title)      .setContentText(text)      .addAction(R.drawable.ic_answer,          getString(R.string.call_answer),          answerPendingIntent)      .addAction(R.drawable.ic_ignore,          getString(R.string.call_ignore),          ignorePendingIntent)      .build();
</div>

new Notification.Builder(this)      .setSmallIcon(...)      .setContentTitle(title)      .setContentText(text)      // started in Jelly Bean      .setStyle(          new Notification.BigPictureStyle()          .bigPicture(photoBitmap))      .build();        // rich text?      .setStyle(          new Notification.BigTextStyle()              .bigText(longText))      .build();
</div>

多端同步,如果一端的notification被干掉,同步到其他端也将其干掉。

onGoing Notification

用户无法划掉

  • startForeground()
  • incoming calls
  • prefer snooze-and-repost pattern

需要给用户可以划掉/干掉的机会

如:音乐播放器在播放的时候无法划掉,在暂停/停止的时候,允许用户划掉(改优先级)(Google Music目前的做法)如: SSH/V*N连接在连接上的时候无法划掉,但是提供Action断开链接就自动干掉

IV. Delight the user

两种用户:

  1. 从来都不开声音,要不只开振动
  2. 始终都开通知声音,并且喜欢去设置声音类型针对不同的应用

设置通知声音

<RingtonePreference      android:persistent="true"      android:key="sms_sound"      android:denpendency="sms_enable"      android:ringtoneType="notification"      android:title="@string/sms_sound" />
</div>
SharedPreferences prefs = PreferenceManager      .getDefaultSharedPreferences(context);  String url = prefs.getString(SOUND, null);  if(uri != null){      builder.setSound(Uri.parse(uri));  }
</div>

V. Connect them to the people they love

系统提供指定联系人(星标) ,其余联系人不打扰的模式,因此我们可以在不请求获取联系人权限的情况下通过以下的方式进行对通知绑定

new Notification.Builder(this)      .setSmallIcon(...)      .setLargeIcon(...)      .setContentTilte(senderName)      .setContentText(msgText)      .addAction(...)      // email      .addPerson(Uri.fromParts("mailto",          "igzhenjie@gmail.com", null)          .toString())      .build();        // tel      .addPerson(Uri.fromParts("tel",          "1(617) 555-1212", null)          .toString())
</div> </div>

来自: http://blog.dreamtobe.cn/2016/01/09/notification_best_practise/

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!