Trying to record audio in the background, File1 delete problem

Okay can you make this app and give me aia file for Android 13??
Please i am losing my time​:smiling_face_with_tear::smiling_face_with_tear::smiling_face_with_tear:
This very important for me.can you help me??or can you give me block example???

While asking permission, use if then logic

If the sdk version greater than 33
Ask record audio
Else
Ask all the 3 permissions

And store the file in ASD

ASD mean??i am new.
Please can you give me block example or Aia file?:heart:thanks

go through with this thread and Will come to know what should be done

I don’t want waste more time..i want hire one developer who can make this for Android 13..suggest me one mit app developer


ChatGPT said that,microphone permission isn’t possible allowed all the time so i cannot make background record for Android 13???
Please give me real information.

I now joined your 2 threads
Please do not start a new thread with the same question,
You forgot to follow my suggestions

Taifun

Sometimes AI gives misleading information
See again

Taifun

this problem solved but it not working in android
version 13

You did not fix the issues from your latest screenshot

Taifun

leave this screenshot and tell me it possible or not.can i make background recorder for android 13?

My guess was, that it will not work for newer Android versions, but Gemini had another opinion. . See again Not working for background soundRecorder - #5 by Taifun

You previously said, it worked? Which Android version was that? It would help to fix the errors in the screenshot...

Taifun


The final block of my code is functioning well on Android 10. However, on Android 13, there is an intermittent issue with microphone permissions. While the app records audio correctly when running in the foreground, the microphone stops capturing sound after the app is removed from RAM or the device is locked. As a result, recordings are created without any audio.

It looks like ChatGPT is correct

Taifun

have not any way?

how can working whatsapp or others calling app?

Use your solution on older devices
Say thank you to Google for protecting us from the evil

Where exactly do these apps record audio in the background?
It still might be possible for system apps

For further questions don't hesitate to ask AI for help, I currently have nothing more to add to the discussion

Taifun

okay i am leaving mit app..

I now asked ChatGPT for you

I would like to write an Android app for my Android14 device, which will allow me to record audio in the background while the app is not open. Can you help me with some code snippets for Java?

Please find below the answer.
You could take the answer and write your own extension to provide a solution for App Inventor

Taifun


Sure! Creating an Android app that records audio in the background on Android 14 (API level 34) requires careful handling of permissions and foreground services due to stricter background task limitations. Below is a basic setup using Java that:

  1. Requests necessary permissions.
  2. Starts a Foreground Service to record audio.
  3. Records audio while the app is not in the foreground.

1. Add Permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Add your service:

<application ...>
    <service
        android:name=".AudioRecordService"
        android:foregroundServiceType="microphone"
        android:exported="false" />
</application>

2. Request Permissions in MainActivity.java

public class MainActivity extends AppCompatActivity {

    private static final int PERMISSION_CODE = 200;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (!checkPermissions()) {
            requestPermissions();
        }

        findViewById(R.id.startButton).setOnClickListener(v -> {
            Intent intent = new Intent(this, AudioRecordService.class);
            ContextCompat.startForegroundService(this, intent);
        });
    }

    private boolean checkPermissions() {
        return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
    }

    private void requestPermissions() {
        ActivityCompat.requestPermissions(this, new String[]{
                Manifest.permission.RECORD_AUDIO
        }, PERMISSION_CODE);
    }
}

3. Create AudioRecordService.java

public class AudioRecordService extends Service {

    private MediaRecorder recorder;
    private File audioFile;

    @Override
    public void onCreate() {
        super.onCreate();
        startForeground(1, createNotification());
        startRecording();
    }

    private Notification createNotification() {
        NotificationChannel channel = new NotificationChannel(
                "record_channel",
                "Audio Recorder",
                NotificationManager.IMPORTANCE_LOW
        );
        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(channel);

        return new NotificationCompat.Builder(this, "record_channel")
                .setContentTitle("Recording audio")
                .setSmallIcon(android.R.drawable.ic_btn_speak_now)
                .build();
    }

    private void startRecording() {
        try {
            audioFile = new File(getExternalFilesDir(null), "recorded_audio.mp3");

            recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            recorder.setOutputFile(audioFile.getAbsolutePath());
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
            recorder.prepare();
            recorder.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (recorder != null) {
            recorder.stop();
            recorder.release();
        }
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}

4. Layout XML (e.g., activity_main.xml)

<Button
    android:id="@+id/startButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start Recording" />

Important Notes:

  • Foreground service is mandatory for microphone access in the background.
  • Android 14 introduces restrictions on long-running background tasks, so this approach complies with those by using a foreground service.
  • Test on a real device and ensure your app targets API level 34 or higher.

Would you like to add stop recording or save/share functionality too?

1 Like