Sub Class_Globals
Private Root As B4XView
Private xui As XUI
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
Private Sub Button1_Click
Dim in As Intent
in.Initialize(in.ACTION_SEND, "")
in.PutExtra("android.intent.extra.TEXT", "testing...")
in.SetType("text/plain")
SendIntent(in)
End Sub
Private Sub SendIntent (in As Intent)
Dim jo As JavaObject
jo.InitializeNewInstance(Application.PackageName & ".b4xmainpage$MyBroadcastReceiver", Array(Me))
StartActivity(jo.RunMethod("SendIntent", Array(in)))
End Sub
Private Sub ContentChooser_Receive (intent As Object)
Dim in As Intent = intent
If in.HasExtra("android.intent.extra.CHOSEN_COMPONENT") Then
Dim jo As JavaObject = in
jo = jo.RunMethod("getParcelableExtra", Array("android.intent.extra.CHOSEN_COMPONENT"))
Log(jo.RunMethod("getClassName", Null))
Log(jo.RunMethod("getPackageName", Null))
End If
End Sub
#if Java
import android.content.*;
import android.app.*;
public static class MyBroadcastReceiver extends BroadcastReceiver
{
private BA ba;
private static boolean registered;
public MyBroadcastReceiver(B4AClass target) {
ba = target.getBA();
}
public Intent SendIntent (Intent share) {
String shareAction = "content_chooser_result_13";
Intent receiver = new Intent(shareAction);
PendingIntent pi = PendingIntent.getBroadcast(ba.context, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
share = Intent.createChooser(share, null, pi.getIntentSender());
if (registered == false) {
ba.context.registerReceiver(this, new IntentFilter(shareAction));
registered = true;
}
return share;
}
@Override public void onReceive(Context context, Intent intent) {
ba.raiseEventFromUI(null, "contentchooser_receive", intent);
}
}
#End If