Hi I'm trying to download the image which I have upload in the Custom Object from the dashboard.uid is the id I'm getting on fetching that custom Object
QBContent.downloadFile(uid, new QBEntityCallbackImpl<InputStream>(){
#Override
public void onSuccess(InputStream inputStream, Bundle params) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
if (bitmap != null) {
bankImage.setImageBitmap(bitmap);
}else {
bankImage.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.blue));
}
}
#Override
public void onError(List<String> errors) {
for (String error: errors){
Log.d(TAG , "--errors-"+error);
}
}
}, new QBProgressCallback() {
#Override
public void onProgressUpdate(int progress) {
}
});
Getting this error:
Entity you are looking for was not found
Any Help is highly Appreciated.
I was trying to fetch From Content rather that from Custom where I have uploaded the image.
Here's the code if any-one land up here:
QBCustomObject qbCustomObject = new QBCustomObject("Your_Class_Name", "Custom_Object_Id");
QBCustomObjectsFiles.downloadFile(qbCustomObject, "YOUR_FIELD_TO_FETCH", new QBEntityCallbackImpl<InputStream>() {
#Override
public void onSuccess() {
super.onSuccess();
}
#Override
public void onSuccess(final InputStream result, Bundle params) {
super.onSuccess(result, params);
Log.d(TAG, "successFull--bitmap");
}
#Override
public void onError(List<String> errors) {
super.onError(errors);
}
}, new QBProgressCallback() {
#Override
public void onProgressUpdate(int i) {
}
});
Bingo that's it :-)
Related
I am building an app that should connect at least 4 devices using nearby connection api. I am able to connect them intermittently, other wise only two devices are getting connected.
I am using P2P-CLUSTER Topology and sending data as file payloads which are successfully sent.
I have two questions:
Any suggestion on how to have a stable connection among 2+ devices.
While sending data as file payloads, a folder is created in the download folder. Is there any way to discard this step and be able to send data directly as file payloads without having to save them locally.
Here is my code regarding the connection part only.
private final EndpointDiscoveryCallback endpointDiscoveryCallback =
new EndpointDiscoveryCallback() {
#Override
public void onEndpointFound(String endpointId, final DiscoveredEndpointInfo info) {
arrlist.add(endpointId);
for (int i = 0; i< arrlist.size(); i++) {
connectionsClient
.requestConnection(Build.MODEL, arrlist.get(i), connectionLifecycleCallback)
.addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
}
});
}
}
#Override
public void onEndpointLost(#NonNull String endpointId) {
}
};
private final ConnectionLifecycleCallback connectionLifecycleCallback =
new ConnectionLifecycleCallback() {
#Override
public void onConnectionInitiated(#NonNull String endpointId, #NonNull ConnectionInfo connectionInfo) {
// Automatically accept the connection on both sides.
connectionsClient.acceptConnection(endpointId, new PayloadCallback() {
#Override
public void onPayloadReceived(#NonNull String s, #NonNull Payload payload) {
}
}
#Override
public void onPayloadTransferUpdate(#NonNull String s, #NonNull PayloadTransferUpdate payloadTransferUpdate) {
}
#Override
public void onConnectionResult(#NonNull String endpointId, ConnectionResolution result) {
switch (result.getStatus().getStatusCode()) {
case ConnectionsStatusCodes.STATUS_OK:
if(arrlist != null && arrlist.contains(endpointId)){
System.out.println(TAG+ " End Point Found");
} else {
arrlist.add(endpointId);
}
connectionsClient.stopDiscovery();
connectionsClient.stopAdvertising();
break;
case ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED:
// Some code
break;
case ConnectionsStatusCodes.STATUS_ERROR:
// Some code
break;
default:
}
}
#Override
public void onDisconnected(#NonNull String endpointId) {
// some code
}
};
private void startAdvertising() {
AdvertisingOptions advertisingOptions =
new AdvertisingOptions.Builder().setStrategy(STRATEGY).build();
Nearby.getConnectionsClient(context)
.startAdvertising(
android.os.Build.MODEL, getPackageName(), connectionLifecycleCallback, advertisingOptions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
}
});
}
private void startDiscovery() {
DiscoveryOptions discoveryOptions =
new DiscoveryOptions.Builder().setStrategy(STRATEGY).build();
Nearby.getConnectionsClient(context)
.startDiscovery(getPackageName(), endpointDiscoveryCallback, discoveryOptions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
}
});
}
I am integrating twitter first time in my android application, i am able to post tweet,i want to share image from app,i have URL of images(Which is stored at AmazonS3 server).i want to share this image from my android app ..please anyone can provide steps to achieve this
public class TwitterIntegration extends GlobalActivity {
TwitterAuthClient mTwitterAuthClient;
TwitterApiClient twitterApiClient;
Preferences preferences;
UserHistory userHistory;
StatusesService statusesService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences=HWUtil.getPreferences(this);
userHistory=preferences.getUserHistory();
mTwitterAuthClient=new TwitterAuthClient();
mTwitterAuthClient.authorize(this, new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
TwitterSession session = result.data;
Log.d("user", session.getUserName());
Log.d("user", session.toString());
HWUtil.showToast(TwitterIntegration.this, session.getUserName());
twitterApiClient = TwitterCore.getInstance().getApiClient(session);
statusesService = twitterApiClient.getStatusesService();
statusesService.update("Hii from android", null, null, null, null,
null, null, null, new Callback<Tweet>() {
#Override
public void success(Result<Tweet> result) {
HWUtil.showToast(TwitterIntegration.this, "Posted SucessFully");
if(Validator.isNotNull(userHistory.getHistoryPictures())&& userHistory.getHistoryPictures().length>0){
shareImage();
}
}
public void failure(TwitterException exception) {
HWUtil.showToast(TwitterIntegration.this, "Failed to post");
}
});
}
#Override
public void failure(TwitterException exception) {
HWUtil.showToast(TwitterIntegration.this, exception.getMessage());
}
});
}
private void shareImage() {
if(Validator.isNotNull(twitterApiClient)){
MediaService mediaService=twitterApiClient.getMediaService();
}
}
#Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
// Pass the activity result to the login button.
super.onActivityResult(requestCode,responseCode,intent);
mTwitterAuthClient.onActivityResult(requestCode, responseCode, intent);
}
}
first of all we have to download all the images as said by #amit i used asynctask
public class DownLoadImageAsyncTask extends AsyncTask{
#Override
protected void onPreExecute() {
progressDialog=new ProgressDialog(TwitterIntegration.this);
progressDialog.setCancelable(false);
progressDialog.setMessage(getString(R.string.please_wait));
progressDialog.setIndeterminate(true);
if(Validator.isNotNull(preferences.getImagePath())&& !preferences.getImagePath().isEmpty()){
preferences.getImagePath().clear();
}
filePath=preferences.getImagePath();
}
#Override
protected Object doInBackground(Object[] params) {
File file=new File(Environment.getExternalStorageDirectory(),"/HealthWel");
if(file.exists()==true){
file.delete();
}
file.mkdir();
for (int i=0;i<mURLs.size();i++){
File f=new File(file+"/"+i+".jpg");
if(f.exists()==true){
f.delete();
}
if(f.exists()==false){
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(mURLs.get(i));
try {
HttpResponse httpResponse=httpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity httpEntity=httpResponse.getEntity();
InputStream is=httpEntity.getContent();
Boolean status=f.createNewFile();
FileOutputStream fileOutputStream=new FileOutputStream(f);
byte[]buffer=new byte[1024];
long total=0;
int count;
while ((count=is.read(buffer))!=-1){
total+=count;
fileOutputStream.write(buffer,0,count);
}
if(!downLoad) {
if (Validator.isNotNull(preferences.getImagePath()) && !preferences.getImagePath().isEmpty()) {
preferences.getImagePath().clear();
}
}
filePath.add(f.getPath());
fileOutputStream.close();
is.close();
runOnUiThread(new Runnable() {
public void run() {
// runs on UI thread
progressDialog.show();
}
});
}
else {
finish();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
#Override
protected void onPostExecute(Object o) {
preferences.setImagePath(filePath);
dismissProgressDialog();
shareImage();
}
}
private void showProgressDialog() {
if(!isFinishing() && progressDialog==null) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
progressDialog.show();
}
}
/**
* dismiss Progress Dialog.
*/
private void dismissProgressDialog() {
if (!isFinishing() &&progressDialog!=null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog=null;
}
}
then we have to upload it to twitter using rest api to get media id using status service and after thatwe have to post it along with status with all media id as post. this perfectly works for me.
I make a request to get user profile info by clicking Button. I debugged and when I just opened app and clicked on button onError callback worked and it said "invalid user id". If I press Button second time it works fine. From experiments I understood that app didn't complete authorization, that's why request was denied.
By pressing Button calls method with this code:
VKSdk.authorize(VKScopes.EMAIL);
VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS,
"user_id,first_name,last_name,sex,bdate,city,photo_200_orig"));
request.secure = false;
request.useSystemLanguage = true;
request.executeWithListener(new VKRequest.VKRequestListener() {
#Override
public void onComplete(VKResponse response) {
super.onComplete(response);
//do some stuff
}
#Override
public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {
super.attemptFailed(request, attemptNumber, totalAttempts);
Log.d("VkDemoApp", "attemptFailed " + request + " " + attemptNumber + " " + totalAttempts);
}
#Override
public void onError(VKError error) {
super.onError(error);
Log.d("VkDemoApp", "onError: " + error);
}
#Override
public void onProgress(VKRequest.VKProgressType progressType, long bytesLoaded, long bytesTotal) {
super.onProgress(progressType, bytesLoaded, bytesTotal);
Log.d("VkDemoApp", "onProgress " + progressType + " " + bytesLoaded + " " + bytesTotal);
}
});
I tried to add if(VKSdk.wakeUpSession()) , but it simply passed through, cuz user is not authorized yet. I found in example callback onTokenExpired as part of listener, where I'll authorize user if needed, but when I added it said "is never used".
How can I wait until VKSdk.authorize() finish working and only after send request?
Thanks in advance!
EDIT
This is the line in onCreate()
VKSdk.initialize(sdkListener, activity.getResources().getString(R.string.vk_app_id));
VKUIHelper.onCreate(this);
VKSdkListener
VKSdkListener sdkListener = new VKSdkListener() {
#Override
public void onAcceptUserToken(VKAccessToken token) {
}
#Override
public void onReceiveNewToken(VKAccessToken newToken) {
//requesting the code at the top (request)
//excluding the line VKSdk.authorize(VKScopes.EMAIL);
}
#Override
public void onRenewAccessToken(VKAccessToken token) {
}
#Override
public void onCaptchaError(VKError vkError) {
}
#Override
public void onTokenExpired(VKAccessToken vkAccessToken) {
}
#Override
public void onAccessDenied(VKError vkError) {
}
};
and in onClick() there is a line VKSdk.authorize(VKScopes.EMAIL);
NOTE VkSdkListener's callbacks are not being called after initialize(), but called after authorize(). I don't know why, the behavior of this is awful. Would be great to see working example with gotten user's email and other things listed above.
I could be wrong, but try to change "user_id" to "id".
The answer to your second question (how to fetch data after authorize) is simple.
VKsdk has a listener with abstract methods that you could (and should) override.
EDIT
private static final String[] sVkontakteScopes = new String[]{
VKScope.FRIENDS,
VKScope.PHOTOS,
VKScope.NOHTTPS,
};
private VKSdkListener mVkontakteLoginListener;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, persistentState);
mVkontakteLoginListener = new VKSdkListener() {
#Override
public void onCaptchaError(VKError captchaError) {
new VKCaptchaDialog(captchaError).show(VkApiActivity.this);
}
#Override
public void onTokenExpired(VKAccessToken expiredToken) {
VKSdk.authorize(sVkontakteScopes);
}
#Override
public void onAccessDenied(VKError authorizationError) {
new AlertDialog.Builder(VKUIHelper.getTopActivity())
.setMessage(authorizationError.toString())
.show();
}
#Override
public void onReceiveNewToken(VKAccessToken newToken) {
//put your method here
makeYourStuff();
PrefUtils.storeVkontakteAccessToken(newToken.accessToken);
}
#Override
public void onAcceptUserToken(VKAccessToken token) {
//put your method here
makeYourStuff();
}
#Override
public void onRenewAccessToken(VKAccessToken token) {
//put your method here
makeYourStuff();
}
};
if (PrefUtils.getVkontakteAccessToken() != null)
VKSdk.initialize(mVkontakteLoginListener, getString(R.string.vkontakte_app_id, PrefUtils.getVkontakteAccessToken()));
else {
VKSdk.initialize(mVkontakteLoginListener, getString(R.string.vkontakte_app_id));
}
VKUIHelper.onCreate(this);
}
private void makeYourStuff() {
VKParameters params = new VKParameters();
params.put(VKApiConst.FIELDS, "id,first_name,last_name, photo_100");
VKRequest request = new VKRequest("users.get", params);
request.executeWithListener(new VKRequest.VKRequestListener() {
#Override
public void onComplete(VKResponse response) {
super.onComplete(response);
JSONArray jsonArray;
String firstName, lastName, id, photoUrl;
try {
jsonArray = response.json.getJSONArray("response");
JSONObject userObject = jsonArray.getJSONObject(0);
firstName = userObject.getString("first_name");
lastName = userObject.getString("last_name");
id = userObject.getString("id");
photoUrl = userObject.getString("photo_100");
/*
here you can start another activity or fragment
put this info into bundle or store into database
*/
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onError(VKError error) {
super.onError(error);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
VKUIHelper.onActivityResult(this, requestCode, resultCode, data);
}
#Override
public void onClick(View v) {
if (v.getId() == R.id.btnLogin) {
VKSdk.authorize(sVkontakteScopes);
// after this method will be called your one of your VKSdkListener methods
// you should put your request method all three SUCCESS methods of VKSdk listener
}
}
I have referred this, I have integrated successfully, now I want to create Notebook from app for that I tried below code but I am getting every time exception.
Note myNote = new Note();
myNote.setTitle("My Test Notebook");
createNoteInAppLinkedNotebook(myNote, new OnClientCallback<Note>() {
#Override
public void onSuccess(Note data) {
}
#Override
public void onException(Exception exception) {
Log.e(TAG, exception.toString());
}
});
#SuppressWarnings("deprecation")
protected void createNoteInAppLinkedNotebook(final Note note,final OnClientCallback<Note> createNoteCallback) {
showDialog(DIALOG_PROGRESS);
invokeOnAppLinkedNotebook(new OnClientCallback<Pair<AsyncLinkedNoteStoreClient, LinkedNotebook>>() {
#Override
public void onSuccess(
final Pair<AsyncLinkedNoteStoreClient, LinkedNotebook> pair) {
pair.first.createNoteAsync(note, pair.second,
createNoteCallback);
}
#Override
public void onException(Exception exception) {
Log.e(LOGTAG, "Error creating linked notestore", exception);
Toast.makeText(getApplicationContext(),R.string.error_creating_notestore, Toast.LENGTH_LONG).show();
removeDialog(DIALOG_PROGRESS);
}
});
}
I am getting Error creating linked notestore exception everytime.
Is there any solution for the same ?
Finally I found my own question's solution:
Notebook nb = new Notebook();
nb.setName("My Test Notebook");
try {
AsyncNoteStoreClient asyncNoteStoreClient = mEvernoteSession.getClientFactory().createNoteStoreClient();
asyncNoteStoreClient.createNotebook(nb, new OnClientCallback<Notebook>() {
#Override
public void onSuccess(Notebook data) {
Log.i(TAG, "onSucceess");
}
#Override
public void onException(Exception exception) {
Log.i(TAG, "onException");
}
});
} catch (TTransportException e) {
e.printStackTrace();
}
i have very strange situetion. I 'm working facebook sdk in android. i wrote login code and also can check username and user id.but this code does not working when divice hase facebook application(i uninstalled it and then worked perfect)
this is a my code
public void LoginFacebook() {
mFacebook.authorize(this, mPermissions, new LoginDialogListener());
}
private final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
SessionStore.save(mFacebook, getApplicationContext());
getProfileInformation();
}
public void onCancel() {
SessionEvents.onLoginError("Action Canceled");
}
#Override
public void onFacebookError(FacebookError error) {
SessionEvents.onLoginError(error.getMessage());
}
#Override
public void onError(DialogError error) {
SessionEvents.onLoginError(error.getMessage());
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
#SuppressLint("SdCardPath")
public void getProfileInformation() {
mAsyncRunner.request("me", new BaseRequestListener() {
#SuppressLint("CommitPrefEdits")
#Override
public void onComplete(String response, Object state) {
final String json = response;
runOnUiThread(new Runnable() {
#Override
public void run() {
try {
JSONObject profile = new JSONObject(json);
facebook_userid = profile.getString("id");
facebook_username = profile.getString("name");
facebook_username = facebook_username.replace(
"%20", " ");
editor.putString("fb_name", facebook_username);
editor.putString("fb_id", facebook_userid);
fb_name.setText(facebook_username);
getFacebookAvatar(facebook_userid);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
#Override
public void onIOException(IOException e, Object state) {
}
#Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
#Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
#Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}
i have no idea what is a wrong.
if anyone knows solution please help me thanks
Enable Client Deep Linking,Single Sign On and in advance tab OAuth Login from devlopers.facebook.com
You Can Do Like This.
public static void getuserdata() throws JSONException {
String Facebook = readT("https://graph.facebook.com/me?access_token="+mFacebook.getAccessToken()+"&fields=id,username)".replace(" ","%20"));
try
{
JSONObject jsonobj = new JSONObject(Facebook);
fb_id = jsonobj.getString("id");
fb_username = fb_fname+" "+fb_lname;
Log.e("..fb_username..........", fb_username);
}
catch (JSONException e)
{
e.printStackTrace();
}
}