• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Chasing origin of error A resource failed to call close

hi
To help you troubleshoot the issue you are experiencing, it might be helpful to try the following steps:

  1. Review the code around line 30 in the file App.java, as this is where the Strict Mode violation is being triggered. This is likely the code that is responsible for acquiring the resource that is being leaked.

  2. Look for any places in your code where you might be opening resources, such as streams or database connections, and make sure that you are properly closing them when you are finished with them.

  3. If you are unable to find the cause of the leak in your code, you could try enabling more verbose logging in Strict Mode by setting the penaltyLog flag in the VmPolicy.Builder object. This will cause Strict Mode to print a more detailed log message when a violation occurs, which might provide more clues about the cause of the leak.

  4. Another option might be to try running your app in a debugger and setting a breakpoint at line 30 in App.java. This will allow you to pause the app at the point where the leak is occurring, and inspect the state of the app to see if you can find any clues about the cause of the leak.
I hope this helps! Let me know if you have any other questions.

Thanks for the suggestions.
Line 30 is just the line that sets strict mode policy up so that I can capture the event. The issue still occur if I remove this:

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedClosableObjects()
.penaltyListener( this.getMainExecutor(), ( Violation v) -> {
v.fillInStackTrace();
v.printStackTrace();
} )

I will try the other suggestions to

Thinking about the future (phones, plans, Android in general)

Try using Samsung's Smart Switch utility to transfer her old S10 user account data to the new S22. It's a pretty reliable tool to backup/transfer data, especially between two Samsung phones, but be sure to read through the exclusions for third-party data that might not be included (i.e. WhatsApp, which has its own backup service in the WhatsApp app.)
https://www.samsung.com/us/apps/smart-switch/
Hope your retirement into a RV life is as awesome as it sounds to be.

Thanks! I used SmartSwitch to move the accounts from our older Galaxies to the 10s - and have already backed up my 10 to get ready.

We've been doing this full-time RV lifestyle for 7-1/2 years and love it. When asked about our exit plan, we tell folks we're going to do it until we have to find a rest area to pull over and die... and watch their faces. (Of course, we do more serious planning for real.)

Rob

Using insecure protocols with repositories

you are trying to use an insecure protocol (HTTP) to access a Maven repository in your Gradle build. This is causing a problem because, as the error message states, using insecure protocols with repositories is unsupported.

To fix this issue, you will need to either:

  1. Switch to a secure protocol (such as HTTPS) when accessing the repository. This will require updating the repository URL in your build configuration to use HTTPS instead of HTTP.

  2. Allow insecure protocols to be used with repositories by adding the following line to your build configuration:
Code:
repositories {
    maven {
        url "http://localhost/"
        allowInsecureProtocols()
    }
}

Note that allowing insecure protocols to be used with repositories is generally not recommended, as it can pose a security risk. It is generally safer to switch to a secure protocol (such as HTTPS) whenever possible.

Help required Mi4 Fitness Band

just curious as to how inconsistent are they? are they even close? and you are only measuring sleep duration? i would only trust the one that you are supposed to use with the watch, the MI Fit app ....but that is me.

Frequently the results are not at all close, the 3 apps may show sleep duration is
twice the number of hours such as 3 hrs in one app and 6 hrs or even more in another. Usually Notify has the lowest figure, Zepp the highest, Master in the middle --- but even that is not consistent. I do not think this is a minor disparity and if it is regarded as 'acceptable it renders the Band much less useful than expected. It will not be worth buying again.

I am looking for an Android Studio Client/Server USB Sample/Example Code

hi
Here's a simple example of how to set up a client-server communication between an Android device and a computer running Ubuntu using a USB connection:

  1. On the computer running Ubuntu, create a new Java project and add the following code to create a server that listens for incoming connections on a specific port:
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8000);
            System.out.println("Server started on port 8000");
            Socket clientSocket = serverSocket.accept();
            System.out.println("Client connected");
            BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                System.out.println("Received message: " + inputLine);
                out.println("Server received message: " + inputLine);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

  1. On the Android device, create a new project in Android Studio and add the following code to create a client that connects to the server and sends a message:
