How to find forground application Unique ID/Name in Blackberry - blackberry

I have problem in finding the current opened application name.
I used ApplicationManager class for getting the visible applications.
The application descriptors are showing the same name for all these apps Email,Messaging,Sms,call log.
They are displaying "net_rim_bb_messaging_app" for all the above apps.
I need to find a unique identifier/name for these applications(Email,messaging,sms,calllog) when they are opened.
I tried this for the past 3 days and can't find a solution.
Can you please let me know a solution for this?
ApplicationDescriptor [] appDis = manager.getVisibleApplications();
int currentForgroundAppID = manager.getForegroundProcessId();
for(int i=0;i<appIDs.length;i++)
{
if(appDis[i].getModuleName().equals("net_rim_bb_messaging_app"))
{
//print Messaging app in foreground...
}
}
the case with in the for loop above is true for every app in this list.
Email,
Text message
Call log...
But, I need to find a unique way to find the application that was opened.
Thanks In Adv,
Satish.k

following code can display current foregroundApplication name
ApplicationDescriptor[] mAppDes;
ApplicationManager appMan = ApplicationManager.getApplicationManager();
appMan.getForegroundProcessId();
mAppDes = appMan.getVisibleApplications();
for (int i = 0; i < mAppDes.length; i++) {
boolean isFG = appMan.getProcessId(mAppDes[i]) == appMan.getForegroundProcessId();
if(isFG)
{
System.out.println("This is your Foteground application Name"+mAppDes[i].getName());
}else{
System.out.println("This is your Background application Name"+mAppDes[i].getName());
}
}

Related

Display contact address in ios using xamarin

absolute beginner with xamarin.
Followed the following tutorial to try and simply click a button to display the contact list, select a contact, and then to display firstname, surname, and address on the screen.
https://github.com/xamarin/recipes/tree/master/Recipes/ios/shared_resources/contacts/choose_a_contact
Managed to get the firstname and surname to be displayed, but cannot get the address. Constantly getting the error
Foundation.MonoTouchException: Objective-C exception thrown. Name: CNPropertyNotFetchedException Reason: A property was not requested when contact was fetched.
On the
contanct.PostalAddresses
This is the snippet of code:-
partial void UIButton197_TouchUpInside(UIButton sender)
{
// Create a new picker
var picker = new CNContactPickerViewController();
// Select property to pick
picker.DisplayedPropertyKeys = new NSString[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.PostalAddresses };
// Respond to selection
var pickerDelegate = new ContactPickerDelegate();
picker.Delegate = pickerDelegate;
pickerDelegate.SelectionCanceled += () => {
SelectedContact1.Text = "";
};
pickerDelegate.ContactSelected += (contact) => {
SelectedContact1.Text = contact.GivenName;
SelectedContact2.Text = contact.FamilyName;
SelectedContact3.Text = contact.PostalAddresses
};
pickerDelegate.ContactPropertySelected += (property) => {
SelectedContact1.Text = property.Value.ToString();
};
// Display picker
PresentViewController(picker, true, null);
}
Am i missing something?
Seem to have resolved this if anyone else is having a similar issue.
The solution was to completely close down visual studio on the mac and re-open it.
Originally, i was stopping the project, and re-building. Possibly a bug, but non of my changes where being picked up.
A simple re-start kicked it back in

Fetching gmail emails using .NET MVC

