Is it possible to add a blackberry PIN to a device's 'black berry messenger' contact list programmatically?
Can anyone verify this for me?
I have looked through the API, but I do not see a clear way.
Thank you.
Before you begin: Make sure that you have completed the task, Register your application with the BlackBerry Messenger platform, and that the class that displays the MyBBMChatScreen screen passes in a reference to the application's associated BBMPlatformContext object into the screen's contructor. (as always :D)
I use this codes to add just one contact. You can modify it to add multiple contact. Just change the size of contacts array.
String PIN = "123456";
String name = "Someone";
BBMInvitationRequest[] contacts = new BBMInvitationRequest[1];
contacts[0] = new BBMInvitationRequest(PIN, name);
platformContext.getUIService().inviteToBBM(contacts);
May this help :)
Related
What have I done so far:
I am currenctly facing some problems with the launchers.
My application adds shortcuts to the workspace of the launcher (homescreen).
But on some devices (Samsum Duos) for example, the titles and /or icons
are changed back after reboot to my default application one.
So I am currently going through 1000s of lines code in the android
source to identify the problem, but was not able to find it.
I saw in InstallShortcutReceiver
a comment in line 183 that the "name" provided by Intent.EXTRA_SHORTCUT_NAME can in
some situations be used only for comparison etc and will be replaced
with the applications default name.
// This name is only used for comparisons and notifications, so fall back to activity name
// if not supplied
But (my Samsum Duos is rooted) I could find the complete information's
about the cell position and shortcutInfo's inside of the launcher.db.
So it was not gone, after reboot, but maybe only not correct initialized!
First Question:
Does anybody know the reason for a custom, programmatically created shortcut to change the title and or icon back to the application's one that created it?
Next story:
I noticed that this issue was reproducible on my Samsum Duos, so I decided
to exclude the Devices Launcher from my "save launcher" list.
To receive the default launcher I am doing the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = null;
try {
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); //can return null!
}catch(RuntimeException e){
ExceptionHandler.logAndSendException(e);//package manager has died
return false;
}
But the problem now is, that it always returns that the default launchers
package is: com.android.launcher2.Launcher, which would be the standard
android stock launcher. But I know that Samsum uses the TouchWiz home
launcher, whos Package is located under com.sec.android.app.launcher!
That is also where I found the launcher.db and all its ShortcutInfo's.
2. Second Question
How do I get reproducible the correct default launcher package to identify
which launcher is used?
edit:
I kind of fixed the second problem. Somehow the ResolveInfo I get from
the PackageManager seems to be not reliable.
For the Samsum Duos I get:
resolveInfo.activityInfo.name = com.android.launcher2.Launcher
resolveInfo.activityInfo.packageName = com.sec.android.app.launcher //this is what I need
But for the Redmi MIUI:
resolveInfo.activityInfo.name = com.miui.home.launcher.Launcher //this time I would need this
resolveInfo.activityInfo.packageName = com.miui.home //the packageName is not complete!
I need an unique identifier for the launcher! So I thought activityInfo.name would be the
way to go, but it isn't in some situations. And the packageManager seems to apply to too many devices. Any suggestions?
Cheers!
Android platform is really fun to work with especially when it comes to resolving issues. Indeed, there is possibly everything there is to know about Android development on the internet.
Alright, I've been searching for about a week and haven't found anything that was close from working. Let's dive into it.
We are building an Android Application that requires a read/write access to existing Contacts on a device. It has become really easy to read a contact's set photo using this method :
// Returns a stream reading a contact thumbnail
public InputStream getContactThumbnail(int id) {
// Stream reading contact image
InputStream stream = ContactsContract.Contacts.openContactPhotoInputStream(
context.getContentResolver(),
ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, id
)
);
// If image is null, try to read Facebook image
if (stream == null) {
stream = new ByteArrayInputStream(getFacebookPhoto(id));
}
return stream;
}
Now, the previous method receives an id as a parameter and returns a Stream making it possible to read the contact's thumbnail. It is needed to be a stream because the phone acts like a web server and has multiple threads running. If a thumbnail is requested several times in the same short time lapse, an OutOfMemoryException will be thrown for sure.
I need to correctly implement the getFacebookPhoto(int) method so that it returns whatever stream reading the Facebook profile picture of a contact that has his or her contact linked with his or her respective Facebook profile. I've tried and failed so many times.
Hypothesis #1
If a contact is linked with a Facebook profile, it has to have the Facebook ID saved somewhere. If this information is accessible, it would make it easy to get a Facebook profile picture using graph. Problem is an internet connection is needed to do so.
Hypothesis #2
Facebook thumbnails are saved somewhere on the SD card. Maybe there's a link between a Contact and those files that can be found through an SQLite request?
Hypothesis #3
sigh, I look desperate. Okay, if I understood correctly, a phone Contact and a Facebook Contact are not the same things in the database. If you query all the contacts from the following URI :
*ContactsContract.Contacts.CONTENT_URI*
you only get contacts that you created and nothing regarding Facebook links. Is there a way to find all linked contacts and get their respective photos?
Conclusion
Yeah, that's about is. To sum it up, I need to read all contacts information. For each contact, I have to find its photo. If the user has not set a picture to a contact that is linked to a Facebook profile, the profile picture which it was linked too must be read.
Up until now, the StackOverflow community has been of a great help and saved my life and job countless times. It is possible, I've seen it in other apps.
Thank you for spending of your time, it is truly appreciated.
EDIT
Let's not give up! I will start a 100pts bounty as soon as I can.
Your hypothesises are right to a certain extend. In contact application this things are handled as folows -
Device's Contact & its Facebook account are mapped by Contact's _ID & Facebook's id, this is one-to-one mapping. So from this mapping first you have to find out the Facebook id
of the conserned contact. But in which table this info is stored & wheather that table is eposed to you or not, URL to that table completely dependent on vendors.
From Facebook Id we can get corresponding profile image either from Facebook's server or from Media DB, if it is also cached in.
But this is not supported by all OEMs. And implementation varies from OEM to OEM as Google don't enforce for any common standard implementation of it.
So there is no garantee that a single implementation will work for all devices from different OEMs.
You should really go and play around with Graph Explorer on the Facebook Developers site it will help you a lot in figuring out what you need to do to get certain things. In order to get the picture for an person you just have to do is do a simple GET HTTPRequest with the graph path of /ID?fields=picture (where ID is the facebook id of the contact) which will return a JSON object that contains the link to that person's profile picture. From there it should be fairly simple for you to get the image.
You can also do the same thing to get all of a person's friends with the picture information by sending a GET request to /me/friends?fields=picture. It seems like you are trying to avoid a web connection but if the android contacts do not store the facebook id then you will have to get the ids yourself I'm afraid.
Hope that helps.
Why don't you use FQL, for Android you can use -
String query = "SELECT uid, name, pic, pic_small, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new CustomRequestListener());
where CustomRequestListener() extends RequestListener in the Facebook Android SDK.
With a couple of timeline items sharing the same bundle ID, I create the bundle cover with:
TimelineItem timelineCover = new TimelineItem();
timelineCover.setText("Help Options");
timelineCover.setBundleId(bundleId);
timelineCover.setNotification(new NotificationConfig().setLevel("DEFAULT"));
timelineCover.setIsBundleCover(true);
timelineCover.setIsPinned(true);
MirrorClient.insertTimelineItem(credential, timelineCover);
It comes through to the timeline properly bundled but with isPinned = false.
I tried updating the isPinned field to true in the timeline playground but it stays false.
Is it possible to pin a bundle?
You can only pin a bundle by setting a non-cover item of the bundle to have the menu action TOGGLE_PINNED, and then the user has to tap on the cover, drill into a child card that can be pinned, tap it for the pin option and then pin it. This has the result of pinning the entire bundle, including the cover which as David pointed out in a comment, even when set to be able to be pinned, can't since clicking it just goes into the bundle.
Something else related in that it's also kind of weird and related to bundles, is that if you allow a user to delete the cover of a bundle, and they do, the children do not get deleted, instead the most recently added card becomes the new cover.
I think this is a great question. Thanks for it Daniel.
The isPinned property cannot be directly set to true. Your user must pin the card themselves using the TOGGLE_PINNED built-in menu item.
Your code for the timeline item insert would look like this:
TimelineItem timelineCover = new TimelineItem();
timelineCover.setText("Help Options");
timelineCover.setBundleId(bundleId);
timelineCover.setNotification(new NotificationConfig().setLevel("DEFAULT"));
timelineCover.setIsBundleCover(true);
List<MenuItem> menuItemList = new ArrayList<MenuItem>();
menuItemList.add(new MenuItem().setAction("TOGGLE_PINNED"));
timelineCover.setMenuItems(menuItemList);
MirrorClient.insertTimelineItem(credential, timelineCover);
Once inserted your user could use the menu to make this card pinned.
I have added code to my casual game to share highest score through social networks, email, etc.
This is the text I send as defined on strings.xml resouce, for l10n:
<string name="game_sharing_score" formatted="false">
My new High Score on Gamename: %d\n
You can download Gamename from here:\n
https://play.google.com/store/apps/details?id=gamepackage
</string>
Please, note that Gamename and gamepackage are not the actual ones that I am using.
The code for sharing is the following one:
String shareScoreMsg = String.format(context.getString(R.string.game_sharing_score), highestScore);
Intent shareScoreInt = new Intent(Intent.ACTION_SEND);
shareScoreInt.setType("text/plain");
shareScoreInt.putExtra(Intent.EXTRA_TEXT, shareScoreMsg);
game.startActivity(Intent.createChooser(shareScoreInt, context.getString(R.string.game_sharing_score_title)));
game is an Activity, context is an Application context, game_sharing_score_title is the title of the activity "Share your score". Anyway there is no problem with the code it self, it is working fine for sharing through Google+, WhatsUp or Twitter, but when the user selects to share through FaceBook, the text is clipped and it publish only the last link, with the information and one icon image that FB gathers from Google Play, ignoring all the text before the link.
It is pretty clear that the problem is just with Facebook, no with the code or the string.
What I would like to find is some kind of workaround, if exists, to avoid these FB problems. To be honest, I do not like Facebook, but it is a social network with millions of people and I cannot simply ignore it on my game.
Thanks a lot in advance,
Create Facebook app on your account
After that, you get the App id.
Access all methods from Facebook API.
I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.