FAU Android

FAU's local android experts!

To launch an app made using Processing from an app made using Eclipse, for this method we first need to export our processing application as shown in method 1.  From here we need to import it into our Eclipse environment.  Add a new java file for your broadcast receiver called “MyBroadcastReceiver.java”.  See below:

In the MyBroadcastReceiver.java file put the following code:

package processing.test.collect_accelerometer_data;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;


public class MyBroadcastReceiver extends BroadcastReceiver {
    public MyBroadcastReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
		
		
        if (intent.getAction().equals("edu.fau.android.mybroadcast")) {
	        Intent i = new Intent(context, collect_accelerometer_data.class);
	        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	        context.startActivity(i);
        }
    }
		
}

The name of the package and Activity to launch will vary, but for the most part this code can be used in any other application.  This code uses the broadcast receiver’s onReceive method to launch a specific Activity when it receives a broadcast with the action “edu.fau.android.mybroadcast”.  The broadcast receiver cannot be used in the application until it is registered in the AndroidManifest file. Within the application tags of the file place the following xml code:


<receiver android:name="MyBroadcastReceiver">
      	<intent-filter>
            <action android:name="edu.fau.android.mybroadcast" />
      	</intent-filter>    
 </receiver>

This code filters intents of a specific action and calls the appropriate BroadcastReceiver’s onReceive method.

The receiver part is now complete.  If you would like to send a broadcast to the receiver use the following code in a button click method or similar method:


public void launchApp(View v){
		
	Intent intent = new Intent();
	intent.setAction("edu.fau.android.mybroadcast");
	sendBroadcast(intent); 
				
}

Download the source code at the bottom of this post.

processing_exported_collect_acc_data
eclipse_app_launcher_method_2

Comments are closed.