I am trying to post a picture and text to some user's news feed using the Facebook Android SDK (not using the Dialog), but for some reason it posts the picture and text only to the user's own timeline and not to the global news feed where his friends can see it. If I remove the picture param the text is shown in the news feed. Am I missing something?
This is my code:
//Prepare picture data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
//Post data
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, LoginActivity.mFacebook.getAccessToken());
params.putByteArray("picture", data);
params.putString("message", txt.getText().toString());
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(LoginActivity.mFacebook);
mAsyncRunner.request("me/feed ", params, "POST", new FacebookUploadListener(), null);
mAsyncRunner.request(response, new FacebookUploadListener());
Can I achieve that without the Facebook SDK's dialog?
Related
I'm trying to use Aspose pdf java to digitally sign a document. This is my code
public ByteArrayOutputStream signDocument(Document doc, String signedBy) throws Exception {
PdfFileSignature pdfSignSingle = new PdfFileSignature();
pdfSignSingle.bindPdf(doc);
pdfSignSingle.setCertificate(prop.getSigningKeyStorePath(), prop.getKeystorePassword());
PKCS7 signature = new PKCS7(prop.getSigningKeyStorePath(), prop.getKeystorePassword());
pdfSignSingle.setSignatureAppearance(prop.getSimploudLogo());
signature.setAuthority("Authority");
signature.setDate(new Date());
signature.setContactInfo("email");
signature.setLocation("Location");
signature.setReason("reason");
pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 200, 200), signature);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pdfSignSingle.save(baos);
pdfSignSingle.dispose();
doc.dispose();
return baos;
}
In picture is shown how the signature looks in adobeReader.
As you can see both image and Authority are not shown. I tried image to be both in pdf and png format. I've also tried to make it smaller then Rectangle area. As for authority i really need it to be customizable so that text in first line in picture can be
Signed by "customParameter"
The API offers another Class i.e. SignatureCustomAppearance which can further be used to set such properties for a signature such as DateSigned, Reason, Location, etc. Please check the following complete code snippet which can fulfill your requirements:
String inputFile = "doc.pdf";
String outSignedFile = "out_20.9.pdf";
// Create PdfFileSignature instance
com.aspose.pdf.facades.PdfFileSignature pdfSignSingle = new com.aspose.pdf.facades.PdfFileSignature();
// Bind the source PDF by reading contents of Stream
pdfSignSingle.bindPdf(inputFile);
PKCS7 pkcs = new PKCS7("mykey2.pfx", "pass");
pkcs.setAuthority("Authority");
pkcs.setDate(new Date());
pkcs.setContactInfo("email");
pkcs.setLocation("Location");
pkcs.setReason("reason");
pkcs.setImage(new FileInputStream("simpleLogo.png"));
SignatureCustomAppearance sca = new SignatureCustomAppearance();
sca.setDateSignedAtLabel(null);
sca.setDigitalSignedLabel(null);
sca.setShowReason(true);
sca.setShowLocation(true);
sca.setShowContactInfo(true);
pkcs.setCustomAppearance(sca);
pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 200, 200), pkcs);
// Set image for signature appearance
//pdfSignSingle.setSignatureAppearance("simpleLogo.png");
// Save final output
pdfSignSingle.save(outSignedFile);
As mentioned in the comment below the question, the same inquiry was posted in Aspose.PDF official forum as well at "Aspose pdf java PdfFileSignature setAuthority not working" and a solution has also been provided there.
I'm attempting to obtain an image URL through JSON data, which works successfully. Everything below works SLOWLY. However, I am trying to figure out a way to get a URL to display much faster below in Android Volley or another fast method. I am trying to download these images from a URL (resized too) into a MapView pin icon. If there is a more efficient example anyone can find, I am all in. Please let me know if you need more information from me. I am following this guide: Android load from URL to Bitmap
final String profilePicture = profilePic;
URL url = new URL(profilePicture);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bit = BitmapFactory.decodeStream(is);
Bitmap b = Bitmap.createScaledBitmap(bit, 100, 100, false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 10, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(decoded);
Use picasso library :
http://square.github.io/picasso/
Its easy to use and have alot of useful feature !
For example :
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)
You can use Koushik Ion library. Its very easy to use.
[https://github.com/koush/ion][1]
This is my code to post image on my facebook wall its done successfully. but image is not saved in photos on facebook album and it is too small.
Bundle b = new Bundle();
b.putString("picture", imageurl); // imageurl ="http://bks6.books.google.ca/books?id=5VTBuvfZDyoC&printsec=frontcover&img=1&+zoom=5&edge=curl&source=gbs_api"
b.putString("caption","This is deme");
b.putString("description","Download " );
b.putString("name","Demo Name");
b.putString("message","Download www.google.com \n Vote For tp://abc.com");
b.putString("link","WWW.google.com"); // demo link
String strRet = fb.request("/me/feed",b,"POST");
My image should look like this but its not happening. i mean in big size.see bellow image. .
see the image which i posted on wall its too small and its not saved in album.
please help me ..
Add following parameter.
b.putString("method", "photos.upload");
//..other extras
replace following line
fb.request("/me/feed",b,"POST");
with
fb.request(null, b, "POST");
Following is full code.
FileInputStream fis;
try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(imageUrl);
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
int imageLength = (int)(entity.getContentLength());
InputStream is = entity.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(b)) != -1) {
baos.write(b, 0, bytesRead);
}
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
params.putString("caption",
"your Caption\nYour Caption");
String resp = facebook.request(null, params, "POST");
}
I believe you should be uploading images to someone's album rather than to their wall (as you're doing).
Try this: (I realize this example is php, and not java... I'll see if I can dig up the java sample).
https://developers.facebook.com/blog/post/498/
edit:
Here's an Android sample:
http://sunnysharma4android.blogspot.com/
I am trying to build a function for the android phone that will open the CameraAPI and then send the captured picture to a new activity.
In this activity i need it to show a preview for the image and then save.
How could i go about doing this without having to save the image to the SD card?
You can store the image into a bitmap and then convert it to byte array and then transfer to other activity through this code below
Bitmap bitmapPicture= "PICTURE FROM CAMERA";
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmapPicture.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
Then Pass Through Intent
Intent imagepass = new Intent(Cam.this,Preview.class);
imagepass.putExtra("imagepass", bytes.toByteArray());
startActivity(imagepass);
In Other Activity we have to recieve the byte array and convert to bitmap and display in imageview through
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("imagepass");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView iv=(ImageView) findViewById(R.id.imgvw2);
iv.setImageBitmap(bmp);
You will have to use custom camera control Hope This Helps.
I have an app that takes a screenshot and the shares this with the share intent. Rather than save multiple images each time a user wants to simply share the image. Below is the code I used for images saved to the SD
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
dir = "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Folder/" + location;
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(dir));
startActivity(Intent.createChooser(share, "Share Image"));
However I cant figure out how to simply save a Bitmap such as...
share.putExtra(Intent.EXTRA_STREAM, theBitmap);
Is there a way to do this without saving the image?
Thanks
What I eneded up doing was saving one "Temp" image to the SD/Phone and just overwrite the each time.
Try using this one:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Uri uri = Uri.parse("android.resource://com.your.app/drawable/" + yourimage);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareImage);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Send your image"));
This code works fine for me to send drawables that I use in my app. No pictures saved on sd card. The only problem is that it doesn't work with some social apps :/
Yes you can send the image without having to save it as a file. From just looking at the code you posted I have no idea how your sending the image but you convert the file with the following:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] data;
if(yourBitmap!=null){
yourBitmap.compress(CompressFormat.PNG, 75, bos);
}else if (yourBitmap==null){
Log.w("Image going to server is null","Lost in memory");
}
try{
data = bos.toByteArray();
I dont know if your sending the image to another user via your app or what but thats how I use it upload to a server. When your done with the image you would just nullify it all like this.
bos = null;
data = null;
yourBitmap = null;