This is an update to the ANDROID Appcelerator Titanium Alloy JPUSH Push Notification Module
You can find the main post about these modules here:
http://dieskim.me/2015/04/04/appcelerator-titanium-alloy-jpush-push-notification-module-ios-and-android-china-push-notification-non-gcm/
I have added two new functions – Local Notification, to enable easy local notification as natively provided for iOS in Titianium – and Custom Layouts, to customize the layout of the notification in Android.
Local Notification:
Example usage with iOS code as well:
/////////////////////////////////////////////////////////////////////////////////////////// // START COME BACK TO APP LOCAL NOTIFICATION // // START FUNCTION - setComeBackToApp function setComeBackToApp(){ Ti.API.log("setComeBackToApp - 5 Days"); // set 5 days var days = 5; var daysVar = 1000 * 60 * 60 * 24 * days; // set Language String var comeBackToAppTitle = L("string_78"); var comeBackToAppString = L("string_118"); // START IF - iOS ELSE Android if (Ti.Platform.name == 'iPhone OS'){ // set badge to 0 and cancel notification Ti.UI.iPhone.setAppBadge(0); Ti.App.iOS.cancelLocalNotification("comeBackToApp"); // set scheduled notification var notification = Ti.App.iOS.scheduleLocalNotification({ // Create an ID for the notification userInfo: {"id": "comeBackToApp"}, alertBody: comeBackToAppString, badge: 1, date: new Date(new Date().getTime() + daysVar) }); }else{ // set notificationExtras var notificationExtras = { alertType: "comeBackNotification", }; // set notificationData var notificationData = { content: comeBackToAppString, // content string title:comeBackToAppTitle, // title string id: "2", // id - numbers only time: daysVar, // time from now in miliseconds extras: notificationExtras, // extras as object if needed }; // use JPush to addLocalNotication JPush.addLocalNotification(notificationData); }; // END IF - iOS ELSE Android }; // END FUNCTION - setComeBackToApp // END COME BACK TO APP LOCAL NOTIFICATION // ///////////////////////////////////////////////////////////////////////////////////////////
Custom Layout:
1. Run JPush.setStyleCustom(); after starting the module
// REQUIRE JPUSH MOFULE var JPush = require('cn.jpush.ti'); // setStyleCustom JPush.setStyleCustom();
2. Edit the custom_layout.xml file inside – approot/cn.jpush.ti/1.x.x/platform/android/res/layout/custom_layout.xml – here you can change how you want the notification to look.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dip" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#286CA6" android:textSize="20sp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#6FA45E" android:textSize="16sp" android:maxLines="3" /> </LinearLayout> </LinearLayout>
3. Specify the layout for the Push on the JPUSH panel when sending – 通知 栏样式编号 = 2