I make some code that schedule a notification.
It works well from lua, and show notification with no error.
problem is that this code never response when I touch notification.
I think there must be something in life cycle of CoronaApplication activity.
my code is below
public class Func\_scheduleNotification implements com.naef.jnlua.NamedJavaFunction { @Override public String getName() { return "scheduleNotification"; } @Override public int invoke(com.naef.jnlua.LuaState luaState) { com.ansca.corona.CoronaActivity activity = com.ansca.corona.CoronaEnvironment.getCoronaActivity(); if (activity == null) return 1; Resources res = activity.getResources(); double time = luaState.checkNumber(1); String name = luaState.checkString(2); String content = luaState.checkString(3); double notread = luaState.checkNumber(4); int requestID = (int) System.currentTimeMillis(); Intent notificationIntent = new Intent(activity.getApplicationContext(), CoronaApplication.class); notificationIntent.putExtra("name", name); notificationIntent.setFlags(Intent.FLAG\_ACTIVITY\_CLEAR\_TOP | Intent.FLAG\_ACTIVITY\_SINGLE\_TOP); PendingIntent contentIntent = PendingIntent.getActivity(activity, requestID,notificationIntent, PendingIntent.FLAG\_UPDATE\_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(activity); builder.setContentTitle(name) .setContentText(content) .setTicker("new alarm") .setContentIntent(contentIntent) .setAutoCancel(true) .setNumber((int)notread) .setWhen(System.currentTimeMillis() + (long)time) .setDefaults(Notification.DEFAULT\_ALL) .setSmallIcon(R.mipmap.ic\_launcher); .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic\_launcher)); if (android.os.Build.VERSION.SDK\_INT \>= android.os.Build.VERSION\_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY\_MESSAGE) .setPriority(Notification.PRIORITY\_HIGH) .setVisibility(Notification.VISIBILITY\_PUBLIC); } int hash = name.hashCode(); NotificationManager nm = (NotificationManager) activity.getSystemService(Context.NOTIFICATION\_SERVICE); nm.notify(hash, builder.build()); luaState.pushInteger(hash); return 1; } }
in addition, i have to know how i pass some variable to lua-side when activity starts from notification.
like, from main.lua,
local launchArgs = ...
p.s. I know there is notification plugin but i have to make my own java function for some reason.
sorry for my bad english skills.
waiting for your help. thank you.