Android Studio - Deploys my app without new changes - android

My problem is basically that Android Studio wont deploy my app with my changes in the new code. Heres my case scenario:
I have a wifi direct code working like this (just testing with its methods):
public void peerDiscovery(){
mWifiDirectManager.discoverPeers(mChannel,
new WifiP2pManager.ActionListener() {
#Override
public void onSuccess() {
Log.v(TAG,"Discovery Peers Success");
}
#Override
public void onFailure(int reason) {
Log.e(TAG,"Error on Discovery Peers, code: "+reason);
}
});
}
The above code works and then I decided to change it by adding the method: setPeerDiscoveryHandler(boolean isSuccess);
After the changes my code was as follows:
public void peerDiscovery(){
mWifiDirectManager.discoverPeers(mChannel,
new WifiP2pManager.ActionListener() {
#Override
public void onSuccess() {
setPeerDiscoveryHandler(true);
Log.v(TAG, "Message Sent");
}
#Override
public void onFailure(int reason) {
Log.e(TAG,"Error on Discovery Peers, code: "+reason);
setPeerDiscoveryHandler(false);
}
});
}
But guess what, even after doing this new code and clicking on the Run button, it was like I didnt do nothing! And I realized that was happening after I started to check my logcat and the message:
"Discovery Peers Success"
was being printed, but I had it removed from the code (as you can see in my new code). I tried to rebuild and clean the project, uninstall the application from the mobile before deploying it again, but nothing seems to take effect. Any thoughts about it ?
Thanks in advance for all help guyz.

Well guyz, turns out that I found the solution for that problem of mine. Actually, I dont know why, but when that starts to happen you need to click on a button called "Sync Project with Gradle Files", and it will sync all your project files all over again. Like I said before, I really dont understand why that is needed, but in case someone have this problem in the future thats a solution. Thanks.

Android studio 4.2.x
This solved my problem:
In Android Studio, go to Run > Edit Configurations -> Disable "Allow parallel run"

Just go to "File -> Settings -> Build, Execution, Deployement -> Deplyoyment ->" and just disable the automatic Perform Run when ApplyChanges fails.

Related

WifiP2pManager.discoverPeers fails in android 10

following code sample returns Error code: 0, which is the error code for internal error in android. Is there any workaround which can enable discovering peers in android 10 devices?
wifip2pmanager.discoverPeers(wifip2pmanagerChannel, new WifiP2pManager.ActionListener() {
#Override
public void onSuccess() {
status.setText("Peer Discovery Started");
}
#Override
public void onFailure(int reason) {
status.setText("Error code:" + reason);
}
});
Exactly the same happened to me...
ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION are not enough. The user has to explcitly activate the location services!
(in my case turning on location solved the problem...)
This means: Either you activate location in your settings manually or you make a usability friendly request to the user to activate location services (looks similar to permission request window; see google maps)
See this question for example code of the latter. Hope this helps!
Edit: If you search for an anwser that not envolves any Google libs, see the anwser to this question.
In addition to the statement in the list, you also need to dynamically apply for this permission.

FirebaseRemoteConfig.fetch() does not trigger OnCompleteListener every time

