Android Facebook Share not showing description on facebook wall - java

When my app try to share something, the description is shown in the share activity, but it does not show up when it is posted. I went through many stackoverflow posts, but nothing could solve my problem.
Here is my call flow :
Share button is clicked
Activity calls a static method and passes itself and content to share to it via Bundle
Share activity is invoked from this static method. It displays the content to share correctly with all image, caption and description
Content is shared successfully
When the facebook post is checked, it just shows the playstore app details, with the image that I had set in 3, without the description
Here is the code that i use
if (FacebookDialog.canPresentShareDialog(activity.getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG))
{
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(activity)
.setLink("<playstore link>")
.setApplicationName("<appname>")
.setName("<some name>")
.setCaption("<some text>")
.setDescription("a description")
.setPicture("http://url/to/image.jpg")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
But sharing the same using FeedDialog works
Bundle params = new Bundle();
params.putString("name", "name");
params.putString("caption", "caption");
params.putString("description","desc");
params.putString("link", "playstore link");
params.putString("picture", "http://url/to/image.jpg");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(activity,
session,
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(activity,
"Posted Successfully!",
Toast.LENGTH_SHORT).show();
activity.finish();
} else {
// User clicked the Cancel button
Toast.makeText(activity.getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
activity.finish();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(activity.getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
activity.finish();
} else {
Toast.makeText(activity.getApplicationContext(),
"An Error Occurred",
Toast.LENGTH_SHORT).show();
activity.finish();
}
}
})
.build();
feedDialog.show();
Thank You

From the docs (Versions 4.0+)
To show the ShareDialog for a link in your activity, create a
ShareDialog instance in your onCreate method:
public class MainActivity extends FragmentActivity {
CallbackManager callbackManager;
ShareDialog shareDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
}
Then show the ShareDialog:
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription(
"The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}

Slartibartfast's Answer is working fine until compile 'com.facebook.android:facebook-android-sdk:4.24.0'
From Facebook SDK version 4.25.0
setContentTitle("") setContentDescription("") is depricated.
You have to use setQuote(""); Method instead of setContentDescription("");
For more detail about depreciation Refer: https://developers.facebook.com/docs/sharing/android

Related

How to update the Flutter app state after navigating back from Android Java activity?

From the Flutter side, using the PlatformChannel, I am navigating to an Android Java activity, and doing some processes.
The activity successfully opens and I'm able to do the functionality and have the final result of it.
How may I navigate back to the Flutter side to a specific page and pass a value?
P.S.: without going back to the same page and then redirecting to the
next page.
On the Flutter side:
I have these variables
/// Filters Method Channel
final filtersChannel = const MethodChannel('flutter.native/filters');
/// Filters Method Channel
final filtersResultChannel = const MethodChannel("flutter.native/result_filters");
I have a floatingActionButton with this function which invokes a MethodChannel
Future<void> startNewActivity() async {
try {
await filtersChannel.invokeMethod('open_filters');
} on PlatformException catch (e) {
debugPrint("Failed to Invoke: '${e.message}'.");
}
}
On the MainActivity.java
On the protected void onCreate(#Nullable Bundle savedInstanceState) function, I'm starting an activity which has the AR video recording like this:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, FiltersActivity.class);
startActivity(intent);
}
On the FiltersActivity.java
On the public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) function
I’m defining and invoking my two channels:
The flutter.native/result_filters channel which builds the UI and
the functionality.
The flutter.native/filters channel which returns the final result.
Here:
#Override
public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
String resultFiltersChannelIdentifier = "flutter.native/result_filters";
filtersResultChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), resultFiltersChannelIdentifier);
String filtersChannelIdentifier = "flutter.native/filters";
MethodChannel filtersChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), filtersChannelIdentifier);
filtersChannel.setMethodCallHandler(this::filtersMethodCallHandler);
}
Then, the flutter.native/filters displays the UI using the filtersMethodCallHandler function. Here:
private void filtersMethodCallHandler(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("open_filters")) {
openUI();
} else {
result.notImplemented();
}
}
In the openUI function, I'm assigning the record button a function, here:
recordButton.setOnClickListener(this::toggleRecording);
And here's the toggleRecording function:
public void toggleRecording(View unusedView) {
boolean recording = videoRecorder.onToggleRecord();
if (recording) {
recordButton.setImageResource(R.drawable.round_stop);
Toast.makeText(this, "Started Recording", Toast.LENGTH_SHORT).show();
} else {
recordButton.setImageResource(R.drawable.round_videocam);
Toast.makeText(this, "Recording Stopped", Toast.LENGTH_SHORT).show();
videoPath = videoRecorder.getVideoPath().getAbsolutePath();
Toast.makeText(this, "Video saved: " + videoPath, Toast.LENGTH_SHORT).show();
Log.d(TAG, "Video saved: " + videoPath);
// Send notification of updated content.
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.TITLE, "Sceneform Video");
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DATA, videoPath);
getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
filtersResultChannel.invokeMethod("filters_result", videoPath);
finish();
}
}
As shown above, I'm invoking the filters_result method for the filtersResultChannel channel and I'm adding the videoPath to it.
And then, I'm calling the finish(); method to close the FiltersActivity and return back to the MainAvtivity which successfully returns me to the Flutter page!
BACK to the Flutter side,
I'm listening to the filtersResultChannel like this:
#override
void initState() {
super.initState();
filtersResultChannel.setMethodCallHandler(_filtersResultHandler);
}
Future _filtersResultHandler(MethodCall methodCall) async {
if (methodCall.method == "filters_result") {
final videoPath = methodCall.arguments;
if (videoPath != null && videoPath.length >= 0) {
SchedulerBinding.instance.addPostFrameCallback((_) {
debugPrint("YES YES YES => $videoPath");
setState(() {
reportStatus = videoPath;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoShow(clipPath: videoPath),
),
);
});
});
}
return null;
} else {
return null;
}
}
As shown above, I have a debugPrint statement, this statement prints the returned videoPath from the filtersResultChannel
<--------->
THE PROBLEM
<--------->
Even though I'm successfully getting the videoPath value and successfully returning back to the Flutter page, I'm NOT able to use it!!
The setState(); doesn't update the UI NOR navigate to the next screen, the VideoShow screen!
HOW MAY I FIX SUCH AN ISSUE?

