17

I have two apps that I made, and am trying to send an intent from one to the other but the intent is never getting to the onReceive() however this problem is only one way. The first app can send to the second but the second cannot send back info. I am using a different intent action to send from the second to the first but otherwise they are identical. Any ideas on why this might not be working? I have tried everything I can think of and read most of the posts I could find on here and to no avail.

It's not crashing or giving me any indications as to what is happening in the logcat it's just doing nothing.

send function

private void sendFinishLog(String ID, String Cond)
{
    Log.d("me", "send finish log");
    Intent logIntent = new Intent();
    logIntent.putExtra("ID", ID);
    logIntent.putExtra("Cond", Cond);
    logIntent.setAction("com.me.intent.finishlog");
    Log.d("me","logIntent : " + logIntent.toString()   
        +logIntent.getExtras().toString());
    sendBroadcast(logIntent);
}

receive class

public class LogReceiver extends BroadcastReceiver {

    public static ArrayList<LogDataHolder> logData = new ArrayList<LogDataHolder>();
    private boolean found;
    static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    private static String lasttime;
    private static String now = "Boot time";
    @Override
    public void onReceive(Context cont, Intent logIntent) 
    {
        Log.d("me","On receive");
                etc.....
    }

Receiving app manifest

<!-- for receiving logs  -->
<receiver 
    android:name = "LogReceiver"
    android:enabled="true">
    <intent_filter>
        <action android:name="com.me.intent.finishlog" />
    </intent_filter>
</receiver>
juanferrer
  • 1,192
  • 1
  • 16
  • 29
Cob50nm
  • 911
  • 2
  • 9
  • 27
  • 1
    did you register the receiver? – bofredo Aug 15 '13 at 14:09
  • Does it not amount to the same thing? And I want it to always be listening so I can pick it up whenever it is triggered so the manifest way is the better option for this, from what I understand. – Cob50nm Aug 19 '13 at 15:09

4 Answers4

9

something like:

public void onResume() {
    IntentFilter filter = new IntentFilter();
    getActivity().registerReceiver(mLogReceiver,filter);
}

and for un-register:

public void onPause() {
    getActivity().unregsiterReceiver(mLogreceiver);
}

edit: i just figured that your LogReceiver-class has no constructor neither. you will need to write one aswell:

private LogReceiver mLogReceiver = new LogReceiver() {

and after that you can use the onReceive-method like you have it already in your code.

bofredo
  • 2,348
  • 6
  • 32
  • 51
5

Try it again like this. The category may need to be added

<receiver
    android:name = "LogReceiver"
    android:enabled="true">
    <intent-filter>
        <action android:name="com.me.intent.finishlog" />
         <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter>
</receiver>
Nelson Almendra
  • 784
  • 1
  • 9
  • 20
Eden
  • 51
  • 1
  • What does the default mean though? Does it mean a standard android one or can it be used for custom intent actions? – Cob50nm Aug 15 '13 at 14:56
  • If you do not have to add an action, you do not need to add category .But if you add the action, I think it necessary to add a category to indicate how to use this action – Eden Aug 16 '13 at 04:59
2

My problem was solved when I removed the receiver unregister from the OnPause(). method.

shiny vn
  • 91
  • 3
1

You declared the receiver in the manifest as:

    android:name = "LogReceiver"

The documentation states that name should be:

The name of the class that implements the broadcast receiver, a subclass of BroadcastReceiver. This should be a fully qualified class name (such as, "com.example.project.ReportReceiver"). However, as a shorthand, if the first character of the name is a period (for example, ". ReportReceiver"), it is appended to the package name specified in the element.

In other words, it needs to include the package. Try changing the name to:

    android:name = ".LogReceiver"

or

    android:name = "com.me.yourpackagename.LogReceiver"
Sofi Software LLC
  • 3,879
  • 1
  • 36
  • 34