对于Android界面NotificationManager使用Bitmap做图标感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍android中bitmap,并为您提供关于AndroidLoc
对于Android界面 NotificationManager使用Bitmap做图标感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍android中bitmap,并为您提供关于Android LocationManager标准、android notification 小图标的问题、android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)、Android NotificationManager简单使用详解的有用信息。
本文目录一览:- Android界面 NotificationManager使用Bitmap做图标(android中bitmap)
- Android LocationManager标准
- android notification 小图标的问题
- android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)
- Android NotificationManager简单使用详解
Android界面 NotificationManager使用Bitmap做图标(android中bitmap)
今天看到EOE问答里面有这“[Android 界面]notificationmanager 如何使用Bitmap做图标”这样一个问题,在论坛搜索也没有好的案例特写一个简单的demo供大家参考
今天发布的是notificationmanager 使用Bitmap做图标
关键code
public void notification(int flag)
{
Notification notification = new Notification();
//设置statusbar显示的icon
notification.icon = R.drawable.icon;
//设置statusbar显示的文字信息
// myNoti.tickerText= new_msg ;
notification.flags = Notification.FLAG_AUTO_CANCEL;
//设置notification发生时同时发出默认声音
notification.defaults = Notification.DEFAULT_SOUND;
RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.custom_notification);
Bitmap bitmap=null;
if(flag==0)
{
bitmap=drawabletoBitmap(this.getResources().getDrawable(R.drawable.icon));
}else
{
//此处是关键地方,可以从网络或是sdcard上获取图片,转成bitmap就可以
bitmap=drawabletoBitmap(this.getResources().getDrawable(R.drawable.alert_dialog_icon));
}
contentView.setimageViewBitmap(R.id.notification_icon,bitmap);
contentView.setTextViewText(R.id.app_name,"Custom notification");
notification.contentView = contentView;
Intent intent = new Intent(this,MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = contentIntent;
//显示Notification
Random random = new Random(new Date().getTime());
mnotificationmanager.notify(random.nextInt(1000000),notification);
}
//转化drawabletoBitmap
public static Bitmap drawabletoBitmap(Drawable drawable)
{
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),drawable.getopacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
源码下载:NotificationIcon.rar
Android LocationManager标准
如果GPS提供商不可用或没有位置(卫星可见性差)我会从网络提供商处获得GPS提供商的位置.
是否有可能根据我的需要选择使用标准?
解决方法
在其代码中,如果您使用两个提供商(来自GPS和网络),它将进行比较:
... } else if (mUseBoth) { // Get coarse and fine location updates. mFineProviderButton.setBackgroundResource(R.drawable.button_inactive); mBothProviderButton.setBackgroundResource(R.drawable.button_active); // Request updates from both fine (gps) and coarse (network) providers. gpsLocation = requestUpdatesFromProvider( LocationManager.GPS_PROVIDER,R.string.not_support_gps); networkLocation = requestUpdatesFromProvider( LocationManager.NETWORK_PROVIDER,R.string.not_support_network); // If both providers return last kNown locations,compare the two and use the better // one to update the UI. If only one provider returns a location,use it. if (gpsLocation != null && networkLocation != null) { updateUILocation(getBetterLocation(gpsLocation,networkLocation)); } else if (gpsLocation != null) { updateUILocation(gpsLocation); } else if (networkLocation != null) { updateUILocation(networkLocation); } } ...
它实现了最佳位置提供者的想法(通过确定在指定时间段内的准确性,如:
/** Determines whether one Location reading is better than the current Location fix. * Code taken from * http://developer.android.com/guide/topics/location/obtaining-user-location.html * * @param newLocation The new Location that you want to evaluate * @param currentBestLocation The current Location fix,to which you want to compare the new * one * @return The better Location object based on recency and accuracy. */ protected Location getBetterLocation(Location newLocation,Location currentBestLocation) { if (currentBestLocation == null) { // A new location is always better than no location return newLocation; } // Check whether the new location fix is newer or older long timedelta = newLocation.getTime() - currentBestLocation.getTime(); boolean isSignificantlyNewer = timedelta > TWO_MINUTES; boolean isSignificantlyOlder = timedelta < -TWO_MINUTES; boolean isNewer = timedelta > 0; // If it's been more than two minutes since the current location,use the new location // because the user has likely moved. if (isSignificantlyNewer) { return newLocation; // If the new location is more than two minutes older,it must be worse } else if (isSignificantlyOlder) { return currentBestLocation; } // Check whether the new location fix is more or less accurate int accuracyDelta = (int) (newLocation.getAccuracy() - currentBestLocation.getAccuracy()); boolean isLessAccurate = accuracyDelta > 0; boolean isMoreAccurate = accuracyDelta < 0; boolean isSignificantlyLessAccurate = accuracyDelta > 200; // Check if the old and new location are from the same provider boolean isFromSameProvider = isSameProvider(newLocation.getProvider(),currentBestLocation.getProvider()); // Determine location quality using a combination of timeliness and accuracy if (isMoreAccurate) { return newLocation; } else if (isNewer && !isLessAccurate) { return newLocation; } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) { return newLocation; } return currentBestLocation; }
有关完整代码,请查看上面提供的链接.
android notification 小图标的问题
notification 小图标(红线画的)是怎么设置进去的,我设置smallicon,在4.X的系统上是显示这个,在5.X的系统需要设置largeicon,但是在5.X上显示如下图标,而那个小图标显示为空白,如何设置
android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)
网上很多的例子都是直接获取 Notification 对象来设置一个通知,其实 Notification 跟 Dialog 一样,也有自己的 Builder,可以用 builder 对象来设置一个 Notification
这个例子是在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转(跟 android 的 vcard 文件导入时弹出的 Notification 一样)
NotificationManager mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
builder.setOngoing(true);
builder.setProgress (total, current, false);// 设置进度条,false 表示是进度条,true 表示是个走马灯
builder.setTicker (title);// 设置 title
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle (content);// 设置内容
builder.setAutoCancel (true);// 点击消失
builder.setSmallIcon(R.drawable.upload);
builder.setContentIntent (PendingIntent.getActivity (context, 0, new Intent (), 0));// 这句和点击消失那句是 “Notification 点击消失但不会跳转” 的必须条件,如果只有点击消失那句,这个功能是不能实现的
Notification noti = builder.getNotification();
mNotificationManager.notify(id,noti);
希望这个例子对其他人有点用,因为我特曾为这个功能苦恼过,呵呵!
Android NotificationManager简单使用详解
本文实例为大家分享了Android NotificationManager的简单使用代码,供大家参考,具体内容如下
我们有时候需要使用通知,先要获得一个通知管理器,然后通过通知管理器来发送通知。以下就是几种通知的使用:
public class MainActivity extends Activity { private NotificationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //1.使用通知,先要获得一个通知管理器 manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //点击此按钮发出一条通知(普通的通知) findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new NotificationCompat.Builder(MainActivity.this); builder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("我是测试用的普通通知").setContentText("测试测试"); //当通知被点击的时候使用 Intent intent = new Intent(); intent.setClass(MainActivity.this, MainActivity.class); //PendingIntent 等待的意图 PendingIntent intent2 = PendingIntent.getActivity(MainActivity.this, 0, intent, Notification.FLAG_AUTO_CANCEL); builder.setContentIntent(intent2); //通知点击以后消失 builder.setAutoCancel(true); Notification notification = builder.build(); //发送通知 manager.notify(0,notification); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { //进度通知 @Override public void onClick(View v) { new Thread(){ public void run() { Builder builder = new NotificationCompat.Builder(MainActivity.this); for (int i = 0; i <=100; i++) { //progress当前进度 //indeterminate是否精确 builder.setProgress(100,i , false); manager.notify(1,builder.build()); //必须设置setSmallIcon builder.setSmallIcon(R.drawable.ic_launcher); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } manager.cancel(1); }; }.start(); } }); findViewById(R.id.button3).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new NotificationCompat.Builder(MainActivity.this); builder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("标题") .setContentText("test"); BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.c)); style.setBigContentTitle("通知"); builder.setStyle(style); manager.notify(2, builder.build()); } }); findViewById(R.id.button4).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new NotificationCompat.Builder(MainActivity.this); builder.setSmallIcon(R.drawable.ic_launcher); RemoteViews views=new RemoteViews(getPackageName(),R.layout.notify_item); views.setImageViewResource(R.id.iv, R.drawable.ic_launcher); views.setTextViewText(R.id.tv,"自定义视图"); builder.setContent(views); manager.notify(3,builder.build()); } }); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
- Android 使用AlarmManager和NotificationManager来实现闹钟和通知栏
- Android开发 -- 状态栏通知Notification、NotificationManager详解
- Android中通过Notification&NotificationManager实现消息通知
- Android界面 NotificationManager使用Bitmap做图标
今天关于Android界面 NotificationManager使用Bitmap做图标和android中bitmap的讲解已经结束,谢谢您的阅读,如果想了解更多关于Android LocationManager标准、android notification 小图标的问题、android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)、Android NotificationManager简单使用详解的相关知识,请在本站搜索。
本文标签: