how to implements fabric find fiends
i have successfully implemented uploading contacts and i got uploaded contacts numbers too .but i m unable to implement find friends and that's why i got nothing match contacts (where as i have registered users with application see implementation below)
As i suspect ContactMatch(); never be called
codes
find.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Digits.uploadContacts(CONTACT_UPLOAD_REQUEST);
}
});
return view;
}
private static void ContactMatch() {
// progressDialog.show();
Digits.findFriends(new ContactsCallback<Contacts>() {
#Override
public void success(Result<Contacts> result) {
if (result.data.users != null) {
Log.e("data", result.toString());
}
}
#Override
public void failure(TwitterException exception) {
Log.e("failure", exception.toString());
}
});
}
public static class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (ContactsUploadService.UPLOAD_COMPLETE.equals(intent.getAction())) {
ContactsUploadResult result = intent
.getParcelableExtra(ContactsUploadService.UPLOAD_COMPLETE_EXTRA);
if (result != null) {
}
Log.e("contacts", result.successCount + "");
ContactMatch();
// Post success notification
} else {
// Post failure notification
}
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CONTACT_UPLOAD_REQUEST && resultCode == RESULT_CANCELED) {
}
}
Related
I have the following code. Whenever I press a button, the result is displayed in Display class but sometimes it throws me out from app and sometimes it works properly. I Dont know how?
Can anyone explain why this is happening?
public class MainActivity extends AppCompatActivity {
Context con = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onScanClick(View view) {
initiateScan();
}
private void initiateScan() {
IntentIntegrator integrator = new IntentIntegrator((Activity) con);
integrator.setBeepEnabled(true);
integrator.initiateScan();
}
// Get the results:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
ShowResult.Dispay((Activity) con,result.getContents());
Vibrator.vibrate(250L,con);
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
I am using the ZXING QR Code Reader. It is working fine. Detecting codes etc but it does not shows any detection progress(Like red line) while it is scanning the QR Code. Here is Screenshot
And my ScanActivity is,
ScanCode.Java
public class ScanCode extends Activity implements OnClickListener {
Button btnScan;
TextView scanResult;
String text;
Bitmap bmp;
ImageView ivPic;
#Override
public void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.scan_code);
initViews();
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.btnScanCode) {
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 1);
}
}
private void initViews() {
scanResult = (TextView) findViewById(R.id.scanResult);
ivPic = (ImageView) findViewById(R.id.capturedImg);
btnScan = (Button) findViewById(R.id.btnScanCode);
btnScan.setOnClickListener(this);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
if (resultCode == Activity.RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");
Toast.makeText(getApplicationContext(), contents,
Toast.LENGTH_SHORT).show();
scanResult.setText(contents);
}// if result_ok
}// onActivityResult
}
I know this answer is bit late but I've just used Zxing barcode/QR-Code scanner recently in my app, if anyone has issue implementing it just follow the steps below (Using Android Studio Official IDE for android).
First add dependencies in app --> build.gradle file
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
}
Activity Usage:
public class MainActivity extends AppCompatActivity {
Button btnScan;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnScan = (Button) findViewById(R.id.btnScan);
btnScan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
scanBarcode();
}
});
}
private void scanBarcode()
{
new IntentIntegrator(this).initiateScan();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
}
}
}
If you want to use custom callback and BarCodeView. Zxing provide this functionality simply make layout file
<com.journeyapps.barcodescanner.CompoundBarcodeView
android:id="#+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.journeyapps.barcodescanner.CompoundBarcodeView>
<TextView
android:id="#+id/tvScanResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scan Results will be shown here"
android:textColor="#android:color/white"
android:textStyle="bold"/>
In Activity use the following code
public class MainActivity extends AppCompatActivity
{
CompoundBarcodeView barcodeView;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barcodeView = (CompoundBarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.decodeContinuous(callback);
barcodeView.setStatusText("");
}
#Override
protected void onResume()
{
super.onResume();
barcodeView.resume();
isScanned = false;
}
#Override
protected void onPause()
{
super.onPause();
barcodeView.pause();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
}
private BarcodeCallback callback = new BarcodeCallback()
{
#Override
public void barcodeResult(BarcodeResult result)
{
if (result.getText() != null)
{
barcodeView.setStatusText(result.getText());
tvscanResult.setText("Data found: " + result.getText());
}
//you can also Add preview of scanned barcode
//ImageView imageView = (ImageView) findViewById(R.id.barcodePreview);
//imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
}
#Override
public void possibleResultPoints(List<ResultPoint> resultPoints)
{
System.out.println("Possible Result points = " + resultPoints);
}
};
}
Source zxing-android-embedded. Hope someone get help from this solution
I am writing a log in fragment that hosts Facebook and Google+ sign in. The fragment is a parent fragment for three fragments with user content that are called with view pager after successful log in. I am storing email and service name in shared preferences upon retrieval from Google or Facebook, and then if successful the view pager is displayed with user fragments. Facebook log in works fine but when I start Google+ sign in it does not get to the onConnected callback method. When I switch to other tabs and return to log in fragment it is somehow triggered and I get user fragments. How can i trigger the onConnected method upon pressing the Google+ sign in button?
to ensure the onActivityResult is called i added this in main activity
MainActivity.java
#Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
// TODO Auto-generated method stub
super.onActivityResult(arg0, arg1, arg2);
LoginFragment lf = (LoginFragment)getSupportFragmentManager().findFragmentByTag("Login");
if (lf != null) {
lf.onActivityResult(arg0, arg1, arg2);
}
}
LoginFragment.java
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
// Session class instance
mSession = new SessionManager(getActivity());
setupGoogleplus();
loginButton = (SignInButton) getActivity().findViewById(R.id.sign_in_button);
loginButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!mPlusClient.isConnected()) {
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
mConnectionResult = null;
mPlusClient.connect();
}
}
}
}
});
setupViewPager();
if (mSession.isLoggedIn()) {
onLoged();
}
}
private void setupViewPager() {
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager());
mViewPager = (ViewPager) getActivity().findViewById(R.id.pager);
}
private void setupGoogleplus() {
// google+ part
mPlusClient = new PlusClient.Builder(getSherlockActivity(), new ConnectionCallbacks() {
#Override
public void onConnected(Bundle connectionHint) {
String accountName = mPlusClient.getAccountName();
// new
// DownloadImageTask(userPicture).execute(mPlusClient.getCurrentPerson().getImage().getUrl());
// Toast.makeText(getActivity(), accountName + " is connected.",
// Toast.LENGTH_LONG).show();
mConnectionProgressDialog.dismiss();
mSession.createLoginSession(mPlusClient.getCurrentPerson().getName().getGivenName().toString(), mPlusClient.getAccountName(), "Google+");
}
#Override
public void onDisconnected() {
Log.d(TAG, "disconnected");
}
}, new OnConnectionFailedListener() {
#Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to
// resolve
// connection errors. Wait until onConnected() to dismiss
// the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the result and resolve the connection failure upon a
// user click.
mConnectionResult = result;
}
}).setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").build();
mConnectionProgressDialog = new ProgressDialog(getActivity());
mConnectionProgressDialog.setMessage("Signing in...");
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
// Request user data and show the results
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
if (user != null) {
// Display the parsed user info
// Set the id for the ProfilePictureView
// view that in turn displays the profile picture.
// profilePictureView.setProfileId(user.getId());
// Set the Textview's text to the user's name.
mSession.createLoginSession(user.getName(), user.getProperty("email").toString(), "Facebook");
onLoged();
}
}
}).executeAsync();
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
#Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR) {
mConnectionResult = null;
mPlusClient.connect();
} else {
uiHelper.onActivityResult(requestCode, responseCode, intent);
}
super.onActivityResult(requestCode, responseCode, intent);
}
private static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 0:
return new FirstFragment();
case 1:
return new SecondFragment();
case 2:
return new ThirdFragment();
}
return null;
}
#Override
public int getCount() {
return NUMBER_OF_PAGES;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "1";
case 1:
return "2";
case 2:
return "3";
}
return null;
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login_fragment, container, false);
authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("email"));
return view;
}
#Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
#Override
public void onStart() {
mPlusClient.connect();
super.onStart();
}
#Override
public void onStop() {
super.onStop();
mPlusClient.disconnect();
}
public void googleLogout() {
if (mPlusClient.isConnected()) {
mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();
mPlusClient.connect();
mSession.logoutUser();
}
}
public void onLoged() {
mViewPager.setAdapter(mMyFragmentPagerAdapter);
mViewPager.setVisibility(View.VISIBLE);
authButton.setVisibility(View.INVISIBLE);
loginButton.setVisibility(View.INVISIBLE);
}
public void onNotLoged() {
mViewPager.setAdapter(null);
mViewPager.setVisibility(View.INVISIBLE);
authButton.setVisibility(View.VISIBLE);
loginButton.setVisibility(View.VISIBLE);
}}
In onConnected method I call mySession object creation (shared preferences) to store the data and onLoged to display user fragments. Why do I have to switch tabs a few times for onConnected to be called?
Because the resolution for the connection failure was started with startIntentSenderForResult and the code REQUEST_CODE_RESOLVE_ERR, you need to capture the result inside Activity.onActivityResult.
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
So in your case you should call mPlusClient.connect(); in LoginFragment onActivityResult after all needed checks.
I have implemented Inapp Billing in my app. For that i have used buttons. when i click button it goes to the purchase activity and it purchases the product. once it purchases the product the button will be invisible. and the other button will be visible which will allow the user to open the product. It is all happening perfectly.But when i reopen the app again the button for purchase is visible . i do not want the button to be visible once it is purchased. how to make the button invisible once it is used for successful purchase.
StartUpActivity.java
public class StartUpActivity extends PurchaseActivity implements OnIabSetupFinishedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("App started");
}
#Override
public void onIabSetupFinished(IabResult result) {
if (result.isSuccess()) {
Log.d("In-app Billing set up" + result);
dealWithIabSetupSuccess();
} else {
Log.d("Problem setting up In-app Billing: " + result);
dealWithIabSetupFailure();
}
}
#Override
protected void dealWithIabSetupSuccess() {
navigate().toMainActivity();
finish();
}
#Override
protected void dealWithIabSetupFailure() {
popBurntToast("Sorry In App Billing isn't available on your device");
}
}
MainActivity.java
public class MainActivity extends BlundellActivity implements MainMenu {
public Button topicsbutton;
public Button mediabutton;
public Button purchasetopicsbutton;
public Button purchasemediabutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
topicsbutton = (Button) findViewById(R.id.button1a);
mediabutton = (Button) findViewById(R.id.button2a);
purchasetopicsbutton = (Button) findViewById(R.id.button1);
purchasemediabutton = (Button) findViewById(R.id.button2);
}
#Override
public void onTopicsPurchaseItemClick(View v) {
navigate().toPurchaseTopicsActivityForResult();
}
#Override
public void onMediaPurchaseItemClick(View v) {
navigate().toPurchaseMediaActivityForResult();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (Navigator.REQUEST_TOPICS_PURCHASE == requestCode) {
if (RESULT_OK == resultCode) {
dealWithSuccessfulTopicsPurchase();
} else {
dealWithFailedTopicsPurchase();
}
} else if (Navigator.REQUEST_MEDIA_PURCHASE == requestCode) {
if (RESULT_OK == resultCode) {
dealWithSuccessfulMediaPurchase();
} else {
dealWithFailedMediaPurchase();
}
}
}
public void dealWithSuccessfulTopicsPurchase() {
Log.d("Topics purchased");
popToast("Topics purchased");
topicsbutton.setVisibility(View.VISIBLE);
purchasetopicsbutton.setVisibility(View.INVISIBLE);
}
private void dealWithSuccessfulMediaPurchase() {
Log.d("Media purchased");
popToast("Media purchased");
mediabutton.setVisibility(View.VISIBLE);
purchasemediabutton.setVisibility(View.INVISIBLE);
}
private void dealWithFailedTopicsPurchase() {
Log.d("Topics purchase failed");
popToast("Failed to purchase Topics");
}
private void dealWithFailedMediaPurchase() {
Log.d("Media purchase failed");
popToast("Failed to purchase Media");
}
public void TopicsOpen(View v) {
navigate().toTopicsopen();
}
public void MediaOpen(View v) {
navigate().toMediaopen();
}
}
PurchaseActivity.java
public abstract class PurchaseActivity extends BlundellActivity implements OnIabSetupFinishedListener, OnIabPurchaseFinishedListener {
private IabHelper billingHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_purchase);
setResult(RESULT_CANCELED);
billingHelper = new IabHelper(this, AppProperties.BASE_64_KEY);
billingHelper.startSetup(this);
}
#Override
public void onIabSetupFinished(IabResult result) {
if (result.isSuccess()) {
Log.d("In-app Billing set up" + result);
dealWithIabSetupSuccess();
} else {
Log.d("Problem setting up In-app Billing: " + result);
dealWithIabSetupFailure();
}
}
protected abstract void dealWithIabSetupSuccess();
protected abstract void dealWithIabSetupFailure();
protected void purchaseItem(String sku) {
billingHelper.launchPurchaseFlow(this, sku, 123, this);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
billingHelper.handleActivityResult(requestCode, resultCode, data);
}
#Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isFailure()) {
dealWithPurchaseFailed(result);
} else if (Items.SKU1.equals(info.getSku())) {
dealWithTopicsPurchaseSuccess(result, info);
}
else if (Items.SKU2.equals(info.getSku())) {
dealWithMediaPurchaseSuccess(result, info);
}
finish();
}
protected void dealWithPurchaseFailed(IabResult result) {
Log.d("Error purchasing: " + result);
}
protected void dealWithTopicsPurchaseSuccess(IabResult result, Purchase info) {
Log.d("Item purchased: " + result);
}
protected void dealWithMediaPurchaseSuccess(IabResult result, Purchase info) {
Log.d("Item purchased: " + result);
billingHelper.consumeAsync(info, null);
}
#Override
protected void onDestroy() {
disposeBillingHelper();
super.onDestroy();
}
private void disposeBillingHelper() {
if (billingHelper != null) {
billingHelper.dispose();
}
billingHelper = null;
}
}
If you are using the API version 3 you can call getPurchases() method at the onCreate().
This method returns the current un-consumed products owned by the user.
That means if your product is un-consumable, i.e, user will only buy it once then you will have your necessary info right here.
Can't explain how to do it better than in official documentation. Take a look at the Querying for Purchased Items topic to have a code example.
Basically you will receive a list of ownedSkus (owned product ID's) and all you have to do is a loop over this list and make your buttons invisible/ visible.
Let me know if this what you was looking for :)
i am using following codes.
addNewReceipt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), AddReceipt.class);
myIntent.putExtra("receiptList", receipts);
startActivityForResult(myIntent, RECEIPT_ADD);
}
});
}
#SuppressWarnings("unchecked")
public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data)
{
if (resultCode == Activity.RESULT_OK)
{
if (requestCode == RECEIPT_ADD)
{
receipts = (ArrayList<Receipt>) data.getSerializableExtra("receiptList");
addReceiptsInListView();
}
}
}
The code for AddReceipt class is as follow,
#Override
public void finish() {
Intent data = new Intent();
data.putExtra("receiptList", receipts);
setResult(RESULT_OK, data);
super.finish();
}
#SuppressWarnings("unchecked")
public void onCreateCall()
{
done.setOnClickListener(new OnClickListener()
{ //receiptAddBtn
#Override
public void onClick(View v)
{
String error = "";
Receipt receipt = new Receipt();
receipt.comments = comments.getText().toString();
receipt.referenceNo = receiptNo.getText().toString();
receipt.image = imageSelected;
if (receipt.image == null || receipt.referenceNo == "" )
{
error = "Please input Receipt No. and attach Image";
displayAlert(error);
}
else
{
receipts.add(receiptCounter,receipt);
finish();
}
}
});
}
The problem is, when the activity is finished... and i pass this receipt, in my previous class from which i call this activity public synchronized void onActivityResult Never works.
The back button is not ending activity either.
Please tell me where i am wrong,.
Best Regards
Here is the solution to your problem
#Override
public void finish() {
Intent data = new Intent();
data.putExtra("receiptList", receipts);
setResult(Activity.RESULT_OK, data);
super.finish();
}