I'm trying to create a little web application to act as a web mail client for Gmail...
I've used the following code to fetch the emails from my inbox:
public ActionResult Index()
{
using (var client = new ImapClient())
{
using (var cancel = new CancellationTokenSource())
{
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
client.Connect("imap.gmail.com", 993, true, cancel.Token);
// If you want to disable an authentication mechanism,
// you can do so by removing the mechanism like this:
client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate("********#gmail.com", "****", cancel.Token);
// The Inbox folder is always available...
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly, cancel.Token);
m = new List<string>();
// download each message based on the message index
for (int i = 0; i < inbox.length; i++)
{
var message = inbox.GetMessage(i, cancel.Token);
m.Insert(i, message.TextBody);
}
client.Disconnect(true, cancel.Token);
}
}
return View(m.ToList());
}
The reason why I dislike this is way of doing is that this part of code:
for (int i = 0; i < inbox.length; i++)
{
var message = inbox.GetMessage(i, cancel.Token);
m.Insert(i, message.TextBody);
}
It takes so long to fetch all the emails, approximately 40 emails are fetched each 5 seconds... So if someone has 2000 emails, it'd take 20 minutes to load all the emails...
Is there any faster way to load all the emails into my MVC application? :/
P.S. I've tried doing it with email which has 10000 emails, and it takes forever to fetch all the emails....
If all you want is the text body of the message, you could potentially reduce IMAP traffic by using the following approach:
var messages = inbox.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);
int i = 0;
foreach (var message in messages) {
var part = message.TextBody;
if (part != null) {
var body = (TextPart) inbox.GetBodyPart (message.UniqueId, part);
m.Insert (i, body.Text);
} else {
m.Insert (i, null);
}
i++;
}
What this does is send a batched FETCH request to the IMAP server requesting an "outline" (aka body structure) of the message and its unique identifier.
The loop that follows it then looks through the structure of the message to locate which MIME part contains the message's text body and then fetches only that particular sub-section of the message.
In general, you do not watch to download every message over IMAP. The purpose of IMAP is to leave all of the messages on the IMAP server and just fetch the least amount of data possible that you need in order to display whatever it is you want to display to the user.
It should also be noted that you don't actually need to use a CancellationTokenSource unless you are actually planning on being able to cancel the operations.
For example, your code snippet could be replaced with:
public ActionResult Index()
{
using (var client = new ImapClient())
{
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
client.Connect("imap.gmail.com", 993, true);
// If you want to disable an authentication mechanism,
// you can do so by removing the mechanism like this:
client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate("********#gmail.com", "****");
// The Inbox folder is always available...
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
m = new List<string>();
var messages = inbox.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);
int i = 0;
foreach (var message in messages) {
var part = message.TextBody;
if (part != null) {
var body = (TextPart) inbox.GetBodyPart (message.UniqueId, part);
m.Insert (i, body.Text);
} else {
m.Insert (i, null);
}
i++;
}
client.Disconnect(true);
}
return View(m.ToList());
}
Since you are writing your own webmail front-end to GMail, you may find the following suggestion useful:
When you look at the GMail webmail user interface or Yahoo Mail!'s user interface, you've probably noticed that they only show you the most recent 50 or so messages and you have to specifically click a link to show the next set of 50 messages and so on, right?
The reason for this is because it is inefficient to query the full list of messages and download them all (or even just the text bodies of all of the messages).
What they do instead is ask for just 50 messages at a time. And in fact, they don't ask for the messages at all, they ask for the summary information like so:
var all = inbox.Search (SearchQuery.All);
var uids = new UniqueIdSet ();
// grab the last 50 unique identifiers
int min = Math.Max (all.Count - 50, 0);
for (int i = all.Count - 1; i >= min; i--)
uids.Add (all[i]);
// get the summary info needed to display a message-list UI
var messages = inbox.Fetch (uids, MessageSummaryItems.UniqueId |
MessageSummaryItems.All | MessageSummaryItems.BodyStructure);
foreach (var message in messages) {
// the 'message' will contain a whole bunch of useful info
// to use for displaying a message list such as subject, date,
// the flags (read/unread/etc), the unique id, and the
// body structure that you can use to minimize your query when
// the user actually clicks on a message and wants to read it.
}
Once the user clicks a message to read it, then you can use the message.Body to figure out which body parts you actually need to download in order to display it to the user (i.e. avoid downloading attachments, etc).
For an example of how to do this, check out the ImapClientDemo sample included in the MailKit GitHub repo: https://github.com/jstedfast/MailKit

Blackberry: Not able to get locations SDCard/Media Card as fileSystemRoot?

I want to openOrCreate database in SDcard / Media Card. When i run the application in device (BlackBerry Curve 8900), i find only one root i.e "system/" and running application in simulator (9500), i find three roots as shown in comment in code. I am getting error at;
_db = DatabaseFactory.openOrCreate(_uri);
(error: Method "toString" with signature "()Ljava/lang/String;" is not applicable on this object)
And i am not able to understand what is this error about.
Here is the code.
public void getValues() throws Exception
{
boolean sdCardPresent = false;
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements())
{
root = (String)e.nextElement();
System.out.println("Value of root::" +root); // value of root = "system/" when run in device and
// value of root = "store/" "SDCard/" "system/" when run in simulator
if(root.equalsIgnoreCase("system/"))
{
sdCardPresent = true;
}
}
System.out.println("--------------------getValues()----------------------------------");
URI _uri = URI.create(Global.DB_PATH + Global.DB_Main);
System.out.println("Valud of uri::" +_uri);
_db = DatabaseFactory.openOrCreate(_uri); //getting error here.
System.out.println("Valud of _db::" +_db);
_db.close();
I tried these three paths, getting output with "/store"(when run in simulator) but error with rest two paths.Even using "/store" in device is showing the same error.
Global.DB_PATH = "/MediaCard/databases/";
Global.DB_PATH = "/SDCard/databases/";
Global.DB_PATH = "/store/databases/";
Is there any way how to get SDCard/Media Card as root so that i can copy the database in there?
My guess is when you are running your app on a real device you have USB cable plugged in to the device. If this is the case, try to unplug the cable and rerun the app. You may use Dialog.inform() to quickly check what roots you get this time.
private ObjectListField getFileList() {
if (fileList == null) {
fileList = new ObjectListField();
String[] roots = new String[3];
Enumeration enum = FileSystemRegistry.listRoots();
int x = 0;
while (enum.hasMoreElements()) {
if (x < 3) {
roots[x] = enum.nextElement().toString();
}
x++;
}
enum = FileSystemRegistry.listRoots();
fileList.set((roots[2] != null) ? roots : new String[]{"system/", "SDCard/", "store/"});
}
return fileList;
}
Try this code.

