Authenticate using Box Android SDK v2 - android

I want to authenticate using the Box SDK.
I got the Box Java SDK V2 and the Box Android SDK V2.
And I'm using the basic authentication code from the Box Android SDK
Intent intent = OAuthActivity.createOAuthActivityIntent(this, clientId,
clientSecret);
startActivityForResult(intent);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_CANCELED) {
// Get the error message for why authentication failed.
String failMessage = data.getStringExtra(OAuthActivity.ERROR_MESSAGE);
// Implement your own logic to handle the error.
handleFail(failMessage);
} else {
// You will get an authenticated BoxClient object back upon success.
BoxClient client =
data.getParcelableExtra(OAuthActivity.BOX_CLIENT);
youOwnMethod(client);
}
}
but I'm getting this error:
The method createOAuthActivityIntent(Context, String, String) from the type OAuthActivity refers to the missing type Intent
It's probably something stupid I'm doing wrong, but can someone tell me what?

It seems Intent class cannot be found? This is an android class. Are you working on an android project or a regular java project? Do you see any compile error?

Related

Open Android Activity and iOS ViewController from Flutter

I have a Flutter project that requires some certain features that needs to be implemented in native Android Activity or iOS ViewController. is there a way to navigate to android Activity and pass data to it and also retrieve data from it in Flutter?
and if it's impossible, is it possible to show an Activity or fragment from Android, and a ViewController from iOS, as a Widget in Flutter?
Not sure whether this is the best way and I only created it for Android, but this is what I did.
Simple Flutter method channel calling native:
static const platform = const MethodChannel(MY_CHANNEL);
string result await platform.invokeMethod("mycall");
From the native Android part in your mainActivity:
//Class attribute
private Result myresult;
//Method chanel
new MethodChannel(getFlutterView(), MY_CHANNEL).setMethodCallHandler(
(call, result) -> {
// Note: this method is invoked on the main thread.
if (call.method.equals("mycall")) {
myresult = result; //Store the flutter result
Intent intent1 = new Intent(MyClass.class);//Start your special native stuff
startActivityForResult(intent1, RQ_CODE);
} else {
result.notImplemented();
}
});
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check which request we're responding to
if (requestCode == RQ_CODE) {
myresult.success("this will be your result"); //Probably do something with the data instead of a static string.
}
}
Basically the same can be done for iOS
use intent or android_intent packages for android and for ios use https://flutter.dev/docs/get-started/flutter-for/ios-devs link

Braintree Android SDK Drop-in UI not displayed

I am trying to display the Drop-in UI in my app upon clicking a specific button. I have used the guide from Braintree site but for some reason nothing is happening.
Code below:
OnClick function:
public void onClick(View v){
switch (v.getId()){
case R.id.showUI_button:
onBraintreeSubmit(v);
break;
}
}
Drop-in functions:
public void onBraintreeSubmit(View v) {
PaymentRequest paymentRequest = new PaymentRequest()
.clientToken(token)
.amount("$10.00")
.primaryDescription("Awesome payment")
.secondaryDescription("Using the Client SDK")
.submitButtonText("Pay");
startActivityForResult(paymentRequest.getIntent(this), REQUEST_CODE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (resultCode == BraintreePaymentActivity.RESULT_OK) {
PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
);
String nonce = paymentMethodNonce.getNonce();
// Send the nonce to your server.
}
}
}
I have checked that the token is returned from the server.
I have also tried by setting the onClick via the xml code of the button and removing the onClick from the java file but the result is the same, no UI shown.
The log has only two lines
performCreate Call Injection Manager
Timeline: Activity_idle id:android.os.BinderProxy#etc
Any ideas? If more info is needed to understand better let me know
Actually I found this there is a "BraintreeFragment" set up part. Braintree documentation needs to be more clear on this I think.
https://developers.braintreepayments.com/guides/client-sdk/setup/android/v2
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
// mBraintreeFragment is ready to use!
} catch (InvalidArgumentException e) {
// There was an issue with your authorization string.
}
}
The above code should work along with the previous code posted. mAuthorization is the token and needs to be valid to show the payment screen (so the variable "token" in the previous code posted which in my code I just have as private but visible from the whole activity).
Try with the test token that they have on their page and if this works then the main setup is ok.
https://developers.braintreepayments.com/start/hello-client/android/v2
For setting up tokens on your server, they have further documentation so that those test tokens work on the sandbox.