Amazon IAP not launching purchase dialog

I'm migrating an app from the play store to the Amazon App store, considering that in this way it will be avilable for Windows 11 too.
For this to make something very fast and easy i made an activity called PurchaseActivity which contains the codes brought by the amazon IAP guide PDF.
The activity is called from a "buy now" button of a dialog window with the following code:
public class PurchaseActivity extends Activity {
String parentSKU = "com.amazon.sample.iap.subscription.mymagazine";
//Define UserId and MarketPlace
private String currentUserId;
private String currentMarketplace;
private ProgressDialog progress;
#Override
protected void onStart(){
super.onStart();
progress = new ProgressDialog(this);
progress.setTitle("Purchasing");
progress.setMessage("Wait while making the purchase...");
progress.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
progress.dismiss();//dismiss dialog
finish();
}
});
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
PurchasingService.registerListener(this, purchasingListener);
PurchasingService.purchase(parentSKU);
}
#Override
protected void onResume() {
super.onResume();
//getUserData() will query the Appstore for the Users information
PurchasingService.getUserData();
//getPurchaseUpdates() will query the Appstore for any previous purchase
PurchasingService.getPurchaseUpdates(true);
//getProductData will validate the SKUs with Amazon Appstore
final Set<String> productSkus = new HashSet<String>();
productSkus.add(parentSKU);
PurchasingService.getProductData(productSkus);
Log.v("Validating SKUs", "Validating SKUs with Amazon");
}
PurchasingListener purchasingListener = new PurchasingListener() {
#Override
public void onUserDataResponse(UserDataResponse response) {
final UserDataResponse.RequestStatus status = response.getRequestStatus();
switch (status) {
case SUCCESSFUL:
currentUserId = response.getUserData().getUserId();
currentMarketplace = response.getUserData().getMarketplace();
Log.v("IAP SDK", "loaded userdataResponse");
break;
case FAILED:
case NOT_SUPPORTED:
// Fail gracefully.
Log.v("IAP SDK", "loading failed");
break;
}
}
#Override
public void onProductDataResponse(ProductDataResponse productDataResponse) {
switch (productDataResponse.getRequestStatus()) {
case SUCCESSFUL:
//get informations for all IAP Items (parent SKUs)
final Map<String, Product> products = productDataResponse.getProductData();
for (String key : products.keySet()) {
Product product = products.get(key);
Log.v("Product:", String.format("Product: %s\n Type: %s\n SKU: %s\n Price: %s\n Description: %s\n", product.getTitle(), product.getProductType(),
product.getSku(), product.getPrice(), product.getDescription()));
}
//get all unavailable SKUs
for (String s : productDataResponse.getUnavailableSkus()) {
Log.v("Unavailable SKU:" + s, "Unavailable SKU:" + s);
}
break;
case FAILED:
Log.v("FAILED", "FAILED");
progress.dismiss();
finish();
break;
}
}
#Override
public void onPurchaseResponse(PurchaseResponse purchaseResponse) {
switch (purchaseResponse.getRequestStatus()) {
case SUCCESSFUL:
PurchasingService.notifyFulfillment(purchaseResponse.getReceipt().getReceiptId(),
FulfillmentResult.FULFILLED);
break;
case FAILED:
progress.dismiss();
finish();
break;
}
}
#Override
public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse response) {
// Process receipts
switch (response.getRequestStatus()) {
case SUCCESSFUL:
for (final Receipt receipt : response.getReceipts()) {
// Process receipts
if (!receipt.isCanceled()) {
// sharedprefs
SharedPreferences sharedPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor sharedPrefEditor = sharedPreference.edit();
sharedPrefEditor.putBoolean("isPro",true);
sharedPrefEditor.apply();
progress.dismiss();
finish();
}
}
if (response.hasMore()) {
PurchasingService.getPurchaseUpdates(true);
}
break;
case FAILED:
Log.d("FAILED", "FAILED");
progress.dismiss();
finish();
break;
}
}
};
}
Yeah i know i should not call all that stuff in the onStart() method but i'll make an onCreate() with a UI later.
As you can see from this code, i'm testing in sandbox mode.
THE PROBLEM: Actually when the activity starts, i see progressDialog, and i read in the debug logs that "V/Validating SKUs: Validating SKUs with Amazon" but i don't see then the amazon buy window. It also seems like the listener code is never called, even if i put some breakpoints in there, they're never reached which is very weird considering that apprently it gets initialized and called successfully by the method "PurchasingService.registerListener(this, purchasingListener)"
Any help would be very apreciated!
Thanks and have a good evening
You need to call registerListener in your Application's onCreate, otherwise Amazon fails to detect there's an Activity being displayed and it will not show the purchase dialog.

