I am stuck to get the click event of notification (android notification area),
actually i want to open web page when user click on the notification.
here is my code,
var intent = Ti.Android.createIntent({
flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK,
data : 'http://www.google.com',
//url : 'http://www.google.com',
className : 'com.android.browser.BrowserActivity',
packageName : 'com.android.browser'
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
var pending = Ti.Android.createPendingIntent({
activity : Ti.Android.currentActivity,
intent : intent,
type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY
});
var dateValue = new Date();
var notification = Ti.Android.createNotification({
contentIntent : pending,
contentTitle : Title,
contentText : Message,
tickerText : Title,
when : dateValue.getTime(),
icon : Ti.App.Android.R.drawable.appicon,
flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS,
sound : Ti.Filesystem.getResRawDirectory() + 'notification.wav',
});
Ti.Android.NotificationManager.notify(1, notification);
This one of #phil worked for me:
https://github.com/foolprooflabs/AndroidNotificationsCustomActivity
But I've switched to gcm.js, because it's much more reliable.
http://iamyellow.net/post/40100981563/gcm-appcelerator-titanium-module
Related
// i have done the following code on the button click but when i
click on the choose button the screen gets stuck on this screen
only.
btnGallery.addEventListener('click', function() {
Ti.Media.openPhotoGallery({
mediaTypes : [![enter image description here][1]][1][Ti.Media.MEDIA_TYPE_VIDEO], *//to select video*
success : function(event) {
var result=event.media; *//Store video in blob form*
Ti.API.info(event);
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function(e) {
Ti.UI.createAlertDialog({
title : 'Success',
message : 'status code ' + this.status
}).show();
};
xhr.open('POST', 'http://videorequestlive.com/upload_videos');
xhr.send({video : event.media,uploadedby : Ti.App.Properties.getString('loginProfileId'),requested_video_description : rowChildren[1].text,requested_video_id : rowChildren[3].text,requestedby : rowChildren[4].text,requested_video_title : 'User',});
},
});
Your mediaTypes seems to be broken
Try this:
btnGallery.addEventListener('click', function() {
Ti.Media.openPhotoGallery({
mediaTypes : [Ti.Media.MEDIA_TYPE_VIDEO], *//to select video*
success : function(event) {
var result=event.media; *//Store video in blob form*
Ti.API.info(event);
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function(e) {
Ti.UI.createAlertDialog({
title : 'Success',
message : 'status code ' + this.status
}).show();
};
xhr.open('POST', 'http://videorequestlive.com/upload_videos');
xhr.send({video : event.media,uploadedby : Ti.App.Properties.getString('loginProfileId'),requested_video_description : rowChildren[1].text,requested_video_id : rowChildren[3].text,requestedby : rowChildren[4].text,requested_video_title : 'User',});
},
});
I have a question regarding node orm2 hasMany association, my model definition is like this.
schemas/Channel.js
var model = db.define('channels', Channel, ChannelOptions);
var Channel = {
channel_name : String,
channel_email : String,
channel_id : String,
views : Number
};
var ChannelOptions = {
id : "channel_id",
methods: {
my_details : function (err) {
return this.channel_id +' '+ this.channel_name + ' ' + this.views;
}
}
};
schemas/network.js
var model = db.define('networks', Network, NetworkOptions);
var Channel = require('../schemas/Channel')(db);
model.hasMany('channels', Channel, {}, {autoFetch:true});
model.sync()
db.sync(function(){
console.log('DB SYNCHED');
});
var Network = {
network_id : Number,
name : String,
username : String,
logo : String,
website : String
};
var NetworkOptions = {
id : "network_id",
methods: {
}
};
It created a networks_channels table and I have filled it with a networkID and channelID. it is responding with the property (channels) but it is empty.
Is there something missing?
Just figured out what was wrong.
Its becauset I have set up the database table definitions before doing db.sync(). Turns out that its doing all the work for me. Clearing up the tables and refilling it with data did the trick.
Im developing an "share on facebook" button.
But there is a problem, the facebook dialog is not prompted to the user.
I have tried the sample that titanium provide:
function facebook(){
var fb = require('facebook');
var data = {
link : "http://www.appcelerator.com",
name : "Appcelerator Titanium Mobile",
message : "Checkout this cool open source project for creating apps",
caption : "Appcelerator Titanium Mobile",
picture : "http://developer.appcelerator.com/assets/img/DEV_titmobile_image.png",
description : "You've got the ideas, now you've got the power."
};
fb.dialog("feed", data, function(e) {
var toast = Ti.UI.createNotification({
message:"Default",
duration: Ti.UI.NOTIFICATION_DURATION_LONG
});
if(e.success && e.result)
toast.message = "Success! New Post ID: " + e.result;
else {
if(e.error)
toast.message = e.error;
else
toast.message = "User canceled dialog.";
}
toast.show();
});
}
The function is called correctly, but nothing appear.
Someone knows why? Maybe permissions? But i have read that for the dialog aren't required permissions!
thanks to all
try this:
var fb = require('facebook');
fb.appid = FACEBOOK_APP_ID;
fb.permissions = ['publish_stream']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged In');
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
fb.authorize();
I solved by myself!
Even if the Facebook Dialog not Require the Auth(), it require the init with an AppID.
var fb = require('facebook');
fb.appid = your_app_id_number;
With this worked very well.
I've got the below bit of code which pull back a list of the users facebook contacts along with their profile picture, however the images are not loading for each user, it is only showing the images for a few users.
fb.requestWithGraphPath('me/friends', {
fields : 'first_name,last_name,id,installed,picture.width(120).height(120),gender'
}, 'GET', function(e) {
if (e.success) {
var d = JSON.parse(e.result);
var pData = [];
var iData = [];
var row = d.data;
row = row.sort(sortByName)
for (var i = 0; i < d.data.length; i++) {
var img = row[i].picture.data.url
if (row[i].installed) {
pData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
gender : row[i].gender,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
} else {
iData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
}
}
var play = Ti.UI.createListSection({
headerTitle : 'Play with Facebook Friends',
items : pData
});
var invite = Ti.UI.createListSection({
headerTitle : 'Invite Facebook Friends',
items : iData
});
var listView = Ti.UI.createListView({
sections : [play, invite],
});
self.add(listView)
} else {
alert("Facebook Error");
}
})
The images are stored in var img = row[i].picture.data.url and pushed into the data array as part of image : img but not all images are loading.
Is there a way to force the images to load? and show a default image whilst they are loading?
Here is a link to complete example to do exactly what you are trying to accomplish abaove
http://www.clearlyinnovative.com/blog/post/34758524584/alloy-listview-facebook-friends#.UgexZGRATrg
Using the Titanium.Media.createVideoPlayer API in Android 2.2 can't get the video to play in Titanium 2.1.2 using a Ti.UI.currentWindow.
/**
* #author David
*/
var win = Ti.UI.currentWindow;
//var win = Ti.UI.createWindow({});
var contentURL = "http://assets.appcelerator.com.s3.amazonaws.com/video/media.m4v";
var openButton = Ti.UI.createButton({
title : "Start Video",
top : "0dp",
height : "40dp",
left : "10dp",
right : "10dp"
});
openButton.addEventListener('click', function() {
var activeMovie = Titanium.Media.createVideoPlayer({
url : contentURL,
backgroundColor : 'blue',
movieControlMode : Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
fullscreen : true,
autoplay : true
});
var closeButton = Ti.UI.createButton({
title : "Exit Video",
top : "0dp",
height : "40dp",
left : "10dp",
right : "10dp"
});
closeButton.addEventListener('click', function() {
activeMovie.hide();
activeMovie.release();
activeMovie = null;
});
activeMovie.add(closeButton);
});
win.add(openButton);