I'm trying to implement Firebase Remote Config :
override fun onCreate(savedInstanceState: Bundle?) {
val configSettings = FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG).build()
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
mFirebaseRemoteConfig.setConfigSettings(configSettings)
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults)
fetchRemoteConfig()
}
private fun fetchRemoteConfig() {
var cacheExpiration = 3600L
if (mFirebaseRemoteConfig.info.configSettings.isDeveloperModeEnabled) {
cacheExpiration = 0L
}
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d(TAG, "Remote config fetch succeeded")
mFirebaseRemoteConfig.activateFetched()
} else {
Log.d(TAG, "Remote config fetch failed - ${task.exception?.message}")
}
setupView()
}
}
private fun setupView() {
val text = mFirebaseRemoteConfig.getString("my_text")
//...
}
My problem is that the OnCompleteListener is not always called.
If I close/open my app several times, the setupView() is not always triggered.
The OnCompleteListener should always be called right? Even if I'm hitting cache?
EDIT: Even if I disable the developper mode the behavior is the same. Sometimes the callback is triggered, sometimes not.
I was facing the same issue and contacted the firebase support. They replied the following:
There currently is a bug that has been reported where onComplete, onSuccess, and onFailure listeners doesn't get called if fetch() is called too early. [...]
Currently there is a work around where you can put the fetch() inside a postResume. You can try using this in the meantime before a solution has been released.
I implemented the workaround accordingly
protected void onPostResume() {
super.onPostResume();
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "Fetch Succeeded");
// Once the config is successfully fetched it must be activated before newly fetched values are returned.
mFirebaseRemoteConfig.activateFetched();
// Do whatever should be done on success
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
Log.d(TAG, "Fetch failed");
// Do whatever should be done on failure
}
});
}
So far it seems their proposed workaround has resolved the issue.
UPDATE:
I just got notice from the firebase support. According to them the issue is resolved with the latest Google Play Services update.
A fix to Remote Config not calling listeners after fetching has been released in the newest Google play services update.
I'll be closing this case for now. However if you are still experiencing issues, feel free to reach out and let me know.
If your device run an old Google Play Service and incompatible version, you should see in logs:
GooglePlayServicesUtil: Google Play services out of date. Requires 11020000 but found 10930470
One solution is to upgrade your device Google Play services, but if you cannot, you can also simply downgrade firebase version to match the expected version (here change 11.0.2 to 10.9.3).
Not ideal, but still a solution if you cannot upgrade your device (for instance the simulator is running 10.9.3 as of today):
compile 'com.google.firebase:firebase-core:10.2.6'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-config:10.2.6'
For those of you who cannot make it by simply calling fetch() onPostResume (and really willing to make this work better), you may try calling fetch method inside Handler.postDelayed() to delay your fetch timing. For our team it increased the chance of fetch method working correctly. Of course this solution does not work reliably just like calling fetch onPostResume though.
#Override
public void onPostResume() {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mFirebaseRemoteConfig.fetch(cacheExpiration)...
...
}
}, 500L);
}
UPDATE version 9.2.0 of firebase works as one would expect and this hack is no longer needed.
I got this "working" reliably... but you may not like my solution. In order to get the config fetch to happen when firebase is ready I had to do this:
FirebaseAuth.getInstance()
// I don't actually want to or need to sign in..(and this actually throws an error for us.. but we ignore it)
.signInAnonymously()
// when it completes (error or no error) we can do our business
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
// do the remote config fetch you were doing before
remoteConfig.fetch(...).addOnComplete(...);
}
});
This ensures that the firebase internals are ready to do that initial config fetch... on first app open this seems to take about 6-10 seconds on my crappy test device (the entire thing including the auth and config fetch). On subsequent opens the entire thing takes like 2-5 seconds. Obviously that's all arbitrary depending on device/network and YMMV.
I would love to know why this is required.. seems like remote config should be able to manage this internally and not expose this to us.
p.s. you will need this dependency in addition to the firebase-config
compile 'com.google.firebase:firebase-auth:9.0.1'

WearableListenerService onMessageReceived is not called on device