BlackBerry: Programmatic "Add to contacts"

If I type a phone number into the phone application on my Blackberry (5.0.0) I can hit the menu button, and one of the options is "Add to contacts" which will bring up the add contact screen, with the phone number already populated. I would like to do the same thing in my app - bring up the 'add to contacts' screen and pre-fill it with a particular phone number. Is this possible on the BlackBerry 5.0 OS?
While browsing for more information on BlackBerry contacts, I came across this support forum question, which answers my question indirectly. Posted here for anyone else in a similar situation:
http://supportforums.blackberry.com/t5/Java-Development/Problem-adding-contact-to-phone/m-p/341728/highlight/true#M62692
try
{
ContactList contacts = null;
try {
contacts = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
} catch (PIMException e) {
// An error occurred
return;
}
Contact contact = contacts.createContact();
String[] name = new String[ contacts.stringArraySize( Contact.NAME ) ];
name[Contact.NAME_GIVEN] = "Kate";
name[Contact.NAME_FAMILY] = "Turner";
contact.addStringArray(Contact.NAME, Contact.ATTR_NONE, name);
AddressBookArguments entry = new AddressBookArguments(AddressBookArguments.ARG_NEW, contact);
Invoke.invokeApplication(Invoke.APP_TYPE_ADDRESSBOOK, entry);
}
catch (Throwable t)
{
}

BlackBerry application unistallation problem?

In my balckberry application i am using the Persistance,List and Threads to execute the code.
The code is given below:
enter code here
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
CategoryListScreen.getInstance(
UiApplication.getUiApplication())
.setCategoryListContent();
}
});
public void setCategoryListContent() {
categoryList.delete(0);
CategoryListScreen categoryListScreen = CategoryListScreen
.getInstance(UiApplication.getUiApplication());
PersistentObject categoryListPersistObject = PersistentStore
.getPersistentObject(0x73c8d3592648fea5L);
PersistentObject datePersistObject = PersistentStore
.getPersistentObject(0xe453c1c0c14b9aebL);
categoryListPersistObject.setContents(Communicator.categoryDatas);
datePersistObject.setContents(new Date());
categoryListScreen.setCategoryListVector(new Vector());
categoryDataList = Communicator.categoryDatas;
System.out.println("-------------------- " + Communicator.categoryDatas.length);
for (int i = 0; i < Communicator.categoryDatas.length; i++) {
if (Communicator.categoryDatas[i] != null) {
if (Communicator.categoryDatas[i].getName() != null) {
categoryListScreen.getCategoryListVector().addElement(
Communicator.categoryDatas[i].getName());
}
}
}
testListCallback = new ListCallback();
categoryList.setCallback(testListCallback);
int i = categoryListScreen.getCategoryListVector().size();
categoryListScreen.getCategoryList().setSize(i);
System.out.println("---------------------->" + categoryListScreen.getCategoryListVector().size());
//
categoryListScreen.getCategoryList().setRowHeight(40);
// categoryListScreen.invalidate();
invalidate();
System.out.println("End.........................");
}
The application is Using the Threads to execute the persistance and also setting the size of the list.The application is running fine and exiting successfully.
But at the time of unistalling the application the device get being restarted and also after restarting the application ,there is no effect on the application.The application still remains there.
what is the problem in uinstalling the application which uses Threads,persistance and list?
why is it being restarted without any user confirmation or alert?
why is it not get being uninsall after restart?
please give the resolution for the given problem or any useful code snippet ,which would be appreciated.
Thanks,
Mishal Shah
Is this on a device simulator or a real device? As far as I know, if you reset the simulator, it loads back all the installed apps onto to simulator.

Resources