How to create new notebook in evernote from android application? - android

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();
}

Related

How to connect 3+ devices using Google-Nearby Connection APIs

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) {
}
});
}

AWS AppSync Error - AWSMobileClientStore.get(String) on null object reference

APPSYNC_ERROR: Attempt to invoke virtual method
java.util.Map
com.amazonaws.mobile.client.AWSMobileClientStore.get(java.lang.String[])
on a null object reference
I am trying to inserting data in AWS table, But i got this error.
Can you help me to resolve this issue?
AWSAppSyncClient client = AWSAppSyncClient.builder()
.context(context)
.region(AppHelper.cognitoRegion)
.serverUrl(AppHelper.SERVER_URL)
.cognitoUserPoolsAuthProvider(new CognitoUserPoolsAuthProvider() {
#Override
public String getLatestAuthToken() {
try {
return AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString();
} catch (Exception e){
Log.e("APPSYNC_ERROR", e.getLocalizedMessage());
return e.getLocalizedMessage();
}
}
}).persistentMutationsCallback(new PersistentMutationsCallback() {
#Override
public void onResponse(PersistentMutationsResponse response) {
Log.d("NOTERROR", response.getMutationClassName());
}
#Override
public void onFailure(PersistentMutationsError error) {
Log.e("TAG", error.getMutationClassName());
Log.e("TAG", "Error", error.getException());
}
}).build();
You need to initialize AWSMobileClient successfully before its usage.
AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {
#Override
public void onResult(UserStateDetails userStateDetails) {
switch (userStateDetails.getUserState()){
case SIGNED_IN:
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView textView = (TextView) findViewById(R.id.text);
textView.setText("Logged IN");
}
});
break;
case SIGNED_OUT:
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView textView = (TextView) findViewById(R.id.text);
textView.setText("Logged OUT");
}
});
break;
default:
AWSMobileClient.getInstance().signOut();
break;
}
}
#Override
public void onError(Exception e) {
Log.e("INIT", e.toString());
}
});
If initialize is successful, you will be able to retrieve the tokens through the getTokens() method.
Source: https://aws-amplify.github.io/docs/android/authentication

Using mqtt to send push notification , not working when swiped from recent apps

using mqtt for push notification in android with following libs :
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
i followed this tutorial , the problem is it works properly when app is open , but when it is swiped from recent apps , it stops working and I can't receive push notifications anymore
any help is appreciated
solutions i tried :
first solution : created a service and simply created a mqttclient in it , but after swiping from recent apps didn't work anymore
public class MqttService extends Service {
public MqttService(Context context) {
super();
}
public MqttService() {
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
PahoDemo paho = new Paho(getApplicationContext(), "myTopic");
return START_STICKY;
}
#Override
public void onTaskRemoved(Intent rootIntent) {
Intent intent = new Intent("com.example.restart");
sendBroadcast(intent);
}
#Override
public void onDestroy() {
super.onDestroy();
Intent intent = new Intent("com.example.restart");
sendBroadcast(intent);
}
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
PahoDemo :
public class Paho implements MqttCallback {
String topic;
MqttClient client;
Context context;
public Paho(Context context, String topic) {
this.context = context;
this.topic = topic;
try {
client = new MqttClient(StaticValue.getBROKER(), MqttClient.generateClientId(), persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
client.connect(connOpts);
client.setCallback(this);
if (topic != null) {
client.subscribe(topic);
}
} catch (MqttException e) {
System.out.println("error: " + e);
e.printStackTrace();
}
}
#Override
public void connectionLost(Throwable cause) {
}
#Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
Log.i("mqtt", "messageArrived ");
}
#Override
public void deliveryComplete(IMqttDeliveryToken token) {
Log.i("mqtt", token + "");
}
}
second solution:
added the below line to manifest :
<service android:name="org.eclipse.paho.android.service.MqttService" />
called this helper class from mainactivty's Oncreate :
public class MqttHelper {
public MqttAndroidClient mqttAndroidClient;
final String serverUri = "myBrokerUri";
final String clientId = MqttClient.generateClientId();
final String subscriptionTopic = "myTopic";
public MqttHelper(Context context){
mqttAndroidClient = new MqttAndroidClient(context, serverUri, clientId);
mqttAndroidClient.setCallback(new MqttCallbackExtended() {
#Override
public void connectComplete(boolean b, String s) {
Log.w("mqtt", s);
}
#Override
public void connectionLost(Throwable throwable) {
}
#Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
Log.w("Mqtt", mqttMessage.toString());
}
#Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
connect();
}
public void setCallback(MqttCallbackExtended callback) {
mqttAndroidClient.setCallback(callback);
}
private void connect(){
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setCleanSession(true);
try {
mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken asyncActionToken) {
subscribeToTopic();
}
#Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.w("Mqtt", "Failed to connect to: " + serverUri + exception.toString());
}
});
} catch (MqttException ex){
ex.printStackTrace();
}
}
private void subscribeToTopic() {
try {
mqttAndroidClient.subscribe(subscriptionTopic, 0, null, new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.w("Mqtt","Subscribed!");
}
#Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.w("Mqtt", "Subscribed fail!");
}
});
} catch (MqttException ex) {
System.err.println("Exceptionst subscribing");
ex.printStackTrace();
}
}
}
that's all i did since tow days ago . if someone has any ideas , please mention .
when messageArrived is called , you shouldn't use something you don't access to . for example if you wanna check app is in foreground , you may use context , this way your logic may doesn't work properly , so make sure you do what you can do in messageArrived and if you aren't sure the objects you use are available do it another way (also be careful about connectinLost )

download image from quickblox android

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 :-)

android get facebook username and id

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();
}
}

Categories

Resources