Code:
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class MainActivity extends AppCompatActivity {
    private TextView mTextView;
    private EditText mEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = findViewById(R.id.text_view);
        mEditText = findViewById(R.id.edit_text);
    }

    public void sendMessage(View view) {
        String message = mEditText.getText().toString();
        new SendMessageTask().execute(message);
    }

    private class SendMessageTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... strings) {
            try {
                String message = strings[0];
                Socket socket = new Socket("192.168.42.129", 8000);
                PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
                BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                out.println(message);
                String response = in.readLine();
                return response;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

How can I release the mic after my app used it?

To release the microphone after a call ends, you can use the AudioManager.setMicrophoneMute() method to turn off the microphone. This method takes a boolean parameter that specifies whether the microphone should be muted or not.

Here is an example of how you can use this method to release the microphone after a call ends:

Code:
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMicrophoneMute(true); // turn off the microphone

Alternatively, you can use the AudioManager.abandonAudioFocus() method to abandon audio focus and allow other audio apps to use the microphone. This method takes an AudioManager.OnAudioFocusChangeListener as a parameter, which can be used to detect when audio focus is lost or regained.

Here is an example of how you can use this method to release the microphone after a call ends:

Code:
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.abandonAudioFocus(new AudioManager.OnAudioFocusChangeListener() {
    @Override
    public void onAudioFocusChange(int focusChange) {
        // handle audio focus changes here
    }
});

How to avoid HTTP REQUEST CAPTURE [HTTP CRANARY]

Using HTTP basic authentication (i.e., adding an Authorization header to your HTTP requests) can help secure your API by requiring a valid username and password for each request. However, it is important to note that HTTP basic authentication is transmitted in plain text and can be easily captured by anyone who has access to the network traffic.

To make it more secure, you can use HTTPS (HTTP Secure) instead of HTTP. HTTPS encrypts the communication between the client and the server, making it more difficult for third parties to intercept or modify the traffic.

Additionally, you can consider implementing other security measures such as:

  1. Using API keys: You can use API keys to authenticate API requests. API keys are unique strings that are associated with a specific API client. You can use API keys to track and control the usage of your API.

  2. Using OAuth: OAuth (Open Authorization) is a standardized authorization framework that allows users to grant third-party applications access to their resources without sharing their passwords. OAuth is commonly used for authorization in APIs.

  3. Implementing rate limiting: You can use rate limiting to limit the number of API requests that a client can make within a specific time period. This can help prevent abuse and denial of service attacks.
I hope these suggestions help you secure your API. Let me know if you have any questions.

FirebaseMessaging.getInstance().getToken()

There could be several reasons why the FCM token is not being generated when you build the app for publishing on Google Play Store. Here are a few things you can try to troubleshoot the issue:

  1. Make sure that you have correctly added the required dependencies in your app-level build.gradle file.
  2. Check if you have enabled the required services in the Firebase console. Go to the Firebase console, select your project, and make sure that the Cloud Messaging service is enabled.
  3. Make sure that you have added the required metadata to your app's AndroidManifest.xml file. This includes the google-services plugin, the FCM service, and the internet permission.
  4. Check if you have correctly configured your app's SHA-1 key in the Firebase console. Go to the Firebase console, select your project, and add your app's SHA-1 key in the "Settings" > "General" section.
  5. If you are using a physical device to test your app, check if the device has a working internet connection.
I hope these suggestions help you resolve the issue. Let me know if you have any questions or need further assistance.

don't know how to access data using retrofit

To retrieve the launchLatest data from the SpaceX GraphQL API using Retrofit, you can update your Retrofit service interface as follows:

Code:
interface RetroService {
  @POST("graphql/")
  @Headers("Content-Type: application/json")
  fun getLastLaunch(): Call<LaunchModel>

  data class LaunchModel(val data: Data)

  data class Data(val launchLatest: LaunchLatest)

  data class LaunchLatest(
    val id: String,
    val details: String?,
    val isTentative: Boolean?,
    val launchDateLocal: String?,
    val launchDateUnix: Long?,
    val launchDateUtc: String?,
    val launchSite: LaunchSite?,
    val launchSuccess: Boolean?,
    val launchYear: String?,
    val links: Links?,
    val missionId: List<String>?,
    val missionName: String?,
    val rocket: Rocket?,
    val staticFireDateUnix: Long?,
    val staticFireDateUtc: String?,
    val telemetry: Telemetry?,
    val tentativeMaxPrecision: String?,
    val upcoming: Boolean?,
    val ships: List<Ship>?
  )

  data class LaunchSite(val siteId: String, val siteNameLong: String)

  data class Links(val flickrImages: List<String>, val missionPatch: String, val missionPatchSmall: String, val presskit: String, val redditCampaign: String, val redditLaunch: String, val redditRecovery: String, val redditMedia: String, val videoLink: String)

  data class Rocket(val rocketId: String, val rocketName: String, val rocketType: String)

  data class Telemetry(val flightClub: String)

  data class Ship(val shipId: String, val shipName: String, val shipModel: String)
}

To make the request, you can use the following code:

Code:
val retroInstance = RetroInstance.getRetroInstance().create(RetroService::class.java)
val requestBody = "{\"query\":\"{launchLatest{id, details, isTentative, launchDateLocal, launchDateUnix, launchDateUtc, launchSite{siteId, siteNameLong}, launchSuccess, launchYear, links{flickrImages, missionPatch, missionPatchSmall, presskit, redditCampaign, redditLaunch, redditRecovery, redditMedia, videoLink}, missionId, missionName, rocket{rocketId, rocketName, rocketType}, staticFireDateUnix, staticFireDateUtc, telemetry{flightClub}, tentativeMaxPrecision, upcoming, ships{shipId, shipName, shipModel}}}\",\"variables\":null}"
val retrofitData = retroInstance.getLastLaunch(requestBody)
retrofitData.enqueue(object: Callback<RetroService.LaunchModel> {
  override fun onFailure(call: Call<RetroService.LaunchModel>, t: Throwable) {
    Toast.makeText(this@MainActivity, "call fail", Toast.LENGTH_LONG).show()
  }

  override fun onResponse(
    call: Call<RetroService.LaunchModel>,
    response: Response<RetroService.LaunchModel>
  ) {
    val responseBody = response.body()

    if(responseBody != null){
      val

The “Dark Humor” Thread

Slightly NSFW -

A man took his beautiful wife to play her first game of golf. The wife, reluctant to try but wanting to spend more time with her husband, promptly sliced her first shot. It went right through the window of the biggest homes along the course.

The husband cringed. "I warned you to be careful! Now we'll have to go over there, find the owner, apologize and see how much that wonderful drive of yours is going to cost us!"

The couple, in silence, walked to the house and knocked on the front door.

A warm voice said, "come on in."

When they opened the door, they observed the damage that was done: glass was all over the place; and a broken bottle, evidently very old, was lying on its side near the pieces of window glass.

A man reclining on the couch asked, "are you the people who broke that window?"

“Uh, yes sir,” the husband replied, “and we're terribly sorry about that…"

“Oh, no apology is necessary!” the man said. “In fact, I want to thank you. You see, I'm actually a genie, and I've been trapped in that bottle for over a thousand years.”

“Now that you've released me,” he continued, “I'm allowed to grant three wishes. I'll give each of you one wish: but if you don't object, I'd like to reserve the last wish for myself."

“Wow, that's amazing!" The husband said. He pondered a moment and blurted out, "I'd like a million dollars a year for the rest of my life!"

“No problem," said the genie. "You've got it, it's the least I can do. Additionally, I'll guarantee you a long, healthy life! And you, young lady, what do you want?"

The wife, flattered at being called a young lady, replied, “I'd like to own a gorgeous home in every country in the world… complete with service staff."

“Consider it done," the genie said. "Soon, the deeds will begin to arrive at your home, free and clear of all mortgages. And your homes will always be safe from fire, burglary and natural disasters."

Completely flustered by the good fortune of an unfortunate golf swing, the couple asked, “and now, what's your wish, Genie?"

The genie looked at the couple solemnly, and then turned to the man.

“Please understand that I've been trapped in that bottle, all alone, for more than a thousand years. I haven't been with a woman in all those centuries. My wish, should you see fit to grant it, Sir, is to have sex with your wife."

Initially shocked by the proposal, the couple looked at one another. The husband looked at his wife and said, "gee, Honey, you know we both now have a fortune, and all those houses and staff… and it’s because of him! What do you think?"

She looked at the genie, who wasn’t unattractive at all; and back at her husband. She mulled it over for a moment more and replied, "you know, you're right. Considering our good fortune, I guess I wouldn't mind… but what about you, Baby? Will you be okay with it?"

“You know I love you, Sweetheart," the husband said. “I'd do the same for you!"

The genie thanked them and assured the couple that, because of their generous granting of his wish, the house would be cleaned and repaired at no cost to them.

The husband sat and waited nervously while the genie went upstairs with his wife. There, they spent the rest of the afternoon enjoying each other immensely.

The genie was insatiable. The woman, shocked by his stamina and skill, was breathless… and was surprised that she never wanted it to end.

After about four hours of non-stop sex, however, they snuggled warmly into each other’s arms. The genie looked directly into her eyes, smiled and asked, "I’m curious to know… what ages are you and your husband?”

“We're actually both 35," she replied, still trying to regain her composure.

“No kidding?" he responded. "Thirty-five years old… and you both still believe in genies?"

:)

Help Gallery problem

Those are excellent questions - but I don't believe you can password-protect individual apps by default. There are two options for you:

1- Use the Secure Folder for your photos. This is essentially a phone within a phone... photos, videos and other data stored in the Secure Folder are not in your regular phone's storage. You can move files in and out of the Secure Folder, which requires additional login to access.

2 - Use a 3rd party app like AppLock to add password protection to each app.

As far as WhatsApp downloads, they have to download somewhere... and the Gallery app automatically detects them. There should be a setting to exclude the Downloads folder from being scanned by the gallery app.

How i download a Stock Rom with a Micro SD Card?

Also you can't install a stock rom via SD card. You need a computer program to do it called Odin. The only way to do what you are asking is to root the device and have a custom recovery installed on the phone. But even rooting you still need a computer.
Unless the phone is already rooted - the OP hasn't answered any questions about what they are trying to do or what the state and status of the phone is.

All of which makes me suspect that my initial guess, that they are trying to bypass factory reset protection, is correct.

Calling an activity from class PintService

Grazie per la risposta. Hai ragione, oltre al codice, che ho anche intuito, sai dov'era il problema? Solo nel filtro intent in particolare nel tag type. Grazie lo stesso, ottima risposta. Buon 2023!!!!
this is an english only site.

use Google Translate
Thanks for the reply. You are right, besides the code, which I also guessed, do you know where the problem was? Only in the intent filter specifically in the type tag. Thanks all the same, great answer. Happy 2023!!!!

Pocket sized Android phone suggestions

You'll probably need to expand your budget to buy a smaller form-factor phone. Those are considered to be limited, niche market phones so they're priced accordingly. Unfortunately the trend with Android phones is to make them larger and thinner even though the overall consumer demand for those two aspects isn't actually there. I know from my perspective I don't want to deal with using a tablet-sized phone but whatever.
You'll find a lot more viable options online though, most retail stores have a rather limited number of options to choose from.

Facing problem with code

It looks like there is a problem with the line findViewById<SeekBar>(R.id.seekBar), which is not being used in the rest of the code.

One possible solution would be to remove this line from the code, as it is not being used and is likely causing the build to fail.

Here is the revised code:

Code:
@RequiresApi(Build.VERSION_CODES.M)
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val rollButton=findViewById<Button>(R.id.rollButton)
    val resultsTextview=findViewById<TextView>(R.id.resultsTextView)

    rollButton.setOnClickListener {
        val rand=Random().nextInt(SeekBar.generateViewId())
        resultsTextview.text=rand.toString()
    }
}

I hope this helps! Let me know if you have any questions.

Android NFCAdapter - Issue with AuthenticateSectorWithKeyA & Hex

It's possible that the issue may be related to the way that the key is being converted to a byte array. Make sure that you are using the correct syntax to convert the hexadecimal string to a byte array.

Here is an example of how you can convert the hexadecimal string to a byte array:

Code:
string hexString = "192386180500";
byte[] keybytes = new byte[hexString.Length / 2];
for (int i = 0; i < keybytes.Length; i++)
{
  keybytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}

Alternatively, you can use the BitConverter.GetBytes method to convert the hexadecimal string to a byte array:

Code:
string hexString = "192386180500";
byte[] keybytes = BitConverter.GetBytes(long.Parse(hexString, System.Globalization.NumberStyles.HexNumber));

Once you have the keybytes array, you can pass it to the AuthenticateSectorWithKeyA method as usual.

It's also a good idea to double-check the value of the key that you are trying to use, as it's possible that there may be an issue with the key itself.

I hope this helps! Let me know if you have any questions.

Filter

Back
Top Bottom