How to integrate app Invites for Android with Facebook? - android

I'm quite new to Android and I don't quite understand importing classes so please point me in the right direction. I've added the Facebook SDK to my project via Gradle.
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
In my Java class, I have the following imports:
import com.facebook.FacebookSdk;
import com.facebook.appevents.*;
When I add the following code from this link:
String appLinkUrl, previewImageUrl;
appLinkUrl = "https://www.example.com/myapplink";
previewImageUrl = "https://www.example.com/my_invite_image.jpg";
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog.show(this, content);
}
The app throws the following errors:
Error: cannot find symbol variable AppInviteDialog
Error: cannot find symbol variable AppInviteContent
What do I need to import/modify for this to work correctly?

you also need following imports....in general IDEs like Android Studio will give you option to add these imports
import com.facebook.share.model.AppInviteContent;
import com.facebook.share.widget.AppInviteDialog;

If you have already the 2 imports and it won't work, try adding this in your build.gradle of your app:
compile 'com.facebook.android:facebook-android-sdk:4.23.0'

Related

Error: cannot find symbol import com.google.android.gms.ads.InterstitialAd

I had added google AdMob to the project and found this error :
error: cannot find symbol
import com.google.android.gms.ads.InterstitialAd;
^
symbol: class InterstitialAd
location: package com.google.android.gms.ads
I found the answer :
add this codes to build.gradle(app)
(in the android tag )
configurations.all {
resolutionStrategy {
force "com.google.android.gms:play-services-basement:17.0.0"
force "com.google.android.gms:play-services-base:17.1.0"
force "com.google.android.gms:play-services-stats:17.0.0"
force "com.google.android.gms:play-services-gcm:17.0.0"
force "com.google.android.gms:play-services-ads:19.7.0"
}
}
and if you had use of admob in the one library add codes above to library gradle too
If you get this error after updating your com.google.android.gms:play-services-ads dependency to a more recent version, know that importing com.google.android.gms.ads.InterstitialAd has been deprecated since version 19.7.0 and has since been totally removed.
The new import should be:
import com.google.android.gms.ads.interstitial.InterstitialAd;
Either revert com.google.android.gms:play-services-ads to a version pre-19.7.0 or update your code by following the documentation here: https://developers.google.com/admob/android/interstitial.

error: cannot find symbol AppLinks.getTargetUrlFromInboundIntent in com.facebook.android:facebook-android-sdk:11.3.0

While upgrading the facebook SDK from a lowest version(7.1.0) to latest version (11.3.0) got symbol: method getTargetUrlFromInboundIntent(ItemViewActivity,Intent) location: class AppLinks
I have got
error: package bolts does not exist import bolts.AppLinks;
So I have modified and fixed the import error
import bolts.AppLinks; to import com.facebook.bolts.AppLinks;
Now I am getting below error
error: cannot find symbol
AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
^
symbol: method getTargetUrlFromInboundIntent(ItemViewActivity,Intent)
location: class AppLinks
Code:
Uri applinktUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
It seems that bolts has been removed from within facebook SDK in version 9.0.0 although it's not mentioned in the release notes
https://github.com/facebook/facebook-android-sdk/blob/main/CHANGELOG.md
You could use the dependency directly from it's opensource project
https://github.com/BoltsFramework/Bolts-Android
this would be to add
implementation 'com.parse.bolts:bolts-applinks:1.4.0'
and keep your old import line
import bolts.AppLinks
Having said this, I don't know how and if Applinks is used anymore within Facebook

How to use react-native-batch-push on android? RNBatch is undefined when trying to access RNBatch.NOTIFICATION_TYPES

I'm trying to use this package in my react native project.
So far I've followed all the steps in their installation guide and I made it work on iOS.
However, on Android, every time I try to import Batch or BatchPush in my code like this:
import { BatchPush, Batch } from "#bam.tech/react-native-batch";
I get an error on Android only:
null is not an object (evaluating 'RNBatch.NOTIFICATION_TYPES')
So when I go to node_modules/#bam.tech/react-native-batch/dist/BatchPush.js I see this
const RNBatch = react_native_1.NativeModules.RNBatch;
exports.AndroidNotificationTypes = RNBatch.NOTIFICATION_TYPES;
So somehow the native module is not being imported correctly. Do I need to follow extra steps for this to work?
#bam.tech/react-native-batch is being used with version 5.2.1
npm version 6.14.7
react-native version 0.60.5
Update: it turns out that the package was not linked correctly and that I had to manually add the package in MainApplication.java (I don't know why react-native link did not add this automatically)
Add the import:
import tech.bam.RNBatchPush.RNBatchPackage;
And then add
new RNBatchPackage(), in the getPackages() method.

Getting error when building RN

I am trying to upload image to firebase storage with react native. I fail in very beginning. I am near the end of my game project and this is only part that is missing.
I have added
new ImagePickerPackage(),
new RNFetchBlobPackage()
and also
import com.imagepicker.ImagePickerPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
to MainApplication.java
Every time I run react-native run-android then I get this message:
C:\Users\Hai\Desktop\projectHQ2\HaalariQuiz\android\app\src\main\java\com\manager\MainApplication.java:7:
error: package com.imagepicker does not exist import
com.imagepicker.ImagePickerPackage;
^ C:\Users\Hai\Desktop\projectHQ2\HaalariQuiz\android\app\src\main\java\com\manager\MainApplication.java:8:
error: package com.RNFetchBlob does not exist import
com.RNFetchBlob.RNFetchBlobPackage;
^ C:\Users\Hai\Desktop\projectHQ2\HaalariQuiz\android\app\src\main\java\com\manager\MainApplication.java:30:
error: cannot find symbol
new ImagePickerPackage(),
^ symbol: class ImagePickerPackage
C:\Users\Hai\Desktop\projectHQ2\HaalariQuiz\android\app\src\main\java\com\manager\MainApplication.java:31:
error: cannot find symbol
new RNFetchBlobPackage()
I just cannot understand the error or what I am doing wrong.
Besides adding the dependencies to MainApplication.java, you also need to add to build.gradle and settings.gradle.
Follow https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package to link the package for android.
Follow https://github.com/react-community/react-native-image-picker/blob/develop/README.md#install for image picker

android.annotation cannot be resolved IntDef and NonNull

I'm trying to run a sample android code in Andriod Studio, but when I try:
import android.annotation.IntDef;
import android.annotation.NonNull;
keep getting an error related to this line like:
the import android.annotation cannot be resolved
Any suggestion will be appreciated
I think it would be better if you work with the support annotations:
add this dependency to your project and see if it works:
compile 'com.android.support:support-annotations:24.2.0'
accourding to this answer you can use
android-sdk/tools/support/annotations.jar - Which includes the following annotations:
SuppressLint
TargetApi
android-sdk/extras/android/support/annotations/annotations.jar - Which includes many other annotations:
AnimRes
AnimatorRes
AnyRes
ArrayRes
AttrRes
BoolRes
ColorRes
DimenRes
DrawableRes
FractionRes
IdRes
IntDef
IntegerRes
InterpolatorRes
LayoutRes
MenuRes
NonNull
Nullable
PluralsRes
RawRes
StringDef
StringRes
StyleRes
StyleableRes
XmlRes
I had faced the same problem and came across this question but was not answered.
I could resolve this issue by following steps mentioned here.
After this, You shall sync the project with Gradle files.
Note: You may not find the same annotation path
e.g. import android.annotation.NonNull; --> import androidx.annotation.Nullable;

Categories

Resources