1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by cubangt, Aug 30, 2016.

  1. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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.
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
  3. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    Thanks, just reading thru the page seems like it will def help, ill test it out tonight and post back my results..

    thank you
     
  4. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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
     
  5. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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..
     
  6. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
    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.
     
  7. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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..
     
  8. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
    You have not shown how the numDeletes array is initialised within your code, so it's not possible to explain why this is happening. If you would like to post the full code of CallReceiver then this would help.
     
  9. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    So i dont have the code with me at work, so will need to post that later tonight..
    But the numDeletes is setup like this..

    String[] numDeletes = {"1234567890", "0987654321", "3456789120"};

    Ill post CallReceiver tonight..
     
  10. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    Code (Java):
    1. package com.personal.calllogadmin;
    2.  
    3. import android.content.Context;
    4.  
    5. import java.util.Date;
    6.  
    7. public class CallReceiver extends PhonecallReceiver {
    8.  
    9.     MainActivity ma = new MainActivity();
    10.  
    11.     @Override
    12.     protected void onIncomingCallStarted(Context ctx, String number, Date start) {
    13.     }
    14.  
    15.     @Override
    16.     protected void onOutgoingCallStarted(Context ctx, String number, Date start) {
    17.     }
    18.  
    19.     @Override
    20.     protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) {
    21.  
    22.         ma.removeContactsLogFromPhoneLogs(numDeletes);
    23.     }
    24.  
    25.     @Override
    26.     protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) {
    27.  
    28.         ma.removeContactsLogFromPhoneLogs(numDeletes);
    29.     }
    30.  
    31.     @Override
    32.     protected void onMissedCall(Context ctx, String number, Date start) {
    33.  
    34.         ma.removeContactsLogFromPhoneLogs(numDeletes);
    35.     }
    36.  
    37.     private String[] numDeletes ={
    38.             "8555553493",
    39.             "2222229896",
    40.             "2222225005 "
    41.     };
    42. }
    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.
     
  11. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
    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.
     
  12. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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
     
  13. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
    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 (Text):
    1.  
    2. for (String nn : numberTag) {
    3.   ...
    4. }
    5.  
    If array numberTag contains entries, then this code must work.
     
  14. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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?
     
  15. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,828
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,828
    11,398
    1,988
    Male
    Software developer
    South West of England
    SQLite. That is the standard database included with Android.
     
  16. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    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.
     
  17. cubangt

    cubangt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    May 30, 2012

    May 30, 2012
    17
    0
    15
    Is there anything else I can do or check on this.. id like to try and make some progress on this..

    thank you
     

Share This Page

Loading...