I am looking to get the name of the operator for the user's Android device.
E.g. "Verizon" or "Vodafone", I think I have found the Android equivalent documented here called getSimOperatorName() from http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperatorName()
I am scanning over the documentation for Appcelerator Titanium, but can't seem to find a way of doing this in the docs (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network).
Is this possible in Appcelerator Titanium?
You can use tinetworkinfo Module
Ex:-
var netInfo = require('com.clever_apps.tinetworkinfo');
var win = Ti.UI.createWindow({exitOnClose: true});
var testLabel = Ti.UI.createLabel({
height:"80%",
width:"90%",
top:0
});
var refreshButton = Ti.UI.createButton({
title:"Refresh Data",
height:"15%",
bottom:"5%"
});
refreshButton.addEventListener("click", getTelephonyData);
win.add(testLabel);
win.add(refreshButton);
getTelephonyData();
win.open();
function getTelephonyData(){
var imei = netInfo.getIMEI();
var cellid = netInfo.getCellID();
var lac = netInfo.getLac();
var mnc = netInfo.getMNC();
var mmc = netInfo.getMMC();
var outString = "IMEI: "+imei+"\nCell ID: "+cellid+"\nLAC: "+lac+"\nMNC: "+mnc+"\nMMC: "+mmc;
testLabel.text = outString;
}
Currently there is no API that will return you that information. For that, you need to create your own Android module.
I could not get tinetworkinfo Module working. However, a module named TelephonyManager worked fine.
I ran this in the terminal for the project:
gittio install com.goyya.telephonymanager
Then this code to get the network operator name:
var telephonymanager = require("com.goyya.telephonymanager");
Ti.API.log('networkOperatorName: ' + telephonymanager.networkOperatorName);
Related
I'm trying to save some files on my local File storage So, I'm doing Something like below
var folder_name = "abcde/" + viewModel.dir_path;
const documents = fileSystemModule.knownFolders.documents();
documents._path = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
const folder = documents.getFolder(folder_name);
var file = fileSystemModule.path.join(folder._path, this.pdf_url.split("/").pop());
var url = this.pdf_url;
httpModule.getFile(url, file).then(function(result) {
console.log(result);
Toast.makeText(`${result._name} is succesfully downloaded in ${folder_name}`).show();
}, function(e) {
console.log(e);
});
the only problem is the hardcoded value abcde/ I want it to be app name. whatever the app name is it should take that name.
I don't find any ways to read app name programatically. I need this to Android I'm not interested in IOS.
may be this is one could be the answer. but still this is not a proper way
const documents = fileSystemModule.knownFolders.currentApp();
console.log(documents); --> "/data/data/org.nativescript.app_name/files/app"
var str = documents;
var arr = str.split("/")[3];
console.log(arr.split(".")[2]); ---> app_name
In Android, you can set the app name for the application in strings.xml, for example:
<string name="app_name">"App_Name"</string>
Then whenever you want to reuse the app name, you can use the getString method with its name in the application.
How can I run a Glide query from in a widget? (Service Portal)
This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232"); // hardcoded good sample
destination_sys_id = grTask.sys_id;
When I run the code in Scripts, I get:
*** Script: sys_id: 0f4d[...]905
When I run it in the widget, I get:{}
To elaborate on my Widget code:
Body HTML template
data.destination_sys_id = {{data.destination_sys_id }}
Server script
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id;
data.destination_sys_id = destination_sys_id;
})()
you can add it as c.data.destination_sys_id nad at the time of assigning the value to object always use .toString() in order to stringify the field value.
I needed a .toString(); in my server script:
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id.toString(); // <- note the addition of .toString()
data.destination_sys_id = destination_sys_id;
})()
Another way is to use grTask.getUniqueValue() instead of grTask.sys_id.toString().
Also, getters and setters are recommended with GlideRecord, so use grTask.getValue('sys_id') instead of grTask.sys_id.toString().
I'm trying to direct the user to the play store.
import app = require("application");
var intent = new android.content.Intent("android.intent.action.VIEW" );
intent.setData( "market://details?id=MY.APP.LINK" );
app.android.currentContext.startActivity(intent);
The above isn't working!
I think the problem has to do with my translation from Java code to something {N} can use.
#Brad Martin gave the answer in comments but I'm adding this for readability, as I needed this snippet. Didn't try the iOS part yet.
Here is the code I used, with TypeScript.
First, add those lines in import
import * as application from "application";
import * as Utility from "utils/utils";
declare var android: any;
Then, you can use a function like this one for Android
gotoPlayStore() {
let androidPackageName = application.android.packageName;
let uri = android.net.Uri.parse("market://details?id=" + androidPackageName);
let myAppLinkToMarket = new android.content.Intent(android.content.Intent.ACTION_VIEW, uri);
// Launch the PlayStore
application.android.foregroundActivity.startActivity(myAppLinkToMarket);
}
You can use this code for iOS devices
gotoAppStore() {
let appStore = "";
appStore = "itms-apps://itunes.apple.com/en/app/id" + myAppId;
Utility.openUrl(appStore);
}
This code is based on the plugin nativescript-rating from Nic Raboy and this particular file : https://github.com/nraboy/nativescript-ratings/blob/master/ratings.ts
You may get this error on Android : ERROR Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=your.package.id } , but it's working on real device, as Play Store application is running on it.
Here's what worked for me:
try
{
let uri = android.net.Uri.parse( "market://details?id=com.company" );
var intent = new android.content.Intent( android.content.Intent.ACTION_VIEW, uri );
application.android.foregroundActivity.startActivity( intent );
}
catch ( e2 )
{
console.error( "Error =" + e2.message + "=" );
}
So basically I am making an event app. Everything has been going smoothly but there's just sharing the event to twitter.
I have searched the internet but all I am getting is using the native app of twitter which I don't want. I want to use the browser to tweet.
I have implemented this method for FB sharing.
Any idea would help me a lot.
let content = FBSDKShareLinkContent()
content.contentURL=NSURL(string: "http://facebook.com")
content.imageURL = NSURL(string: "http://facebook.com")
content.contentTitle = "Shou 3emlin test app "
content.contentDescription = "testing testing testing"
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.mode=FBSDKShareDialogMode.Browser
shareDialog.shareContent = content
if !shareDialog.canShow() {
shareDialog.mode=FBSDKShareDialogMode.Native
shareDialog.shareContent = content
}
if shareDialog.canShow() {
shareDialog.show()
}
Put this in an action method of a button or in the method where you want to use the browser to tweet your text Swift 3.0:
let tweetText = "your text"
let tweetUrl = "http://stackoverflow.com/"
let shareString = "https://twitter.com/intent/tweet?text=\(tweetText)&url=\(tweetUrl)"
// encode a space to %20 for example
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
// cast to an url
let url = URL(string: escapedShareString)
// open in safari
UIApplication.shared.openURL(url!)
Result:
Take a look at Fabric.io. This SDK allows you to compose tweets directly from your app.
let composer = TWTRComposer()
composer.setText("just setting up my Fabric")
composer.setImage(UIImage(named: "fabric"))
// Called from a UIViewController
composer.showFromViewController(self) { result in
if (result == TWTRComposerResult.Cancelled) {
print("Tweet composition cancelled")
}
else {
print("Sending tweet!")
}
}
let tweetText = "hy"
let tweetUrl = "http://rimmi/"
let shareString = "https://twitter.com/intent/tweet?text=\(tweetText)&url=\(tweetUrl)"
// encode a space to %20 for example
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
// cast to an url
let url = URL(string: escapedShareString)
// open in safari
UIApplication.shared.openURL(url!)
#ronatory's solution worked like charm. It also opens a Twitter application if it's already installed on the user's device.
For swift 5+ use UIApplication.shared.open(url!) instead of UIApplication.shared.openURL(url!) as it's deprecated.
I found the nsINavBookmarksService, however since Firefox 3, it does not seem to have any API methods for getting/setting the Bookmark description. (API doc)
I've seen other Add-Ons modify the description as a method of synchronized data storage (which is exactly what I'm trying to do). I'm guessing perhaps the description is a non-gecko standard, and that's why it is not directly supported, but then there must be a completely different interface for manipulating Bookmarks that I haven't discovered.
Can anyone help with this newbie problem?
Starting with Firefox 3 the bookmarks have been merged into the Places database containing all of your browsing history. So to get the bookmarks you do a history query, like this (first line is specific to the Add-on SDK which you appear to be using):
var {Cc, Ci} = require("chrome");
var historyService = Cc["#mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsINavHistoryService);
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
query.onlyBookmarked = true;
var result = historyService.executeQuery(query, options);
result.root.containerOpen = true;
for (var i = 0; i < result.root.childCount; i++)
{
var node = result.root.getChild(i);
console.log(node.title);
}
That's mostly identical to the code example here. Your problem is of course that nsINavHistoryResultNode has no way of storing data like a description. You can set annotations however, see Using the Places annotation service. So if you already have a node variable for your bookmark:
var annotationName = "my.extension.example.com/bookmarkDescription";
var ioService = Cc["#mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var uri = ioService.newURI(node.uri, null, null);
var annotationService = Cc["#mozilla.org/browser/annotation-service;1"]
.getService(Ci.nsIAnnotationService);
annotationService.setPageAnnotation(uri, annotationName,
"Some description", 0, Ci.nsIAnnotationService.EXPIRE_NEVER);
For reference: nsIAnnotationService.setPageAnnotation()