How to open native calendar from titanium app? - titanium

how to open native calendar from titanium app for android and iOS? As in, on the click of a button, i want to open the native calendar on the ipad.

In android you can open it using a native intent, as explained here
There's a difference between versions lower and greater than Gingerbread. There's also a difference in HTC devices because of the HTC Sense Software, as explained at the end of this question.
Here is my tested code for Titanium:
if (Titanium.Platform.osname=="android"){
//Params needed to create the android intent.
var packageStr = "com.google.android.calendar";
var classStr = "com.android.calendar.LaunchActivity";
var actionStr = Ti.Android.ACTION_VIEW;
var model = Ti.Platform.model;
if ((model.indexOf("HTC") != -1) || (model.indexOf("htc") != -1)){
//If it's a HTC device
packageStr = "com.htc.calendar";
classStr = "com.htc.calendar.MonthActivity";
actionStr = Ti.Android.ACTION_MAIN;
}
else {
//For android versions before Gingerbread (2.3)
var version = parseFloat(Ti.Platform.version);
if (version < 2.4) packageStr = "com.android.calendar";
}
//Launch native calendar
var intent = Ti.Android.createIntent({
action: actionStr,
packageName: packageStr,
className: classStr
});
Ti.Android.currentActivity.startActivity(intent);
}
You can also open the "create event" screen of the native calendar by adapting this for Titanium in the same way as the code above

Just use:
Titanium.Platform.openURL('CALSHOW://');

Related

setOngoing(true) is not working in Oreo+ Notifications

I am creating a custom notification with channel_id and start it as foreground. I have background music playing .. My problem is when user swipe notification it disappears. I have also setOngoing(true). i want notification to stay when music is playing.
NOTE: It only happens in Oreo+. in lower versions it is working fine.
public void CustomNotification() {
remoteViews = new RemoteViews(getPackageName(), R.layout.player_noti_layout);
notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("default",
getString(R.string.player_channel),
NotificationManager.IMPORTANCE_LOW);
channel.enableVibration(true);
channel.enableLights(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.setDescription("Notification, Play/pause & Next/Prev");
notificationmanager.createNotificationChannel(channel);
}
builder = new NotificationCompat.Builder(this, "default");
Notification foregroundNote;
// Set icon
foregroundNote = builder.setSmallIcon(R.drawable.ic_radio)
.setLargeIcon(R.drawable.cool_1)
// Set ticker message
.setTicker(getResources().getString(R.string.app_name))
// Dismiss notification
.setAutoCancel(false)
.setOngoing(true)
.setContent(remoteViews)
.setContentTitle("title").
setContentText("text")
.build();
foregroundNote.flags |= Notification.FLAG_ONGOING_EVENT;
foregroundNote.flags |= Notification.FLAG_NO_CLEAR;
foregroundNote.contentView = remoteViews;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
startForeground(2, foregroundNote);
} else
notificationmanager.notify(2, foregroundNote);
}
In a few words, that's due to fragmentation and customization. Probably that phone has some kind of setting to configure that behavior. As someone said one day: Some phones are just -trash-. Don't waste your time trying to fix an issue for every possible phone.

Playing different Sound files in Appcelerator Titanium makes the audio got noise

I have created an app using appcelerator for Iphone , which buy click on buttons it will play a relative sound , here is the code, but the problem is when i play the audio many times and play different audios using this function the sound starts to lag and have noise inside, can anybody help me with it , Thanks.
var soundplaying = 0;
var sound;
function playaudio(url) {
if (soundplaying == 0) {
sound = Ti.Media.createSound({});
sound.setUrl('../assets/audio/' + url);
sound.addEventListener('complete', function() {
sound.release();
soundplaying = 0;
});
sound.play();
soundplaying = 1;
}
}
(i have tried to release the sound object after each time but still no use, I tried to createSound only once but seems the titanium dose not support changing url for Media.Sound) dynamically.
I could have solve this issue temporary , by changing the audio files format to .m4a (aac).
i was using mp3 earlier.

How can I draw the stream of a camera on a Silverlight control - Metro & Windows 8

