problem with broadcast receiver

SachGw

Member
Licensed User
Longtime User
Hey guys i am trying to port over this code from java to basic4android,but for some reason it isn't working,can some one please tell me whats wrong in it.:sign0163:

the Java source code

B4X:
public static void callDataExport(Context context) {
 
 final String dateFrom = "2011-08-01"; // format "yyyy-mm-dd"
 final String dateTo = "2011-08-31"; // format "yyyy-mm-dd"
 final String exportType = "e3"; // values [e1-e5]
 final String exportFormat = "html"; // values [csv, html, xml]

 Intent intent = new Intent("com.dynamicg.timerecording.DATA_EXPORT");
 intent.putExtra("com.dynamicg.timerecording.DATE_FROM", dateFrom);
 intent.putExtra("com.dynamicg.timerecording.DATE_TO", dateTo);
 intent.putExtra("com.dynamicg.timerecording.EXPORT_TYPE", exportType);
 intent.putExtra("com.dynamicg.timerecording.EXPORT_FORMAT", exportFormat);

 final String KEY_RESULT_FILE = "com.dynamicg.timerecording.FILE";

 BroadcastReceiver resultReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent resultIntent) {
   Bundle bundle = this.getResultExtras(true);
   String filepath = bundle.getString(KEY_RESULT_FILE);
   File file = new File(filepath);

   String feedback = "File=["+file+"], canRead=["+file.canRead()
      +"], sizeKB=["+(file.length()/1024)+"]";
   Toast.makeText(context, feedback, Toast.LENGTH_LONG).show();
   System.out.println(feedback);
  }
 };
 
context.sendOrderedBroadcast(intent, null, resultReceiver
  , null, Activity.RESULT_OK, null, null);
 
}

And this is my implementation

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim Intent1 As Intent
   Dim BCR As BroadCastReceiver
   
   Dim mDateFrom As String
   Dim mDateTo As String
   Dim mExportType As String
   Dim mExportFormat As String
   
   
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
   Activity.LoadLayout("main.bal")
   
End If
End Sub

Sub Activity_Resume
   Activity.LoadLayout("main.bal")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub BCR_OnRecieve(Action As String)
   ToastMessageShow(Action,True)
End Sub


Sub Button1_Click
   mDateFrom = "2012-07-01"
   mDateTo = "2012-07-06"
   mExportType = "e5"
   mExportFormat = "csv"
   Intent1.Initialize("com.dynamicg.timerecording.DATA_EXPORT",Null)
   Intent1.Action = "com.dynamicg.timerecording.DATA_EXPORT"
   Intent1.PutExtra("com.dynamicg.timerecording.DATE_FROM",mDateFrom)
   Intent1.PutExtra("com.dynamicg.timerecording.DATE_TO",mDateTo)
   Intent1.PutExtra("com.dynamicg.timerecording.EXPORT_TYPE",mExportType)
   Intent1.PutExtra("com.dynamicg.timerecording.EXPORT_FORMAT",mExportFormat)
   
   BCR.Initialize("BCR")
   BCR.registerReceiver("com.dynamicg.timerecording.DATA_EXPORT")
   BCR.sendOrderedBroadcast("com.dynamicg.timerecording.DATA_EXPORT",Null)
End Sub
 
Top