remove notification from another program.

cammel8

Member
Licensed User
Longtime User
Is it possible to remove a notification from a different program. Here is what I am doing. I made a dead man switch that when released will text and call an emergency number. It mutes all volume so if anyone calls or texts because they want to check on you, the phone makes no sounds. It also puts a notification in the notification area so you can disable the panic mode.

Now what I would like to do is remove any notifications from SMS messages that come in stating you have a message. I know you can intercept an SMS but it is read only and the messaging program still receives the SMS. I know there is nothing I can do to stop it, But is there any way to hide the notification that it puts up, so that if someone looks at the notifications drop down they don't see a message from mom saying are you really in trouble or are you messing with me.

I want the program to be as stealthy as possible. I know that if I click the Notifications drop down that I can click clear, and it clears all the notifications in the drop down but is there any way to initiate that programatically?

If not is there anything else that i could do to hide it?

Thanx in advance
George
 

moster67

Expert
Licensed User
Longtime User
Upvote 0

cammel8

Member
Licensed User
Longtime User
You will need a custom library for this. The library should include a broadcast receiver that will receive the Sms and cancel the broadcast. It should then start a Service which is part of your project.

I need to make a custom library to remove the notification, or I need to make a custom library to stop the SMS from reaching the messaging program?

Second question, in either case, is there something out there that is in basic or vb that I could use to make the library, I don't know any java programming and am somewhat lost reading all of these tutorials. I get the gist of what they are doing, but the problem is coming up with the code itself. Because none of them actually spell out exactly what I need, I would have to interject some code and to d that I would need to know some java to finish the project.

Although I have found many very informative sites where I am pretty sure the info I need to make the Library is located, I have no idea how to implement it.

This one goes over receivers
<receiver> | Android Developers

This one broadcast receiver class BroadcastReceiver | Android Developers

This one is a tutorial in services and recievers
Android Service and Broadcast Receiver Tutorial

Here's another tutorial
Android Service and Broadcast Receiver Tutorial

and the last one seems to be a class
BroadcastReceiver (Google Android Library 2.2.1 API)

As I said, I am sure one or more of them have the info I need to make this thing; however, because I don't have any experience in java, I am at a loss here. When I was taking vb.net in college, I had made a few librarys and am quite certain I understand the fundamentals.

I have read this tutorial
http://www.b4x.com/forum/libraries-developers-questions/6810-creating-libraries-basic4android.html

and this one
http://www.b4x.com/forum/libraries-developers-questions/8665-create-basic4android-libraries.html#post48269

Which both seem real easy to follow. I even watched the video tutorial here
http://www.b4x.com/forum/libraries-developers-questions/12431-video-tutorial-creating-simple-library.html

So I am not at a loss for how to make a library in and of itself. Where I have the problem is in the code area. I have an idea of what should be in the code area I just don't know what to put. And I really don't want to start learning another language in the middle of learning this one as it is I get confused enough with this one sometimes, I don't need to add any more fuel to the fire so to speak.

Any help would be greatly appreciated.
Thanks in advanced.
George
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The following (untested) code creates a BroadcastReciever that start a service with the original intent and then cancels the intent.
B4X:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class SmsInterceptor extends BroadcastReceiver{

   @Override
   public void onReceive(Context context, Intent intent) {
      android.content.Intent in;
      try {
         in = new android.content.Intent(context, Class.forName("package.name.service1"));
      } catch (ClassNotFoundException e) {
         throw new RuntimeException(e);
      }
      if (intent != null)
         in.putExtra("b4a_internal_intent", intent);
      this.abortBroadcast();
      context.startService(in);
   }

}

You will need to set the service class name (lower cased).
You will need to modify the manifest file and add the receiver tag.

You can use an almost empty XML file as this "library" doesn't include any accessible methods.
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
I'm doing it in a different way, however I receive a java.lang.StackOverflowError at the following code:

B4X:
/**
    * Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through 
    * sendOrderedBroadcast. This will prevent any other broadcast receivers from receiving the broadcast.
    * It will still call onReceive() of the BroadcastReceiver that the caller of sendOrderedBroadcast passed in.
    * This method does not work with non-ordered broadcasts such as those sent with sendBroadcast
    */
   public void abortBroadcast() {
      abortBroadcast();
   }

I also already tried this.abortBroadcast.

Note that the receiver is registered programmatically instead of modifying any XML, which makes it a lot easier.

Another question: Does the SMSinterceptor (that's already integrated with B4A) (phone lib i guess) also uses broadcast or some inbuild Java?
If yes, is it possible to see the source?



Tomas
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Yes, but i dont know on how to solve it, as i have never seen that before. :eek:

Sent from my SE Xperia Play using Tapatalk.

Hard to say without seeing the rest of the code.
I dont think you should be changing the abortBroadcast method anyway. You should call it from somewhere else (like when you receive the broadcast).
Are you using the BroadcastReceiver class?

I think Erel's example is good, what method are you trying?

EDIT: Also, you can see the PhoneLibs's source using jd-gui. If Erel allows ofcourse. :)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
B4X:
   public void abortBroadcast() {
      abortBroadcast();
   }
Looks like you need to read up on inheritance. abortBroadcast is inherited from BroadcastReceiver. If you want to expose it then either give it a different name to the inherited method name
B4X:
   public void AbortBroadcast() {
      abortBroadcast();
   }
or if you must keep the same name then override the inherited method.
B4X:
   @Override
   public void abortBroadcast() {
      super.abortBroadcast();
   }
If you don't have it set already I recommend setting in Eclipse

"Window- > Java - Error/Warnings - Annotations - Missing '@Override' annotation" to "Warning".

You will have to scroll down the "Error/Warnings" page to see it.
 
Upvote 0
Top