I have added a simple non drop-in paypal integration in sandbox mode to my app. Here is a test activity with a single "Pay" button:
public class PaypalPaymentAcivity extends Activity implements PaymentMethodNonceCreatedListener {
private BraintreeFragment mBraintreeFragment;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paypal);
findViewById(R.id.payButton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startPayment();
}
});
}
private void startPayment() {
try {
mBraintreeFragment = BraintreeFragment.newInstance(this, "...");
PayPalRequest request = new PayPalRequest("1")
.currencyCode("USD")
.intent(PayPalRequest.INTENT_AUTHORIZE);
PayPal.requestOneTimePayment(mBraintreeFragment, request);
} catch (InvalidArgumentException e) {
e.printStackTrace();
}
}
#Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
}
}
However once the PayPal browser window comes up after clicking the buttons it just keeps popping up over and over, and never returns to my activity.
Anyone had a successful integration like this?
Related
I hope you can help me, I am starting with UnityAds, I have an application on Android Studio (Java) where the SplashActivity has a button.
What I want is that, after pressing the button, the UnityAds interstitial is shown and when the ad ends, the MainActivity is shown.
The code I made shows the interstitial after the button but I don't know how to make it open the next activity to the MainActivity because after the interstitial it returns to the SplashActivity
public class SplashActivity extends AppCompatActivity {
String GameID = "123456";
String adUnitId = "Interstitial";
Boolean TestMode = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro_uno);
//iniciador Unity
UnityAds.initialize(SplashActivity.this, GameID, TestMode, new IUnityAdsInitializationListener() {
#Override
public void onInitializationComplete() {
}
#Override
public void onInitializationFailed(UnityAds.UnityAdsInitializationError unityAdsInitializationError, String s) {
}
});
//iniciador Unity
}
public void onClick(View view) {
IUnityAdsShowListener iUnityAdsShowListener = new IUnityAdsShowListener() {
#Override
public void onUnityAdsShowFailure(String s, UnityAds.UnityAdsShowError unityAdsShowError, String s1) {
}
#Override
public void onUnityAdsShowStart(String s) {
UnityAds.load(adUnitId);
UnityAds.show(SplashActivity.this,adUnitId);
}
#Override
public void onUnityAdsShowClick(String s) {
}
#Override
public void onUnityAdsShowComplete(String s, UnityAds.UnityAdsShowCompletionState unityAdsShowCompletionState) {
}
};
UnityAds.load(adUnitId);
UnityAds.show(SplashActivity.this,adUnitId);
}
}
Just add
startActivity(new Intent(MainActivity.this,MainActivity2.class));
In onUnityAdsShowComplete method
---In this above line MainActivity is the Current Activity and MainActivity2 is the second Activity
I am trying to implement truecaller in my app and i am doing exactly written in Truecaller Docs.
But still it gives me error.
I have tried googling the problem but still couldn't find the solution.
Here is the error:
No compatible client available. Please change your scope
Here is my code:
public class MainActivity extends FragmentActivity implements ITrueCallback {
private ViewPager2 viewPager2;
private List < Integer > imagesList;
private Button btnContinue, btnLoginTruecaller;
private EditText etPhone;
private Preferences preferences;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Constants.removeStatusBar(this);
TruecallerSdkScope trueScope = new TruecallerSdkScope.Builder(this, sdkCallback)
.consentMode(TruecallerSdkScope.CONSENT_MODE_BOTTOMSHEET)
.buttonColor(Color.parseColor("#000000"))
.buttonTextColor(Color.parseColor("#000000"))
.loginTextPrefix(TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_GET_STARTED)
.loginTextSuffix(TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_VERIFY_MOBILE_NO)
.ctaTextPrefix(TruecallerSdkScope.CTA_TEXT_PREFIX_USE)
.buttonShapeOptions(TruecallerSdkScope.BUTTON_SHAPE_ROUNDED)
.privacyPolicyUrl("<<YOUR_PRIVACY_POLICY_LINK>>")
.termsOfServiceUrl("<<YOUR_PRIVACY_POLICY_LINK>>")
.footerType(TruecallerSdkScope.FOOTER_TYPE_NONE)
.consentTitleOption(TruecallerSdkScope.SDK_CONSENT_TITLE_LOG_IN)
.sdkOptions(TruecallerSdkScope.SDK_OPTION_WITHOUT_OTP)
.build();
TruecallerSDK.init(trueScope);
btnContinue = findViewById(R.id.btnContinue);
etPhone = findViewById(R.id.etPhone);
btnLoginTruecaller = findViewById(R.id.btnLoginTruecaller);
TruecallerSDK.getInstance().getUserProfile(this);
btnLoginTruecaller.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {}
});
preferences = new Preferences(this);
if (preferences.isLoggedin()) {
Intent intent = new Intent(this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
imagesList = new ArrayList < > ();
imagesList.add(R.drawable.black);
imagesList.add(R.drawable.pubg);
// ViewPagerAdapter adapter = new ViewPagerAdapter(this,imagesList);
// viewPager2.setAdapter(adapter);
btnContinue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
preferences.setMobileNumber(etPhone.getText().toString());
Intent intent = new Intent(MainActivity.this, OTPActivity.class);
intent.putExtra("phone", etPhone.getText().toString());
startActivity(intent);
}
});
}
private final ITrueCallback sdkCallback = new ITrueCallback() {
#Override
public void onSuccessProfileShared(#NonNull TrueProfile trueProfile) {
}
#Override
public void onFailureProfileShared(#NonNull TrueError trueError) {
}
#Override
public void onVerificationRequired(TrueError trueError) {
}
};
#Override
public void onSuccessProfileShared(#NonNull TrueProfile trueProfile) {
}
#Override
public void onFailureProfileShared(#NonNull TrueError trueError) {
}
#Override
public void onVerificationRequired(TrueError trueError) {
}
}
Here is the truecaller docs i am following:
https://docs.truecaller.com/truecaller-sdk/android/integrating-with-your-app/setup
Thanks for sharing the above information.
The exception that you are facing :
No compatible client available. Please change your scope
comes only in the case where you are calling a method from TruecallerSDK that is not in the scope which you provide while initialising the SDK.
For instance, in case where Truecaller app is not installed or Truecaller app is installed but not logged and you have mentioned the sdkOptions as TruecallerSdkScope.SDK_OPTION_WIHTOUT_OTP then on calling TruecallerSDK.getInstance().getUserProfile() method you will face this exception.
To refrain from facing this again you can put a check that if TruecallerSDK.getInstance.isUsable turns out to be True, then only call TruecallerSDK.getInstance.getUserProfile or you can change the sdkOptions scope to TruecallerSdkScope.SDK_OPTION_WITH_OTP to verify both Truecaller and Non-Truecaller users
In case if you face any queries in the future, please feel free to reach us via our support channel https://developer.truecaller.com/support for a faster and dedicated response.
Regard,
Parth
I would like to pass FCM token in the start url. My code doesnt work everytime, i think needs a delay but i cant handle it.
Below code doesnt work every time because sometimes the TWA launches before the firebase connection has been made:
public class LauncherActivity
extends com.google.androidbrowserhelper.trusted.LauncherActivity {
public static String x = null;
#override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//RegisterToTopic for FCM
FirebaseMessaging.getInstance().subscribeToTopic("all");
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener() {
#override
public void onComplete(#nonnull Task task) {
// Get new FCM registration token
x = task.getResult();
}
});
}
#Override
protected Uri getLaunchingUrl() {
// Get the original launch Url.
Uri uri = super.getLaunchingUrl();
// Append the extra parameter to the launch Url
return uri
.buildUpon()
.appendQueryParameter("z", String.valueOf(x))
.build();
}
}
I have also tried this but the same result:
public class StartActivity extends AppCompatActivity {
final long SPLASH_DELAY = 4000;
public static String x = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
runMainApp();
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
#Override
public void onComplete(#NonNull Task<String> task) {
// Get new FCM registration token
x = task.getResult();
Intent intent = new Intent(getBaseContext(), CustomLauncherActivity.class);
intent.putExtra("EXTRA_SESSION_ID", x);
startActivity(intent);
}
});
}
private void runMainApp() {
new Handler().postDelayed(() -> {
startActivity(new Intent(SplashActivity.this, CustomLauncherActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
finish();
overridePendingTransition(R.anim.anim_right_in, R.anim.anim_left_out);
}, SPLASH_DELAY);
}
}
I have received an answer from android-browser-helper repo but i cant handel it. If someone could provide more help would be much appreciated.
public class MyLauncherActivity extends LauncherActivity {
private static class DelayedTwaLauncher extends TwaLauncher {
#Override
public void launch(TrustedWebActivityIntentBuilder twaBuilder,
CustomTabsCallback customTabsCallback,
#Nullable SplashScreenStrategy splashScreenStrategy,
#Nullable Runnable completionCallback,
FallbackStrategy fallbackStrategy) {
if (firebase has finished loading) {
super.launch(twaBuilder, customTabsCallback, splashScreenStrategy, fallbackStrategy);
} else {
// Save the parameters to some variables.
// Don't do anything else.
}
}
public void actuallyLaunch() {
if (we didn't call super.launch before) {
super.launch(the parameters you saved before);
}
}
#Override
protected TwaLauncher createTwaLauncher() {
return delayedTwaLauncher;
}
}
Starting with android-browser-helper] v2.2.0, it's possible to run asynchronous code before in the LauncherActivity before launching the Trusted Web Activity.
This is how a custom LauncherActivity for Firebase Analytics looks like:
public class FirebaseAnalyticsLauncherActivity extends LauncherActivity {
private String mAppInstanceId;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);
// Start the asynchronous task to get the Firebase application instance id.
firebaseAnalytics.getAppInstanceId().addOnCompleteListener(task -> {
// Once the task is complete, save the instance id so it can be used by
// getLaunchingUrl().
mAppInstanceId = task.getResult();
launchTwa();
});
}
#Override
protected boolean shouldLaunchImmediately() {
// launchImmediately() returns `false` so we can wait until Firebase Analytics is ready
// and then launch the Trusted Web Activity with `launch()`.
return false;
}
#Override
protected Uri getLaunchingUrl() {
Uri uri = super.getLaunchingUrl();
// Attach the Firebase instance Id to the launchUrl. This example uses "appInstanceId" as
// the parameter name.
return uri.buildUpon()
.appendQueryParameter("appInstanceId", mAppInstanceId)
.build();
}
}
Check out the full Firebase Analytics demo here.
i am trying to create group chat android application and used Websocket server written in php. this server work fine on Web browser but when i try to use it in android application application disconnect as soon as it connects.
here Android code:
public class MainActivty extends Activity{
private WebSocketClient mWebSocketClient;
private ListView mMessageListView;
private ArrayAdapter<String> mAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_layout);
mMessageListView=(ListView)findViewById(R.id.listView);
mAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
mMessageListView.setAdapter(mAdapter);
connectWebSocket();
}
private void connectWebSocket(){
URI uri;
try {
uri=new URI("ws://192.168.0.102:9000");
mWebSocketClient=new WebSocketClient(uri){
#Override
public void onOpen(ServerHandshake serverHandshake) {
}
#Override
public void onMessage(String s) {
}
#Override
public void onClose(int i, String s, boolean b) {
}
#Override
public void onError(Exception e) {
}
};
mWebSocketClient.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
return;
}
}
private void Append_Message(String log){
mAdapter.add(log);
mAdapter.notifyDataSetChanged();
}
}
server console:
server console shows client activity
when i rewrite this code using https://github.com/pavelbucek/tyrus-client-android-test i think i could not satisfied full requirement of previous library that i used. but tutorial on this link have solved my problem.
I am using the library scringo on Android. "openChat" function doesn't seem to be working. It does absolutely nothing. Here is my code.
I read through their API:
http://www.scringo.com/docs/api/android/
openChat function should open the 1-on-1 chat with the other user. But that doesnt happen. Nothing happens. All the other functions are working fine.
It doesn't even log any errors or warning.
public class MainActivity extends Activity implements OnClickListener {
private Scringo scringo;
private Activity mainactivity;
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainactivity = this;
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
Scringo.setAppId("MY-APP-ID");
Scringo.setDebugMode(true);
scringo = new Scringo(this);
scringo.init();
scringo.addSidebar();
Scringo.loginWithEmail("a#testapp.com", "hi", new ScringoSignUpListener(){
#Override
public void onError(String arg0) {
}
#Override
public void onSuccess(String arg0) {
Log.w("user",Scringo.getUserId());
}
});
}
#Override
public void onClick(View arg0) {
//I am using the ID of another user.
//This does not work. Nothing happens. No error or warning either.
Scringo.openChat(this, "Qk8vJs4fRE");
//This works fine.
//Scringo.openChatRooms(this);
}
}
You should call the openChat after getting the user:
Scringo.getUserByScringoId("SOME_ID...", new ScringoGetUserListener() {
#Override
public void gotUser(ScringoUser user) {
Scringo.openChat(MainActivity.this, "SOME_ID...");
}
});