Problem with obtaining consent with ump / admob / funding choices

Following this guide https://developers.google.com/admob/ump/android/quick-start I tried to add everything to my app.
What I did:
link funding choices to admob
added ump to build.gradle
added the app ID to android manifest
set up a dialog for the app in admob and activated it for the app
Then I added this code to my app
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
#Override
public void onConsentInfoUpdateSuccess() {
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.isConsentFormAvailable()) {
loadForm();
}
else {
Context context = getApplicationContext();
CharSequence toastText = "No Form Available";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, toastText, duration);
toast.show();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
#Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
Context context = getApplicationContext();
CharSequence toastText = "Error";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, toastText, duration);
toast.show();
}
});
and
public void loadForm() {
UserMessagingPlatform.loadConsentForm(
this,
new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
#Override
public void onConsentFormLoadSuccess(ConsentForm consentForm) {
MainActivity.this.consentForm = consentForm;
if(consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
consentForm.show(
MainActivity.this,
new ConsentForm.OnConsentFormDismissedListener() {
#Override
public void onConsentFormDismissed(#Nullable FormError formError) {
// Handle dismissal by reloading form.
loadForm();
}
});
}
}
},
new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
#Override
public void onConsentFormLoadFailure(FormError formError) {
// Handle the error
}
}
);
}
However, I always end up getting the toast "Error" landing in onConsentInfoUpdateFailure(FormError formError) independet from testing on my mobile phone or in the virtual device (I am in europe btw).
Am I missing something?
Thanks,
Celdri
I had the same issue and I solved it just by configuring properly my adMob account.

