随笔
- android 6.0(api 23) SDK之后Notification中setLatestEventInfo废弃;
新的解决方法是新建Builder对象,将之前的
notification.setLatestEventInfo(this,"this is content title","this is content text",Intent);替换成
builder.setContentTitle(titile);
builder.setContentText(content);
builder.setContentIntent(contentItent);
如下:
public static void showNotice(Context context, String titile,
String content, Intent intent, int ioc, int userSound) {
Notification.Builder builder = new Notification.Builder(context);//新建Notification.Builder对象
UserMsgSharedPreference uspf = new UserMsgSharedPreference(context);
int requestId = uspf.getRequestId();
PendingIntent contentItent = PendingIntent.getActivity(context,
requestId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentTitle(titile);
builder.setContentText(content);
builder.setContentIntent(contentItent);//执行intent
requestId++;
uspf.setRequestId(requestId);
mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int notifyId = uspf.getNotifyId();
Notification notification = builder.build();//将builder对象转换为普通的notification
if (userSound == Notification.DEFAULT_SOUND) {
notification.defaults = Notification.DEFAULT_SOUND; // 系统默认声音,点击/清楚消失
} else {
notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + userSound);
}
notification.defaults |= Notification.DEFAULT_VIBRATE;// --添加震动
notification.flags = Notification.FLAG_AUTO_CANCEL;// --点击清除通知震动
notification.icon = ioc;
notification.when = System.currentTimeMillis();
mNotificationManager.notify(notifyId, notification);
notifyId++;
uspf.setNotifyId(notifyId);
}
- android 6.0(api 23) SDK,不再提供org.apache.http.*(只保留几个类)
Android Studion解决办法
android {
useLibrary 'org.apache.http.legacy'
}
- Android6.0之后需要动态申请权限,下面是在Google提供的demo
google demo地址
以下是需要单独申请的权限,共分为9组,每组只要有一个权限申请成功了,就默认整组权限都可以使用了。
group:android.permission-group.CONTACTS
permission:android.permission.WRITE_CONTACTS
permission:android.permission.GET_ACCOUNTS
permission:android.permission.READ_CONTACTS
group:android.permission-group.PHONE
permission:android.permission.READ_CALL_LOG
permission:android.permission.READ_PHONE_STATE
permission:android.permission.CALL_PHONE
permission:android.permission.WRITE_CALL_LOG
permission:android.permission.USE_SIP
permission:android.permission.PROCESS_OUTGOING_CALLS
permission:com.android.voicemail.permission.ADD_VOICEMAIL
group:android.permission-group.CALENDAR
permission:android.permission.READ_CALENDAR
permission:android.permission.WRITE_CALENDAR
group:android.permission-group.CAMERA
permission:android.permission.CAMERA
group:android.permission-group.SENSORS
permission:android.permission.BODY_SENSORS
group:android.permission-group.LOCATION
permission:android.permission.ACCESS_FINE_LOCATION
permission:android.permission.ACCESS_COARSE_LOCATION
group:android.permission-group.STORAGE
permission:android.permission.READ_EXTERNAL_STORAGE
permission:android.permission.WRITE_EXTERNAL_STORAGE
group:android.permission-group.MICROPHONE
permission:android.permission.RECORD_AUDIO
group:android.permission-group.SMS
permission:android.permission.READ_SMS
permission:android.permission.RECEIVE_WAP_PUSH
permission:android.permission.RECEIVE_MMS
permission:android.permission.RECEIVE_SMS
permission:android.permission.SEND_SMS
permission:android.permission.READ_CELL_BROADCASTS
以下是普通权限,只需要在AndroidManifest.xml中申请即可
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT