My app has a feature that posts a photo + text to a user's facebook wall (works fine). Now I'm trying to include a link in the text that goes to a specific facebook page (doesn't work).
The basic code looks like this (works fine):
private void postImageToFacebookWall(String filePath, String msg) {
try {
Bundle param = new Bundle();
param = new Bundle();
// prep photo byte array
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
// add byte array and user msg
param.putByteArray("image", byteArray);
param.putString("message", msg);
// post to Facebook
mAsyncRunner.request("me/photos", param, "POST", new PostRequestListener(), null);
} catch (Exception e) {
e.printStackTrace();
}
}
Now I'm trying to embed a link to a facebook page in the msg, using the following syntax:
#[fb_page_id:str]
This works when I type it directly into facebook. But it doesn't work when I use it in the code, modified as follows (doesn't work):
String fbPageRef = "#[" + Constants.FACEBOOK_PAGE_ID + ":str]";
param.putString("message", msg + " " + fbPageRef);
When I run the code with the embedded link (fbPageRef), it doesn't show up.
What am I doing wrong? Thanks.
I didn't notice at first that a facebook post generated by an app already includes an attribution to the source app. It's at the bottom of the post and reads something like: "2 hours ago via YourAppName".
This is friendly to read, and correctly links back to the app's facebook page (assuming there is one). So if that's good enough, you don't have to worry about how to insert a link in the text part of the post!
Still it would be good to know how to embed a link to a facebook page in a machine-posted message (?). Thanks.
Related
I have a notification listener service that reads notifications from other apps (with the user's permission) and extracts all the data. Able to access everything except the image shown in the expanded view of the notification.
I am also reading the EXTRA_PICTURE intent value
if (extras.containsKey(Notification.EXTRA_PICTURE)) {
// this bitmap contain the picture attachment
try {
Bitmap bmp = (Bitmap) extras.get(Notification.EXTRA_PICTURE);
ByteArrayOutputStream picStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, picStream);
byte[] picBmpData = picStream.toByteArray();
notificationPicture = Base64.encodeToString(picBmpData, Base64.NO_WRAP);
} catch(Exception e){
e.printStackTrace();
}
}
This works sometimes but for all notifications with image in their expanded view. Am I missing anything?
UPDATE: more clarification on what happens in the negative cases:
In negative cases when there is an image in the notification, the extras dont seem to have the EXTRA_PICTURE key set. However I do see
android.template
key set to
android.app.Notification$BigPictureStyle
Im interested in running some custom analytics on my interactions with contacts on my phone.
Some things I would like to see are:
How many times was this contact called
How long did the conversation last
How many missed calls from this contact
How many answered calls from this contact
What time and date was an sms sent
What was its message content
What time and date was an sms received
What was its message content
If it was mms can i get the picture some how
Ill use a third party api for facial recognition and nudity checks (was it a nude, selfie, meme)
Is there a way to simply export this data into a xml or csv file? (How would I save pictures?)
My goal here is to make an app using some sort of android java sdk. Then using the app, ill upload to my web server and use php to do the analytics.
Where do i look to start getting the information i want to analyze?
Try to look at these links:
PhoneStateListener
TelephonyManager
Read SMS
ContentResolver
To export your pictures from mms use a filestream and a bitmap:
private void GetMmsAttachment(String _id, String _data)
{
Uri partURI = Uri.parse("content://mms/part/" + _id );
String filePath = "/sdcard/photo.jpg";
InputStream is = null;
OutputStream picFile = null;
Bitmap bitmap = null;
try {
is = getContentResolver().openInputStream(partURI);
bitmap = BitmapFactory.decodeStream(is);
picFile = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, picFile);
picFile.flush();
picFile.close();
}
catch (Exception e)
{
e.printStackTrace();
//throw new MmsException(e);
}
}
Also for photo Identification I recommend you use IBM Watson,.If the photo has text use Google Tesseract to extract the text.
I need to save ParseObject with ParseFile, but locally. Method pinInBackground gives error: "Unable to encode an unsaved parse file"
I can not call file.saveInBackground. Because I need to use offline mode.
So what should I do?
//get bitmap
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] data = baos.toByteArray();
Random random = new Random();
//create parse File
final ParseFile file = new ParseFile(random.nextInt(10000) + ".jpeg", data);
parseObject.put(KEY_IMAGE, file);
parseObject.pinInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
//do some action
}
});
Let me create an answer for all of this.
That error really does tell you what is wrong with the app. You can not pin something that isn't there. Parse pins objects.... you never created an object (yet). Therefore, you can not pin a unsaved object.
You can do two things.
1) If there is no internet connection, display the message to the user and tell them that. Once they restore, they can try again.
2) Use saveEventually. This will save the object once internet hits the device, and then when done, you can pin it. Problem is, if the object doesn't exist and the user wants to see it, they cant.
If it was me, I would go with option 1. If you are asking your user to input files, some sort of connection would be required.
I am trying to create a custom keyboard and use "SoftKeyboard" sample in android SDK for it. I did few modifications with that sample and created my custom keyboard. I can use this custome keyboard with default Messaging app of my Android device.
Now I want to click a button in my custom keyboard and add an image when I type a SMS. I noticed that there is String Builder in "SoftKeyBoard.java" class (private StringBuilder mComposing = new StringBuilder()) and it is appended chars when we type letters using keyboard.
I tried to append an image of my SD card like below,
String imageDataString = "";
String path = Environment.getExternalStorageDirectory().toString() + "/SamplePictures/";
File file = new File(path, "myimage.jpg");
try {
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int) file.length()];
imageInFile.read(imageData);
// Converting Image byte array into Base64 String
imageDataString = encodeImage(imageData);
imageInFile.close();
} catch (FileNotFoundException e) {
System.out.println("Image not found" + e);
} catch (IOException ioe) {
System.out.println("Exception while reading the Image " + ioe);
}
and I appended "imageDataString" to String builder like below,
mComposing.append(imageDataString);
But I got so many characters, not an image.
Is it possible to insert an image when I type SMS using my keyboard?
Updated : I used ImageSpan and Spannable with following code.
SpannableStringBuilder ssb = new SpannableStringBuilder( "Here's a my picture " );
Bitmap smiley = BitmapFactory.decodeResource( getResources(), R.drawable.bitmap );
ssb.setSpan( new ImageSpan( smiley ), 16, 17,Spannable.SPAN_INCLUSIVE_INCLUSIVE );
mComposing.append(ssb);
But it displays only "Here's a my picture" and no image. I created a sample separate app with an EditText and set above "ssb" variable as the text of that EditText. Then it displays well the image. But it doesn't work with Messaging app. If I can set the Messaging app EditText, I guess I can set the image.
Is there any way to access and update the Edit text of Messaging app?
Thanks in Advance..!!
I think what you want to do is use an ImageSpan added to a Spannable, a solution which is already described here. After pressing the image button on your keyboard, you'll fire of a method that should update the editText by taking the existing text from it, adding an ImageSpan containing your image and setting that back to the editText.
I am having trouble tagging friends in pictures using the Facebook API in android. This is what I have at the moment
Bundle param;
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.picture);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] data = stream.toByteArray();
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
InputStream is = null;
param = new Bundle();
param.putString("message", dataMsg);
param.putString("filename", "Invite");
String[] numArr = invitedNum.toArray(new String[invitedNum.size()]);
param.putStringArray("message_tags",numArr);
param.putByteArray("picture", data);
mAsyncRunner.request("me/photos", param, "POST", new SampleUploadListener(), null);
Toast.makeText(context, "Picture posted to Facebok.", Toast.LENGTH_SHORT).show();
This uploads the picture and sets a message on it but does not tag anybody in the picture. Any ideas would be really helpful.
To tag users, you'd need to follow the approach outlined here:
https://developers.facebook.com/docs/reference/api/photo/#tags
So you would:
1/ Upload the photo
2/ Get the photo ID (should be returned if the upload was successful)
3/ Make a call to this Graph API endpoint:
PHOTO_ID/tags
and pass in the FB IDs in the tags parameter:
tags=[{"id":"1234"}, {"id":"12345"}].