Display a download failed notification using Download Manager for Android TV?

I,m trying to build my first app using Android Studio.Its for Android TV. I can't figure out how to notify the user if a download fails.
It's an Android TV app so threes no status bar to display download managers progress in.The code as is displays results from any button click including ones from mainactivity2. However obviously the way I have it it displays the same message when receiving ACTION_DOWNLOAD_COMPLETE regardless of success or failure.
I've tried many methods but most assume I have a better grasp on coding than I do, or had many errors I'm not knowledgeable enough to understand, so I've been unable to incorporate them.
I did manage to get a progress bar to work but with the files being less than a megabyte, and only providing an empty progress bar when download was unsuccessfull, it was less than ideal.
I'm hoping someone can help me display failure or success.
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(MainActivity.this, "Your download is complete.", Toast.LENGTH_SHORT).show();
}
};
#Override
public void onClick(View view) {
registerReceiver(receiver, filter);
int id = view.getId();
if (id == R.id.myfile) {
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request1 = new DownloadManager.Request(
Uri.parse("https://myurl.zip"));
request1.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/mydir/myfile.zip");
dm.enqueue(request1);
Toast.makeText(MainActivity.this, "Your chose myfile.zip", Toast.LENGTH_SHORT).show();
} else if (id == R.id.myfile2) {
DownloadManager dm;
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request2 = new DownloadManager.Request(
Uri.parse("https://myurl2.zip"));
request2.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/mydir2/myfile2.zip");
dm.enqueue(request2);
Toast.makeText(MainActivity.this, "You chose myfile2.zip.", Toast.LENGTH_SHORT).show();
}
}
}
I thought I should post my resolution to my problem in hopes it may assist someone with a similar situation.
I ultimately abandoned DownloadManager in favor of the fast Android networking library from https://github.com/amitshekhariitbhu/Fast-Android-Networking.
I'm sure there was a way to accomplish my goal with DownloadManager but this worked for me.
Here's an Example of receiving a success or failure toast when downloading a file. Progress status is unused in this example.
#Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.example) {
Toast.makeText(MainActivity.this, "You chose The example.", Toast.LENGTH_SHORT).show();
AndroidNetworking.download("https://example.github.io/repository.0.3.1.zip",Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/example", "/repository.0.3.1.zip")
.setTag("Download")
.setPriority(Priority.MEDIUM)
.build()
.setDownloadProgressListener(new DownloadProgressListener() {
#Override
public void onProgress(long bytesDownloaded, long totalBytes) {
}
})
.startDownload(new DownloadListener() {
#Override
public void onDownloadComplete() {
Toast.makeText(MainActivity.this, "The download is complete.", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(ANError error) {
Toast.makeText(MainActivity.this, "The download failed.", Toast.LENGTH_SHORT).show();
}
});

Facebook share completion listener

I have something i am really stuck at. The thing is that i am trying to catch the completion when some one is done with sharing something on facebook
i am using the following function to execute and catch the completion. But i am not getting the result.
public void FaceBookSharing() {
Log.d(TAG, "Running facebook share");
Log.d(TAG, "Share on facebook 1: "+sport);
Log.d(TAG, "Share on facebook 2: "+speed);
Log.d(TAG, "Share on facebook 3: "+distance);
Log.d(TAG, "Share on facebook 4: "+date);
Log.d(TAG, "Shared image url: "+sharedImage);
callbackManager = CallbackManager.Factory.create();
final ShareDialog shareDialog = new ShareDialog(this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.d(TAG, "success");
}
#Override
public void onError(FacebookException error) {
Log.d(TAG, "error");
}
#Override
public void onCancel() {
Log.d(TAG, "cancel");
}
});
ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
.setContentTitle("Mijn workout "+sport+" | " +speed+" | "+ distance+" | "+ date+" is gesponsord door "+Company)
.setContentDescription(shareDesc)
.setContentUrl(Uri.parse(mUrl))
.setImageUrl(Uri.parse(sharedImage))
.build();
ShareDialog.show(advertise.this,shareLinkContent);
}
I have searched everywhere and i am unable to find a suiting solution to my problem also i am not really good with listeners.
Thank you.
I have solved as i forgot to init the call back in oncreate.

Categories

Resources