I have a tablet with Windows 8 installed and I want to create a Metro-Application.
I have a front-facing and a back-facing camera. I'd like to draw the camera stream of any of these sources on a Silverlight rectangle. For Windows Phone 7 I can do that with a VideoBrush in a Rectangle.
How does that work on Windows 8?
And I'm not talking about making pictures with the CameraCaptureUIclass
I'm sorry, I just found a similar question/answer here:
the answer for my problem is this:
<CaptureElement x:Name="captureElement"/>
async private void StartCamPrev()
{
var mediaCapture = new Windows.Media.Capture.MediaCapture();
await mediaCapture.InitializeAsync();
this.captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
}
And the answer about the front-face/back-face camera I found here:
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var mediaCapture = new Windows.Media.Capture.MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
// the index of the devices-array is defining the device
// here I just put a '0' for testing-purposes:
VideoDeviceId = devices[0].Id
});

Appcelerator titanium TableView with Android 4.x zoomed out

I am working on appcelerator titanium. After I copied almost the same code in KitchenSink to do a tableview, I ended up with a zoomed out TableView when i display it in my device ( android 4 on Galaxy Nexus ). Zoomed out means font and images are really small. What's weird is: 1- it displayed just right in the android emulator 2- it displayed just right in my android device but using KitchenSink
What can be the problem ?
here is the code for that part:
if (Ti.Platform.name == 'android')
{
Titanium.UI.currentWindow.backgroundColor = '#4e5c4d';
}
else
{
Titanium.UI.currentWindow.backgroundColor = '#aebcad';
}
// create table view data object
var data = [
{title:'Table View (Layout 2)', hasChild:true, test:'../main_windows/profile.js'}
];
// create table view
var tableViewOptions = {
data:data,
style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
headerTitle:'TableView examples and test cases',
footerTitle:"Wow. That was cool!",
backgroundColor:'transparent',
rowBackgroundColor:'white'
};
var tableview = Titanium.UI.createTableView(tableViewOptions);
// create table view event listener
tableview.addEventListener('click', function(e)
{
if (e.rowData.test)
{
var win = Titanium.UI.createWindow({
url:e.rowData.test,
title:e.rowData.title
});
Titanium.UI.currentTab.open(win,{animated:true});
}
});
// add table view to the window
Titanium.UI.currentWindow.add(tableview);
SOLVED:
I had to change the tiapp.xml file and add the line:
<supports-screens android:anyDensity="false"/>
in the android mainfest section
so it is now:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<supports-screens android:anyDensity="false"/>
</manifest>
</android>
You should watch out because googles advice is to use this only for Android 1.4 and lower.
The better solution would be to create images which fits the screen size.
See http://developer.android.com/guide/topics/manifest/supports-screens-element.html#any

Can Adobe AIR Desktop application take full screen snapshots (aka Print Screen button)

I would like to know if its possible to get full screen snapshots from an air application.
What i am interested in, is functionality similar to PrintScreen button in windows, which takes snapshots of all screens, including third party application windows, not just window in which air app is running.
If its not specific to air, and flash/flex API can provide such functionality, it also would be great.
Thanx a lot in advance.
Check out this article as it explains obtaining a screenshot by calling a native process:
import flash.filesystem.File;
import flash.events.NativeProcessExitEvent;
var process:NativeProcess;
if(NativeProcess.isSupported) {
var file:File = File.applicationDirectory;
var args:Vector.<String> = new Vector.<String>();
if (Capabilities.os.toLowerCase().indexOf("win") > -1) {
file = file.resolvePath("PATH/TO/WINDOWS/printscr");
//use your prefered screenshot tool here (e.g. https://code.google.com/p/screenshot-cmd/
//also setup the args as needed
} else if (Capabilities.os.toLowerCase().indexOf("mac") > -1) {
file = file.resolvePath("/usr/sbin/screencapture");
args[0] = "-i";
args[1] = "screencapture.png";
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = args;
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.workingDirectory = File.desktopDirectory;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(NativeProcessExitEvent.EXIT,done);
}else trace("NativeProcess NOT SUPPORTED!");
function done(e:NativeProcessExitEvent):void{
trace("screenshot comprete");
}
One important thing to bear in mind is the AIR device profile.
If you're initially testing in ADL, be sure to use the extendedDesktop profile, otherwise NativeProcess.isSupported will return false.
For more details check out the NativeProcess documentation and the Communicating with native processes in AIR developer guide