xml里
<ProgressBar
android:id="@+id/content_view_progress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="100"
android:layout_below="@id/content_view_image"
/>
代碼里
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 0:
notif.contentView.setProgressBar(R.id.content_view_progress, 100, len, false);
manager.notify(0, notif);
break;
case 1:
Toast.makeText(TestAndroid4Activity.this, "下載完成", 0).show();
break;
default:
break;
}
}
};
方法
private class DownLoadThread extends Thread{
private Timer timer = new Timer();
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
timer.schele(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Message msg = new Message();
msg.what = 0;
msg.obj = len;
handler.sendMessage(msg);
if(len == 100){
timer.cancel();
handler.sendEmptyMessage(1);
}
}
}, 0, 1000);
len = 0;
try {
while(len < 100){
len++;
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⑵ Android通知欄詳解
可以看到,Android通知欄默認是標題顯示一行,內容顯示一行,對於一行顯示不完的,用省略號代替。
這是常見的通知欄的樣式,不再贅述。
在不同的手機上,只設置builder.setSmallIcon(R.drawable.ic_launcher)表現可能不一致,在華為P9上不會顯示大的icon,只會顯示小的icon。但是在魅族上卻顯示了,顯示的應該是應用的默認圖標。
所以建議還是設置
與上面的顯示多行文本類似,也是在Android4.1中官方推出的Notification.BigPictureStyle。
使用方式也相同
是因為在用戶還沒有劃出通知欄的時候需要提醒用戶收到通知,所以需要顯示smallIcon。
⑶ Android service 發送通知欄消息!急急急。
http://www.cnblogs.com/xiao-xu/p/3216491.html
可以先看看
⑷ 如何實現Android的消息的通知欄
IntentFilter filter = new IntentFilter();
// 為IntentFilter添加一個Action
filter.addAction(action);
registerReceiver(receiver, filter);
PendingIntent pendingIntent3 = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), MainActivity.class), 0);
// 通過Notification.Builder來創建通知,注意API Level
// API16之後才支持
Notification notify3 = new Notification.Builder(getApplicationContext())
.setSmallIcon(R.drawable.logo1028)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.app_running))
.setContentIntent(pendingIntent3).build(); // 需要注意build()是在API
// level16及之後增加的,API11可以使用getNotificatin()來替代
notify3.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明當通知被用戶點擊時,通知將被清除。
// manager.notify(1, notify3);// 步驟4:通過通知管理器來發起通知。如果id不同,則每click,在status哪裡增加一個提示
startForeground(1, notify3);
⑸ android 通知欄轉跳頁面問題
那你得判斷是從哪進這個A頁面的,如果是從通知欄進入的那就彈dialog。也就是你得告訴A頁面什麼時候需要彈什麼時候不彈,在通知欄跳到A頁面的時候加個標識就行了。
⑹ android消息推送怎麼實現
極光推送可以輕松實現android消息推送。具有操作步驟如下:⑺ android 自定義通知欄
Notification 參數使用 參考:
http://www.cnblogs.com/kexing/p/8371051.html
自定義通知欄
僅支持FrameLayout、LinearLayout、RelativeLayout三種布局控制項
AnalogClock、Chronometer、Button、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper、ListView、GridView、StackView和AdapterViewFlipper這些顯示控制項
否則會引起ClassNotFoundException異常。
流程:點擊通知欄 發送廣播 app接收廣播做相應處理:
為通知欄綁定廣播事件:
1.FLAG_CANCEL_CURRENT:如果AlarmManager管理的PendingIntent已經存在,那麼將會取消當前的PendingIntent,從而創建一個新的PendingIntent.
2.FLAG_UPDATE_CURRENT:如果AlarmManager管理的PendingIntent已經存在,讓新的Intent更新之前Intent對象數據,例如更新Intent中的Extras,另外,我們也可以在PendingIntent的原進程中調用PendingIntent的cancel ()把其從系統中移除掉
3.FLAG_NO_CREATE:如果AlarmManager管理的PendingIntent已經存在,那麼將不進行任何操作,直接返回已經.
4.FLAG_ONE_SHOT:該PendingIntent只作用一次.在該PendingIntent對象通過send()方法觸發過後,PendingIntent將自動調用cancel()進行銷毀,那麼如果你再調用send()方法的話,系統將會返回一個SendIntentException.
添加廣播接收:
AndroidManifest:
⑻ Android通知筆記
當我們自定義通知布局的時候,需要通過 NotificationCompat.Builder 設置自定義的 RemoteViews 。而 RemoteViews 中只支持部分布局和控制項。如下所示。
布局
控制項
注意:上面的信息我是在android-29的 RemoteViews 源碼中看到的,其他版本的像
android-26,android-27都沒看到,感覺很奇怪。
在上面說通過 NotificationCompat.Builder 設置自定義的 RemoteViews 。有兩個方法。
設置通知收起狀態RemoteViews
設置通知展開狀態的RemoteViews
下面看一下網易雲和喜馬拉雅通知布局的對比。
通知欄網易雲展開布局,喜馬拉雅收起布局
通知欄網易雲展開布局,喜馬拉雅展開布局
通知欄喜馬拉雅展開布局,網易雲收起布局
通知欄喜馬拉雅展開布局,網易雲展開布局
在官方的 創建自定義通知布局 中有這么一段話。「 自定義通知布局的可用高度取決於通知視圖。 通常情況下 ,收起後的視圖布局的高度上限為 64 dp,展開後的視圖布局的高度上限為 256 dp 」。
對這段話我的理解是:
接下來我們測試一下,測試機器
收起布局效果
展開布局效果
收起布局效果
展開布局效果
到這里,有個疑問,如果收起布局大於64dp,展開布局大於256dp會是什麼效果呢?接續測試一下。
收起布局效果
展開布局效果
在我的測試機上好像也沒什麼問題,就是我們的通知布局占據的高度變大了。
結論:可以自定義通知欄高度,但是無論是收起布局還是展開布局都不宜過大。過大的話,會導致用戶在通知欄看到的通知數量減少,用戶需要滑動才能看到更多的通知信息,影響用戶體驗。
源碼請參考 NotificationDemo 的CustomizeNotificationActivity。
這個需要在手機中設置。
參考鏈接:
⑼ android8.0之懸浮窗和通知欄
懸浮窗:
使用場景:例如微信在視頻的時候,點擊Home鍵,視頻小窗口仍然會在屏幕上顯示;
注意事項:
1、一般需要在後台進行操作的時候才需要懸浮窗,這樣懸浮窗才有意義;
2、API Level >= 23的時候,需要在AndroidManefest.xml文件中聲明許可權SYSTEM_ALERT_WINDOW才能在其他應用上繪制控制項。
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />;除了這個許可權外,我們還需要在系統設置裡面對本應用進行設置懸浮窗許可權。該許可權在應用中需要啟動Settings.ACTION_MANAGE_OVERLAY_PERMISSION來讓用戶手動設置許可權:startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), REQUEST_CODE);
3、LayoutParam設置:LayoutParam里的type變數。這個變數是用來指定窗口類型的。在設置這個變數時,需要注意一個坑,那就是需要對不同版本的Android系統進行適配。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
};在Android 8.0之前,懸浮窗口設置可以為TYPE_PHONE,這種類型是用於提供用戶交互操作的非應用窗口。
而Android 8.0對系統和API行為做了修改,包括使用SYSTEM_ALERT_WINDOW許可權的應用無法再使用一下窗口類型來在其他應用和窗口上方顯示提醒窗口:
- TYPE_PHONE
- TYPE_PRIORITY_PHONE
- TYPE_SYSTEM_ALERT
- TYPE_SYSTEM_OVERLAY
- TYPE_SYSTEM_ERROR
如果需要實現在其他應用和窗口上方顯示提醒窗口,那麼必須該為TYPE_APPLICATION_OVERLAY的新類型;
如果在Android 8.0以上版本仍然使用TYPE_PHONE類型的懸浮窗口,則會出現如下異常信息:
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@f8ec928 -- permission denied for window type 2002;
具體實現:
1、Activity:
public void startFloatingService(View view) {
...
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(this, "當前無許可權,請授權", Toast.LENGTH_SHORT);
startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), 0);
} else {
startService(new Intent(MainActivity.this, FloatingService.class));
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(this, "授權失敗", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "授權成功", Toast.LENGTH_SHORT).show();
startService(new Intent(MainActivity.this, FloatingService.class));
}
}
}
2、service:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
showFloatingWindow();
return super.onStartCommand(intent, flags, startId);
}
private void showFloatingWindow() {
if (Settings.canDrawOverlays(this)) {
// 獲取WindowManager服務
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
// 新建懸浮窗控制項
Button button = new Button(getApplicationContext());
button.setText("Floating Window");
button.setBackgroundColor(Color.BLUE);
// 設置LayoutParam
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
layoutParams.format = PixelFormat.RGBA_8888;
layoutParams.width = 500;
layoutParams.height = 100;
layoutParams.x = 300;
layoutParams.y = 300;
// 將懸浮窗控制項添加到WindowManager
windowManager.addView(button, layoutParams);
}
}
效果展示:
⑽ android 系統源碼修改 去除下拉菜單,底部菜單
android手機系統的頂部,點擊菜單欄時,會有一個可以下拉的下拉菜單,,,其實就是他的下拉通知欄,,怎麼實現這個下拉的功能
沒分了 見諒