In my Android app, when the following code is successful:
mDbxAcctMgr.startLink(SyncActivity.this,REQUEST_LINK_TO_DBX);
This code runs:
if (ds.getSyncStatus().hasIncoming) {
try {
Map<String, Set<DbxRecord>> mMap = mDatastore
.sync();
dataHasIncoming(mMap); // Inserted into the database
} catch (DbxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
If you close the app while this is occurring, dataHasIncoming(mMap) just inserts part of the data, but loses the rest. Is there any way around this, such as setting a node, or re-opening the synchronization without checking all the data?
Related
I'm trying the my Azure Mobile Service. Below is the code to make a new ToDo item entry. The sample Android code shows how to create a mobile client. I added it to the onCreate method as mentioned in the example.
But the insert always fails. I always get an exception which says com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request.
mClient does get initialized. But, mClient.mCurrentUser is null. Not sure if this is a problem.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient("https://myservice.azure-mobile.net/",
"slkerjasfi234eSomePrivateKey", this);
Item item = new Item();
item.setText("Awesome item");
item.setComplete(false);
mClient.getTable(Item.class).insert(item,
new TableOperationCallback<Item>() {
public void onCompleted(Item entity,
Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
ShowMessage("Success");
} else {
ShowMessage("Failed");
}
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In my case, it looked like the key (parameter 2 in MobileServiceClient constructor) was incorrect. That is how I had downloaded it though. It happened again today and I manually fixed the key and it worked for another service. Believe it was the same issue here. To view your key, you go to your service in Azure and click Manage Keys at the bottom.
I am doing a project related to live wallpaper, in that camera was set as wallpaper, so in my app camera was running continuously, if user set camera as wallpaper, after he opening the camera it will shows the camera failed to load error,
so, i am using the following code to avoid this error:
public void onVisibilityChanged(boolean visible) {
if (visible){
try {
mCamera.reconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
try {
mCamera.unlock();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But my problem is could not unlock the camera object to other apps use the camera.
can any one give me an idea how can i do this?
You cannot access the object used by the native camera app or other apps to access camera. When you create mCamera, you are creating your own object which is used by your app. At a time, only one object can access a particular camera resource, and you have no control over other objects of other apps accessing that camera resource.
If you want avoid the failed to load error, you need to release your camera object before you open another app which uses camera resource. But then I do not think your main objective will be accomplished.
I am using same method with small modifications to solve the issue, i was doing following changes in the code
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
try {
"open camera object"
}catch (Exception e) {
e.printStackTrace();
}
}else {
try {
"release the camera object"
}catch (RuntimeException e) {
e.printStackTrace();
}
}
}
I made a simple android appication for connect with bluetooth serial device and I want to add closeBT if android not connected maybe the device is out of range because crash.
How do I do this? This code is correct?
protected void onStart() {
super.onStart();
findBT(); //Check if bluettoth enable and paired devices
try {
openBT(); //open sockets,streams
} catch (IOException e) {
e.printStackTrace();
closeBT();
}
}
Try-catch is not for the application logic! It is for doing stuff when something went wrong! You want to use an if-else here, like
if (findBT() != null) { // I don't know what findBT does, but maybe it returns BT-devices
try {
openBT(); //open sockets,streams
} catch (IOException e) {
e.printStackTrace();
// inform the user that a connection could not be established or something similar
}
} else {
// inform the user, that no BT-device was found.
}
you want to use closeBT() for instance when the user or your application decides to disconnect the BT-devices.
Up to Android 2.2 I know I can use reflection and terminate the call through getITelephony.
However, as of 2.3 this no longer works because even if you grant the MODIFY_PHONE_STATE permission to your app, it's now a system app only permission:
https://stackoverflow.com/a/5095956/821423
That said, it's possible still because a myriad of applications on the google play market are doing it just fine on ICS, for example, this one:
https://play.google.com/store/apps/details?id=com.androminigsm.fscifree&hl=en
So the question is, how do they do it? I know I can pick up the call using simulating a headset hook, but I can't figure out how to end the call.
Thank you.
Well after much soul-searching I realize something really, really, really dumb. On the plus side no one on StackOverflow seems to have noticed it either. MODIFY_PHONE_STATE is no longer working on silenceRinger() since 2.3+, but endCall is just fine.
So the solution is to comment out the call to silenceRinger().
Can't believe I've just spent a week on this! I'll try to update the other questions as there seem to be tons of dupe on SO along the lines of 'it's not possible to use reflection to terminate the calls anymore'.
The call() , endcall() functions work fine for me as well. But there is also another way tha works without using iTelephony.aidl. Its published in this post. BTW I think google already knows but for some reason they havent done anything with the rest of functions, wich is good!!!
http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html
private void endCall(final String cutofftime) {
TelephonyManager telephony = (TelephonyManager) srvs
.getSystemService(Context.TELEPHONY_SERVICE);
Class c;
final com.android.internal.telephony.ITelephony telephonyService;
try {
c = Class.forName("android.telephony.TelephonyManager");//telephony.getClass().getName());
Log.i("TelephonyClass Name", telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
TimerTask task = new TimerTask() {
#Override
public void run() {
try {
if (telephonyService.isIdle()
|| telephonyService.isOffhook()
|| telephonyService.isRinging())
telephonyService.endCall();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
long delay = Integer.parseInt(cutofftime) * 1000;
new Timer().schedule(task, delay);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have successfully setup the Facebook Plugin by Jos located (https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook) - but I can't seem to figure out a way to log the user out. Sure I could tell them to delete the App access on the website then try to login again and click on "Not you?" but I would really rather have a JS Function that does it for me.
Can anyone help provide some guidance on how to do this? I've looked through the files and it looks like there is a way to do it in the facebook.java but I just need to hack something together to connect it to webview. I'm not capable of doing so :) can anyone please help?
This solution is to disable the single sign on feature in the Facebook plugin
in FaceBook.java file
replace DEFAULT_AUTH_ACTIVITY_CODE in the Authorize method [2 overloads] by FORCE_DIALOG_AUTH
in FacebookAuth.Java file
append this to execute method [in the switch case section]
else if (action.equals("performLogout")){
this.performLogout(first);}
//Add this method to FacebookAuth.java class
public void performLogout(final String appid) {
Log.d("PhoneGapLog", "LOGOUT");
final FacebookAuth fba = this;
Runnable runnable = new Runnable() {
public void run() {
fba.mFb = new Facebook(appid);
fba.mFb.setPlugin(fba);
try {
fba.mFb.logout((Activity) fba.ctx);
fba.success(new PluginResult(PluginResult.Status.OK, ""), fba.callback);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
};
this.ctx.runOnUiThread(runnable);
}
//in facebook.js file add the following section
Facebook.prototype.Logout = function(app_id,callback){
PhoneGap.exec(callback,null, "FacebookAuth", "performLogout", [app_id]); };
// in your page add the following code
function LogoutClick() //on logout click
{
appId = "123" ; //your app Id
window.plugins.facebook.Logout(appId,CompleteLogout);
}
function CompleteLogout() //call back function
{
//do some logic for callback
}
//Enjoy..!!