我使用 THES SORCE 获取和显示通知,但此代码不能自定义。我需要定制通知的来源 从 onesignal.com 收到
我需要通过 onesignal 发送 url 并接收并显示图标通知
package booke.vfj.angour.ir.baftani_davood;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.view.LayoutInflater;
import org.json.JSONObject;
import java.util.ArrayList;
public class G extends Application {
public static Context context;
public static LayoutInflater inflater;
public static Activity currentActivity;
public static ArrayList<StructTest> Recordsfehrset = new ArrayList<StructTest>();
public static ArrayList<StructTest2> recordjoziat = new ArrayList<StructTest2>();
public static ArrayList<StructTest> fov = new ArrayList<StructTest>();
@Override
public void onCreate()
{
super.onCreate();
context = getApplicationContext();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
OneSignal.startInit(this).init();
OneSignal.startInit(this).setNotificationOpenedHandler(new NotificationOpenedHandler()).init();
}
private class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
@Override
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
try {
String messageTitle;
AlertDialog.Builder builder = null;
if (additionalData != null) {
if (additionalData.has("discount"))
messageTitle = "Discount!";
else if (additionalData.has("bonusCredits"))
messageTitle = "Bonus Credits!";
else
messageTitle = "Other Extra Data";
builder = new AlertDialog.Builder(getApplicationContext()).setTitle(messageTitle).setMessage(message + "\n\n" + additionalData.toString());
}
else if (isActive) // If a push notification is received when the app is being used it does not display in the notification bar so display in the app.
builder = new AlertDialog.Builder(getApplicationContext())
.setTitle("OneSignal Message")
.setMessage(message);
// Add your app logic around this so the user is not interrupted during gameplay.
if (builder != null)
builder.setCancelable(true)
.setPositiveButton("OK",null)
.create().show();
} catch (Throwable t) {
t.printStackTrace();
}
}
}