• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Proper way to run app automatically once installed and acknowledged by user

cubangt

Newbie
May 30, 2012
17
0
So ive been working on a really simple app, it doesn't have to display or show anything when it runs, all I need it to do is when a call is ended run the routine within the activity. Basically its clearing the call log after a call(only of numbers pre-determined) currently an array with a few numbers..

Eventually if it works the way I want, ill add ability to manage that list, but for testing purposes, everything is hardcoded.

So right now within the onStart() I'm calling the method that handles the deletions, this all works great, but only works when you open or use the application, I want to install the app, and have it checking/monitoring the calls and when a call is ended, run the routine.

@override
public void onStart() {
super.onStart();
removeContactsLogFromPhoneLogs(numDeletes);
}

Ive read a few places about using Broadcaster and Intent, but nothing clear enough to point me in the right direction.

Since you cant create a Android Service(like on a windows pc) the next best thing is create a empty app that monitors for the call end.

Can anyone point me in the right direction on how I can change my app to either run all the time monitoring for ended calls or whatever other options there are to get this to work..

Like I said, currently if I run the application manually it will delete the numbers in the array from my call log, but its manual and you have to use the app, I want to be able to install the app, and have it already monitoring.

thanks.
 
So I was able to setup the sample code from the link, finally got it working to the point where the app would acknowledge calls. I add my method within the onOutGoingCallEnded, it gets the list of numbers, but doesn't work, doesn't delete anything no matter that while stepping thru the code, it does go into the delete routine and loops thru but nothing is deleted. Below I have attached screen shots of the code and where I'm making the calls.. ive tried to keep this simple to start off and will improve once it actually works.. Can anyone see why it works when called within the MainActivity and not within the CallReceiver

Untitled-1.png

Untitled-2.png
Untitled-3.png
Untitled-4.png
 
Upvote 0
Yea so I keep stepping thru the code and letting it run without interruption and when called from the CallReceiver.java it never loops thru the list of numbers, it only attempts the number that was called, so it seems like even though I'm passing the list of numbers to the routine, the actual number called is what is being passed in, but even then it doesn't delete that call, which is one of the numbers in the list.

What am I doing wrong..
 
Upvote 0
You don't appear to be updating the 'numDeletes' array with the current number being called. I would have expected that onOutgoingCallEnded() would add the number to the array.

In fact using an array doesn't make sense, as this is a fixed size. Instead, use an ArrayList.
 
Upvote 0
ok, so the numDeletes is a String[ ] which contains only the numbers i care to delete. This is hardcoded with the 4 numbers.. Now you are right im not adding the number being called because for this test it is already in the list.. Im not concerned about who im calling or who is calling me.. but i would like to delete the numbers within the array regardless if that is who i called or who has called me..
 
Upvote 0
Java:
package com.personal.calllogadmin;

import android.content.Context;

import java.util.Date;

public class CallReceiver extends PhonecallReceiver {

    MainActivity ma = new MainActivity();

    @Override
    protected void onIncomingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onOutgoingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) {

        ma.removeContactsLogFromPhoneLogs(numDeletes);
    }

    @Override
    protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) {

        ma.removeContactsLogFromPhoneLogs(numDeletes);
    }

    @Override
    protected void onMissedCall(Context ctx, String number, Date start) {

        ma.removeContactsLogFromPhoneLogs(numDeletes);
    }

    private String[] numDeletes ={
            "8555553493",
            "2222229896",
            "2222225005 "
    };
}

So this is what is currently there, granted the variables expected by the override methods expect just string, I'm not looking to pass those since my removeContactsLogFromPhoneLogs already handles the deletion. So I'm passing the string array of numbers from the callreceiver just as if I was calling it from within the main activity but only when called from mainactivity does the routine actually loop thru the list and work.
 
Upvote 0
I find it odd that you are creating an instance of your MainActivity within the CallReceiver class.

If you're creating this just to invoke the removeContactsLogFromPhoneLogs() method, then the Activity class is the wrong place for this method. Normally the usual architecture is to create a database helper class, which contains all methods related to database access.

As to why your code is not looping over the numbers in your numDeletes array, I would set a breakpoint in onOutgoingCallEnded(), and verify that the array actually contains any numbers. Step through the execution of the code line by line, into removeContactsLogFromPhoneLogs(), to check exactly what is going on.
 
Upvote 0
That was my first attempt, since the callreceiver was handling the events, didnt know where to make the call to delete the numbers.. I have placed break points within the callended to step thru from that point as well, within the delete routine, the list of numbers are in the array but doesnt loop.

So of the 3 files in the project, callreceiver, mainactivity and phonecallreceiver which would be the correct place to call the delete routine?
If i need to create an additional file/class is that where i would call the method to delete? But how would i get into that class when the call ends or starts?

Ive created other apps that are not watching for phone events so this is the first time im trying to intercept events and do something about it..

I really appreciate the suggestions and guidance.
thank you
 
Upvote 0
You need a crash course on how to use databases within an Android app. There are plenty of tutorials out there.

For the looping issue, if the array contains numbers, then your code must enter the loop

Code:
for (String nn : numberTag) {
  ...
}

If array numberTag contains entries, then this code must work.
 
Upvote 0
Well thats the thing, if i could record the step thru i would post that, the routine works BUT only when called from MainActivity. When called from callreceiver it doesnt work, it will get to the first line in the loop
for (String nn : numberTag) but never actually gets into the loop, it literally steps out of that and continues..

I have breakpoints within the loop itself and it just gets to the first line and continues outside the loop(when called from callended method)

So i know that the loop works and is not the problem.

When you say databases within android, are you referring to actual databases like SQLite? or built in databases within Android itself?
 
Upvote 0
I've worked with SQLite before, how does that play into intercepting call events? I want to learn and don't like asking questions unless I'm stuck or confused.. The only purpose this app will serve initially is to intercept call events and delete a list of numbers from the call log.. at this time is only the 3 or 4 numbers hard coded into the string array. MAYBE in the future once its working ill change that up to allow the addition and deletion of said numbers to delete. But I believe in starting off simple and working up to full features, and initially this app will only be used by a few family members and friends..

So not looking to get fancy yet..

Goal is to create a app that already monitoring the call events once the application is installed and does it job without user intervention.

#1- Provide everyone with the APK
#2- Install app on the individual phones
#3- Once installed already monitoring call events and deleting the list of numbers from call log
#4- Maybe provide some simple error handling if there was a problem deleting so that user is aware the numbers may still exist in the call log after a call..

Maybe next version could be to monitor the call events for the list of numbers and if exists, then delete, but for simplicity just run the delete every time a call is ended or started.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones