How to implemented in JAVAFX/Gluon a button to go to the default send Message for my Android Mobile

前端 未结 1 1644
再見小時候
再見小時候 2021-01-26 02:12

I have implemented a Button in my Mobile Application und have a Textfieldwith a Telefon Nummer.

What i want to achieve: When the User Click the Button-> The Default Page

1条回答
  •  抹茶落季
    2021-01-26 02:47

    I suggest you have a look at how the Charm Down plugins are implemented.

    You will see that you can use most of the existing services without further modifications.

    If the service you are looking for is not implemented yet, it is really easy to create it, following the same guidelines as the existing plugins:

    On your source packages [Java], add the following classes:

    Package: com.gluonhq.charm.down.plugins. Class: SMSService:

    package com.gluonhq.charm.down.plugins;
    
    public interface SMSService {
        void sendSMS(String number);
    }
    

    Package: com.gluonhq.charm.down.plugins. Class: SMSServiceFactory:

    package com.gluonhq.charm.down.plugins;
    
    import com.gluonhq.charm.down.DefaultServiceFactory;
    
    public class SMSServiceFactory extends DefaultServiceFactory {
    
        public SMSServiceFactory() {
            super(SMSService.class);
        }
    
    }
    

    Finally, on the Android package, implement the service:

    Package: com.gluonhq.charm.down.plugins.android, class: AndroidSMSService

    package com.gluonhq.charm.down.plugins.android;
    
    import android.content.Intent;
    import android.net.Uri;
    import com.gluonhq.charm.down.plugins.SMSService;
    import javafxports.android.FXActivity;
    
    public class AndroidSMSService implements SMSService {
    
        @Override
        public void sendSMS(String number) {
            Intent smsIntent = new Intent(Intent.ACTION_VIEW);         
            smsIntent.setData(Uri.parse("sms:"));
            smsIntent.putExtra("address", number);
            FXActivity.getInstance().startActivity(smsIntent);
        }
    
    }
    

    Test

    Now all you need to do is use the SMS service in your code, once you have the number added to the textField, and a button to fire the action:

    Services.get(SMSService.class)
                .ifPresent(s -> button.setOnAction(e -> s.sendSMS(textField.getText())));
    

    Build the application and deploy it to your Android device. Try it, and check that it opens the Messenger app (maybe it will ask to use other different apps), and already uses the provided number, so you can start typing your message.

    0 讨论(0)
提交回复
热议问题