How to Retrieve product id from bar code?

I have used the same way of Zxing Intent to open scanner from my application. But my application just opens scanner and does nothing. Also, I am getting some FileNotfoundException.
Do I have to add any permission in manifest?
This is my class where I use Intent:
public class BarCodes extends Activity {
/** Called when the activity is first created. */
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
System.out.println("SSSSSSSSSSSSS");
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Also LogCat is here:
java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System Loader…
What might be the problem??
This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.
Your error is nothing to do with the project. Android is saying it is unable to find your class, com.pkg.Scan. You'll have to fix your project setup.
However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.
Steps:
Install Apache Ant (http://www.youtube.com/watch?v=XJmndRfb1TU , this video will help you to do that) and also refer http://ant.apache.org/ for more info and download ant
Download the ZXing source from ZXing homepage and extract it (For More info :http://code.google.com/p/zxing/source/browse/trunk/android/)
With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
Type 'ant -f core/build.xml' or 'ant -f android/build.xml'
Enter Eclipse -> new Android Project
Right-click project folder -> Properties -> Java Build Path -> Library -> Add External JARs
If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code in this way
It will have the product code Stored in the String value 'contents'
Have fun with BarCode by implementing it in your own way :-)

Basic ZXING library application

I am trying to produce
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Using the libraries therefore not needing to install the software, I have had a look at the application that comes with it, and added CaptureActivity.java to my project to see if I can locate the core scanning loop but it kept just requiring more and more files (ended up with about 28 in total) and after I had no errors it still didn't work.
I am not looking into doing anything fancy, just on a button click open the capture layout, scan a code, return the code.
There are a few examples on how to decode local files but not the actual scanning side of it to detect a actual barcode.
So, what I help with is embedding the scanning code
Thanks
I think you're mixing up two things. The code you have shows you are trying to integrate via Intent, in which case you do not need any project code in your application at all.
The source in android/ is a complete stand-alone app (Barcode Scanner) and it is not written for you to copy (although the Apache License permits it). What you are doing is not supported, recommended, or encouraged -- integrating via Intent is much easier.
Write your own app, perhaps looking to the Android source code for inspiration, and that uses the core/ library for scanning. The core scanning happens in DecodeThread.

Androids Facebook SDK, single sign on question?

On Androids Facebook SDK there is a single login feature which I can't get to work.
Done all the key hash thing but maybe there is something wrong with this method.
What exactly should I pass on, or could somebody explain what this is supposed to do?
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
facebook.authorizeCallback(requestCode, resultCode, data);
}
Facebook Single Sign On works fine, but the documentation is not all that great. Get your class to override the Facebook DialogListener.
To request Single Sign On, make sure you're calling Facebook to authorize your app -
facebookClient = new Facebook(FB_APP_ID);
facebookClient.authorize(this,
new String[] {"publish_stream", "read_stream", "offline_access"}, this);
And you also need to override the OnComplete method. Your OnActivityResult method is absolutely fine.
I used the code given by this gentleman here, and it worked perfectly fine for me, except that some of the code that he'd written was using the old API, so you might need to change some parameters passed to methods.
I don't think single sign on could work well in the Facebook Android SDK.
In the method private boolean startSingleSignOn(Activity activity, String applicationId,String[] permissions, int activityCode){} ,you will see below
Intent intent = new Intent();
intent.setClassName("com.facebook.katana",
"com.facebook.katana.ProxyAuth");
try {
activity.startActivityForResult(intent, activityCode);
} catch (ActivityNotFoundException e) {
didSucceed = false;
}
In fact, package com.facebook.katana doesn't exist in the Facebook Android SDK.so the method private boolean startSingleSignOn(Activity activity, String applicationId,
String[] permissions, int activityCode){} will return false ,then it means that single sign-on is Not available.
facebookClient.authorize
This method doesn't work on my device until I renamed those parameters:
"com.facebook.katana","com.facebook.katana.ProxyAuth"
to
"com.facebook.katana1","com.facebook.katana.ProxyAuth1"
=(

Categories

Resources