I am trying to send a simple message from my Android wear app to my phone app using the Wearable.MessageApi.
This is my onConnected callback from GoogleApiClient on the Wear device.
final PendingResult<Status> status = Wearable.DataApi.addListener(googleApiClient, this);
status.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
if (!status.isSuccess()) {
return;
}
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
for (Node node : nodes.getNodes()) {
System.out.println("Sending message: " + node.getDisplayName());
final MessageApi.SendMessageResult result =
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
"request", "12345".getBytes())
.await();
System.out.println("sent: " + result.getStatus().isSuccess());
}
}
});
And this is displaying the following when ran
Sending message: Nexus 6P
sent: true
And this is my registered service on my app:
public class MyWearableListenerService extends WearableListenerService {
#Override
public void onMessageReceived(MessageEvent messageEvent) {
Toast.makeText(this, "Received message", Toast.LENGTH_LONG).show();
}
#Override
public void onPeerConnected(Node peer) {
Toast.makeText(this, "Peer connected", Toast.LENGTH_LONG).show();
}
}
I properly verified that the Peer connected toast is showing up when the emulator is connected to my device. I properly did the port forwarding to debug on wear emulator. I checked that my applicationId and package names are consistent across my app and wear app. However, I never get the onMessageReceived callback on my device.
Any suggestions are greatly appreciated! I've been debugging this for a whole day now :(
Oh, good god.. I figured out my problem. I THOUGHT the applicationId was the same, but it turned out that I never set up build flavors on the wear module, so the two applicationIds were actually com.example.android and com.example.android.dev..
Hope this helps other people who ran into the same problem as me :\
I was having the same issue, due to (very) poor and outdated documentation on the Android Developer website. I was adding a Wear app to an existing app that's been around for years. As such, I have been using a custom debug.keystore for years now in my main app.
When I made the Wear app, I did not update the build.gradle to use the same debug.keystore file as the regular app - once I did that, I started receiving messages from the Watch -> Phone!
Here is a checklist to review if you're having the same issue as me and the OP:
Wear and Phone apps need same applicationId
Same versionNumber and versionName between apps
Signed by the same key (this was what fixed my issue)
I just copied the "signingConfigs" section from my app's build.gradle to the wear app's build.gradle
signingConfigs {
debug {
storeFile file('../app/debug.keystore')
}
}
This issue cost me an entire day, hopefully someone else finds this useful.
Another possible trap, in your WearableListenerService, don't forget the call to super:
#Override
public void onCreate() {
super.onCreate(); // <-- don't forget this
...
}

Parse deleteEventually() method doesn't work (Android code)

I'have downloaded the code of the Parse project "OfflineTodos" (see https://github.com/ParsePlatform/OfflineTodos) for Android. It's a very simple sample app, but I'm having problems with it.
I've tried so many combinations to make this work, but I couldn't!
This is part of the original code from class "NewTodoActivity":
deleteButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// The todo will be deleted eventually but will
// immediately be excluded from query results.
todo.deleteEventually();
setResult(Activity.RESULT_OK);
finish();
}
});
VERY simple, but it doesn't work! It just delete the local Todo Object, not the server one. I've wait a lot of time with the app running, but nothing happens.
The deleteInBackground() works fine, but I need to use the deleteEventually(), because my app will run in locals with bad internet signals.
I didn't make any changes at the original code.
I want this method (deleteEventually()) to delete immediatelly when the cellphone get network, is it possible? If not, what should I do?
Thanks.
Newer versions of android (above version 5) somehow don't seem to accept deleteEventually(). For now, I would suggest a just using deleteInBackground() for the newer versions
if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 21) {
object.deleteInBackground();
}else{
object.deleteEventually();
}

No authentication challenges foundRelevant discussions can be found on the Internet at

I have some typical codes which used Twitter4J to connect Twitter API. They worked fine in android 1.x and 2.x. 3.x 4.x But failed in Android 4.1.1 and 4.1.2 with Nexus 7 device!
Source:
private void retrieveRequestToken() {
mSpinner.show();
new Thread() {
#Override
public void run() {
try {
mRequestToken = mTwitter.getOAuthRequestToken(Twitter.CALLBACK_URI);
mUrl = mRequestToken.getAuthorizationURL();
mWebView.loadUrl(mUrl);
} catch (TwitterException e) {
mListener.onError(new DialogError(e.getMessage(), -1, Twitter.OAUTH_REQUEST_TOKEN));
}
}
}.start();
}
Exception:
No authentication challenges foundRelevant discussions can be found on the Internet at
The problem hapens when i try to get on OAuthToken -> mTwitter.getOAuthRequestToken(Twitter.CALLBACK_URI);
Would anybody please help to investigate this issue?
I foud the problem just put the hour and date correct on device!!!! Go to Phone settings then click 'Date and Time' and select 'Automatic' (Please make sure your device Time Zone and Time,Date all are correct) If your time,Date and Time Zone are not correct then you can not connect with twitter.
My date and time was correct set, but I just restarted my phone and it started working

Categories

Resources