Eclipse Code in B4A

FabioG

Active Member
Licensed User
Longtime User
Hi,

I contacted the developer of the app LightFlow to implement the compatibility of my app with her.

asked me to add some code to my application, but the code provided by him should be used with Eclipse.

Could you help me to fit on Basic4Android?

I will follow in the mail I received.

Thanks a lot in advance
Fabio

HTML:
Excellent. 

Ok, so basically anywhere in your app that you raise a notification add in the following:
 
 
Intent intent = new Intent("com.digibites.calendar.NEW_NOTIFICATION");
data.putExtra("NEW_NOTIFICATION_TEXT", "The text you would show for a notification");
context.sendBroadcast(intent);





Note this code references com.digibites.calendar, but change this to a unique reference (such as the package name) for your app.  If you've a free version and a paid version you don't need to set a different identifier for each, just use one.
 



This will issue out a broadcast that LightFlow can pick up on for the new notification.



 
Anywhere that you clear a notification, just add the following two lines of code:
Intent intent = new Intent("com.digibites.calendar.CLEARED_NOTIFICATION");
context.sendBroadcast(intent);
 
 

This will handle most events, but the most tricky one is swiping away notifications. For this before raising a notification you'll need to register a delete intent that allows code to be run when the notification is swiped away, so add these lines before the notificationManager.notify is issued:





Intent deleteIntent = new Intent(context,NotificationReceiver.class);
 notification.deleteIntent = PendingIntent.getBroadcast(context,0,deleteIntent, 0);
 




 
Then finally add a new notification receiver that will pick up on notifications being swiped away (as they were registered with the pending deleteIntent above) and then broadcast them out in the same way as any other notification that's cleared.
 
Put this info the android manifest.
<receiver android:name=".NotificationReceiver" > </receiver>
 
 
And create a new class as below:
public class NotificationReceiver extends BroadcastReceiver {
    @Override
   public void onReceive(Context context, Intent intent) {
      Intent intent = new Intent("com.digibites.calendar.CLEARED_NOTIFICATION");
       context.sendBroadcast(intent);
   }
}

Let me know if you need any more information. Once you've added this, I'll add in some matching up code in my app which I could e-mail you through to try (or I'm happy to try with your app)



Thanks
 

FabioG

Active Member
Licensed User
Longtime User
Lets start with the simple one:
B4X:
Dim i As Intent
i.Initialize("com.digibites.calendar.NEW_NOTIFICATION"", "")
i.PutExtra("NEW_NOTIFICATION_TEXT", "the text...")
Dim p As Phone
p.SendBroadcast(i)

Thanks Erel!

for this?

B4X:
Intent deleteIntent = new Intent(context,NotificationReceiver.class);
 notification.deleteIntent = PendingIntent.getBroadcast(context,0,deleteIntent, 0);

and for this?

B4X:
public class NotificationReceiver extends BroadcastReceiver {
    @Override
   public void onReceive(Context context, Intent intent) {
      Intent intent = new Intent("com.digibites.calendar.CLEARED_NOTIFICATION");
       context.sendBroadcast(intent);
   }
}
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
It is possible to create this code with Reflector, though it is a bit cumbersome.

However deleteIntent is only supported by Android 4+. Do you only target these devices?

unfortunately I have not yet learned how to use reflector and I do not know how to do.

Mainly Android 4. *
if then I can also adapt to lower versions would be great
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
The deleteNotification code is problematic. For now you will need to write a small library for that. Also note that it will fail on lower versions of Android.

Thanks Erel,

I opened a topic for the library
I'm asking them for help.

thanks
Fabio
 
Upvote 0
Top