編輯:關於Android編程
官網詳解
先自定義Receiver
private static final String TAG = "MyReceiver"; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { Log.i(TAG, "JPush用戶注冊成功"); } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent .getAction())) { Log.i(TAG, "接受到推送下來的自定義消息"); receivingNotification(context, bundle); } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent .getAction())) { Log.i(TAG, "接受到推送下來的通知"); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent .getAction())) { Log.i(TAG, "用戶點擊打開了通知"); openNotification(context, bundle); } }在receivingNotification()中自定義notification通知欄
private void receivingNotification(Context context, Bundle bundle) { NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); // 使用notification // 使用廣播或者通知進行內容的顯示 NotificationCompat.Builder builder = new NotificationCompat.Builder( context); builder.setContentText(message).setSmallIcon(R.drawable.notification_icon_2).setContentTitle(JPushInterface.EXTRA_TITLE); builder.setDefaults(Notification.DEFAULT_SOUND); manager.notify(1,builder.build()); }
還有一種自定義通知欄,帶有下拉效果。是官網介紹的。
布局文件customer_notitfication_layout.xml
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder( MainActivity.this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text); // 指定定制的 Notification Layout builder.statusBarDrawable = R.drawable.notification_icon; // 指定最頂層狀態欄小圖標 builder2.layoutIconDrawable = R.drawable.notification_icon; // 指定下拉狀態欄時顯示的通知圖標 JPushInterface.setPushNotificationBuilder(1, builder1);
這種帶下來效果
還有一種簡版的,也是官網demo,mark一下。設置成默認,發送通知
BasicPushNotificationBuilder builder2 = new BasicPushNotificationBuilder( MainActivity.this); builder2.statusBarDrawable = R.drawable.logo; builder2.notificationFlags = Notification.FLAG_AUTO_CANCEL; // 設置為自動消失 builder2.notificationDefaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS; // 設置為鈴聲與震動都要 JPushInterface.setDefaultPushNotificationBuilder(builder2); JPushInterface.setPushNotificationBuilder(2, builder2);
setPushNotificationBuilder(2, builder2);設置builder2的樣式編號為2,發送時指定編號發送。
先看一下standard啟動模式的說明:只有一個實例,在同一個應用程序中啟動他的時候,若不存在此Activity實例,則會在當前棧頂創建一個新的實例,若存在,則會把棧中在
如果你的微信被舉報了,怎麼辦呢?是慢慢等著自動解封,還是自己動手呢?下面就來看看手機微信被人舉報後怎麼解除吧!舉報現象:1、一種是你真的發布了違背法律法規、
android.support.v7.widget.RecyclerViewandroid.support.v7.widget.LinearLayoutManageran
Android WebView 1.首先修改activity.xml中的代碼:2.然後MainActivity中的代碼:3.最後設置權限:<uses-permiss