Share url from Youtube iOS app to my Codename One iOS app - codenameone

I need to share a video link from the Youtube app to my Codename One app on iOS.
It seems possible, according to: https://stackoverflow.com/a/38036939/1277576
With Codename One, I tried to add these build hints:
ios.plistInject=<key>CFBundleURLTypes</key><array><dict><key>CFBundleURLName</key><string>net.informaticalibera.myappname</string></dict><dict><key>CFBundleURLSchemes</key><array><string>https</string></array></dict></array>
ios.urlScheme=<string>https</string>
and I added this code to a bare bones project:
public void start() {
if (current != null) {
current.show();
return;
}
String url = Display.getInstance().getProperty("AppArg", null);
Form hi = new Form("Test case", BoxLayout.y());
if (url != null) {
hi.add(new SpanLabel("Intercepted URL:\n" + url));
} else {
hi.add(new Label("No URL was intercepted"));
}
hi.show();
}
but it doesn't work: when I share a video link, Youtube offers me several apps, but not mine.

You need to also implement it in native code and I think there are also changes required to the xcode project if I remember correctly from investigating this a while back. Currently we don't have official support for this use case but you can file an RFE for that.

Related

how to do webview and adjust text inside the form?

I am new in codename one. I want to do the apps using webview. When I add the code below the simulator will close automotive. Here is the code:
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Login", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
hi.show();
BorderLayout borderLayout = new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER);
WebView web = new WebView();
web.getEngine().load("http://google.com");
}
The socond question is how to set "Login" title to left and put image icon at the right side?
WebView isn't a Codename One class. The Codename One class is BrowserComponent. I'm guessing you changed the classpath in the project in creative ways and probably the build script as well.
You can access native code with native interfaces but this isn't the way to do it.

Codename One Full Screen Google Ad not loading

I have an Android app that I want to use with full screen Google ads.
I have got the small ad running, but the full screen ad does show any content.
The information I found on the internet is a little conflicting.
This link here https://github.com/chen-fishbein/admobfullscreen-codenameone advises to add several build hints to the project, but then it refuses to build.
The other one here https://github.com/shannah/admobfullscreen-codenameone does not mention any build hints, but then the ads won't load.
The answer here unable to build codename one app after adding admobfullscreen lib tells to ignore the includeGplayServices hint.
I have build the project with the sample code, but to no avail.
What would be the correct approach?
Edit : code added
String idTest = "ca-app-pub-3940256099942544/6300978111";
String idReal = "ca-app-pub-3524209908223138~0000000000";
admobTestId = new AdMobManager(idTest);
admobRealId = new AdMobManager(idReal);
f.addComponent(new Button(new Command("admob test load and show"){
public void actionPerformed(ActionEvent evt) {
admobTestId.loadAndShow();
}
}));
f.addComponent(new Button(new Command(" admob real load & show"){
public void actionPerformed(ActionEvent evt) {
admobRealId.loadAndShow();
}
}));

Streaming Live audio using Codename One

I am trying to convince a friend of mine to use CN1 as his dev platform for mobile apps. One of the challenges he has brought up is the ability to stream live audio from a radio station using a CN1 app.
I have had a look at the docs and I can see examples of loading media files that are already on the phone, but I cannot see an example of where you point it at a URL and stream live audio.
As you have probably guessed he is interested in developing radio apps for remote radio stations that don't already have their own
Is it possible to do this in CN1?
That's quite possible with CN1 and number of developers have done that in the past.
You can use MediaManager and point it to your remote streaming URL.
Below works for playing an audio file from remote URL and could work for streaming:
Form radio = new Form(new BorderLayout());
Display.getInstance().scheduleBackgroundTask(() -> {
try {
Media audio = MediaManager.createMedia(streamingUrl, false);
audio.prepare();
Display.getInstance().callSerially(() -> {
final MediaPlayer player = new MediaPlayer(audio);
player.setAutoplay(true);
audio.setNativePlayerMode(false);
radio.add(BorderLayout.CENTER, player);
radio.revalidate();
});
} catch (IOException err) {
Log.e(err);
ToastBar.showErrorMessage("Error streaming audio: " + err);
}
});
radio.show();
To avoid this error "Video Playing is not supported on this platform", you have to put true to isVidio parameter like this when handling video stream.
Media audio = MediaManager.createMedia(streamingUrl, true);

Codename One: Use Google Calendar

I'd like to access the Google Calendar of a user after Login, since I want to mirror certain labeled events in my Apps event class.
I guess the Google Calendar API Java Library can't be simply used here, so I was sent to this Library by the Codename One Support.
Does anyone have experience or Code examples for this Library?
How did you guys handle access to Google Calendar API if not with this library?
I did some of the initial work on that but haven't kept up with the changes done by the other authors so I can't say I have actual experience with this library...
From the code something like this should work:
DeviceCalendar dc = DeviceCalendar.getInstance();
if(!dc.hasPermissions()) {
// show message
return;
}
String calName = Preferences.get("selectedCalendar", null);
if(calName == null) {
Collection<String> calendarNames = dc.getCalendars()
calName = promptUserToPickCalendar(calendarNames);
if(calName == null) {
return;
}
Preferences.set("selectedCalendar", calName);
}
String calId = dc.openCalendar(calName, false);
Collection<EventInfo> events = dc.getEvents(calId, startDate, endDate);
// merge your events then use removeEvent/saveEvent respectively to apply your changes

Video having problems on my phone in Codename One

I have created an app for video demonstration using Codename one. I'm Facing some challenges when I'm running the app on my Google Android Phone as it does not allow a full screen view and also after the video is done playing, it does not go back or restart the video again. Another problem was that I had a button at the bottom at the borderlayout and each time I click the button, it corrupts the video and the video won't play anymore. These are codes used for my demonstration app Demonstration App 1, Demonstration App2 .
#Override
protected void postMain1(Form f) {
final MediaPlayer mp = findMpPresent();
try {
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/sbuda.mp4");
if (is != null) {
mp.setDataSource(is, "video/mp4", null);
} else {
}
} catch (IOException ex) {
ex.getMessage();
}
}
This is a bit unclear since I can't see the stop/start etc with a GUI builder application.
You can use native on-device controls for playback using setFullScreen. Notice that this works nicely on the device but has no equivalent on the simulator.
Once playback is finished the media no longer exists as your input stream has been depleted. You will need to create a new Media object. You can use the completion callback (the Runnable argument) to detect the end of the media.

Resources