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

Help!: What wrong with this code?

I am a newbie to coding with Android Studio / Korlin.
To get started I am trying to build a simple app that give a Treeview of the internal storage of the device its run on (In the AVD I am using a Pixel 6 Pro - 34.

The below code build and I can create the APK and deploy it, but opening it, it closes instantly.
This is starter code which I will look to build upon once I have a running starting point, but as youll see, that isnt what I presently have (LOL)

MainActivity.KT:

package com.example.treeview

import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

import android.content.Context
import android.os.Bundle
import android.os.Environment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast

import java.io.File
import java.util.ArrayList

class TreeViewActivity : AppCompatActivity() {
private lateinit var recyclerView: RecyclerView
private lateinit var files: MutableList<File>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_tree_view)

recyclerView = findViewById(R.id.recycler_view)
recyclerView.layoutManager = LinearLayoutManager(this)

files = ArrayList()

// Get all files from internal storage
val internalStorage = Environment.getExternalStorageDirectory()
val allFiles = internalStorage.listFiles()
for (file in allFiles) {
if (file.isDirectory()) {
files.add(file)
}
}

// Create a TreeViewAdapter and set it to the RecyclerView
val adapter = TreeViewAdapter(this, files)
recyclerView.adapter = adapter
}

class TreeViewAdapter(private val context: Context, private val files: MutableList<File>) :
RecyclerView.Adapter<TreeViewAdapter.ViewHolder>() {

private val inflater = LayoutInflater.from(context)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = inflater.inflate(R.layout.item_file, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val file = files[position]
holder.textView.text = file.name

// Check if the file is a directory
if (file.isDirectory()) {
holder.imageView.setImageResource(R.drawable.fileinfolder)
} else {
holder.imageView.setImageResource(R.drawable.files)
}

holder.itemView.setOnClickListener {
// Do something when the file is clicked
Toast.makeText(context, "File clicked: " + file.name, Toast.LENGTH_SHORT).show()
}
}

override fun getItemCount(): Int = files.size

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val textView: TextView = itemView.findViewById(R.id.text_view)
val imageView: ImageView = itemView.findViewById(R.id.image_view)
}
}
}

Activity_Tree_View.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@String/no_files_found"
android:visibility="gone" />

</LinearLayout>


Item_file.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@String/no_files_found"
android:visibility="gone" />

</LinearLayout>


Build.Gradle (App):

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.example.treeview'
compileSdk 33

defaultConfig {
applicationId "com.example.treeview"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation platform('androidx.compose:compose-orlin:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
}


Anyone that can help get this to actually run on the AVD I would be very appreciative...

Bill

Getting Samsung Phone To Easily Answeri Calls

EASILY answering a call should be the first priority of a cell phone. With Samsung it clearly is not. A family member has a Samsung Orbit and regularly misses calls because she can't get the "hold & swipe properly" exactly right fast enough. I have a Samsung J2 as a travel phone and often have the same problem.

I found on Youtube a way to change my J2 to answer with just a "press" using Accessability -> Interaction-Dexterity -> Assistant Menu. But that leaves the Assistant Menu "button" visible and in the way. On the J2 there is still an option to cover and hide it. But that is no longer available on the Orbit so the Assistant menu button is annoyingly always there overlaying something on the screen.

I need to replace my primary cell phone (LG) - it seems that Samsung is about the only reliable Android replacement with somewhat decent support. But I don't want that annoying Assistant Menu button constantly overlaying something. Anyone found a way around this with a current Samsung?

[APP] Mountain Landscape Wallpaper - the best live wallpaper 2023?

Mountain Landscape Wallpaper

ic_launcher_msc_free.png
Experience the breathtaking beauty of live wallpapers that bring stunning mountain landscapes to life on your screen.

msc_free_1024_500_2.jpg

Mountain Landscape Live Wallpapers immerse you in the serene beauty of heavenly landscapes, where the grandeur of mountains and the depth of lakes blend in perfect harmony. Enjoy the captivating beauty of nature with Mountain Landscape Live Wallpapers.

msc_phone_rotate.jpg

Feel the tranquility of this idyllic spectacle, where majestic pink sakura delicately hangs over picturesque lakes, creating a sense of serenity and peace.

msc_phone_1.jpg

Now, with the Mountain Landscape Live Wallpapers app, you can meditate anywhere and anytime, combining the pleasure of observing enchanting mountain landscapes with the soothing sounds of nature (quick double-tap anywhere on the screen to play/pause the sound).

msc_phone_sound.jpg

The automatic day and night mode system allows you to enjoy the app at dawn, noon, in the radiance of sunset, and at any time of the day as the lighting changes.

msc_phone_2.jpg

Key Features:
• Detailed customization options
• Automatic background change over time
• Nature sounds and nightingale's melody (quick double-tap to toggle sound playback)
• Animated sky, clouds, and rainbow
• Dynamic reflection of the sky in lakes
• Moving 3D camera (tilt your device for a 3D effect)
• Animated butterflies
• Large air balloons
• Shimmering stars and meteors
• Battery-efficient performance
• High-quality textures
• 3D parallax effect
• Three types of animated birds


Immerse yourself in the beauty of mountain landscapes with Mountain Landscape Live Wallpapers. Let this app turn your device into a window to the magnificent world of mountains and lakes. Allow yourself to enjoy the glitter, shine, and beauty of live wallpapers wherever you are.


Help Download images got permenantly deleted without me doing anything, Help!

I have a Huawei Mediapad tablet M5 lite 10. I left it to charge through the night (it wasn't powered off, was just closed) and the next day when I opened it and went to gallery my downloads were in the process of being deleted! They were turning into blank images and going to the recently deleted folder, and the weirdest thing was, they were also being permenantly deleted? I'm dumbstruck because they deleted ALL of my downloads (I had 834) except a few downloads left over, maybe 6 pictures. People suggested turning auto-delete and automatic storage cleaner option off, but I can't find those options anywhere on my device. I also did not clear my storage recently. I did not back up my photos anywhere. Why did this happen and how can I prevent this from happening again? Can I get back my photos? Help!


Edit: I have just realised that my downloaded documents and audios are gone too! It seems that all of the files I downloaded from the web are permenantly deleted, why did this happen???

Problem with APK file

Please ignore this post. The problem seems to have gone away.
but I can’t find a way to delete it.

Noobie here. I installed Android Studio flamingo and followed a couple of tutorials on youtube. My latest effort involves experimenting with the Recyclerview. I have tried running it on a couple of different virtual devices and it runs OK until I try to launch the activity that has the Recyclerview. Then I get this error:

Failed to measure fs-verity, errno 1: /data/app/~~pmpCKyqulePUBHTy7ke96g==/com.example.recyclerdemo-480zG4iexej-Wk4snRDEjQ==/base.apk

So far I have not been able to find enough info about APK files to even know where to look.

Can someone help please? Much appreciated.

Is there any sign before a battery explode?

I have heard about battery in smartphones exploded, but I did not study the details.
Now, I am going to replace my battery, but since the model is a bit old, there is no way to replace it with the original battery, so chances are I am probably getting a generic battery or even a counterfeit one from a shop that fixes smartphone,

Is there any sign before a battery explode, or could it happen without any sign? Then it would be so dangerous!

Samsung A14 5G random 'red alert sound'

That's exactly what it is. A sound very similar to a Star Trek Red Alert from the original series. this phone randomly makes this 'whoop whoop' alert sound once, and nothing is on the screen. last time it was when it was charging, today it just did it in my pocket. Nothing is listed in recent notifications and there is no such sound in the list of 'notification sounds'. I can't think of any app that makes this particular sound and I'm quite involved in what I allow to make noise on a smartphone (only calls, texts and emails, everything else is set to either block notifications (I hate status bar clutter) or silent/minimized.)) There should only be three items that make sound and with sounds I select (thanks to whomever told me a month or so back to move any downloaded sounds into the 'notifications' folder). None involve any red alert sound. I got emergency SOS and Wireless Emergency Alerts all turned off. It's not a disconnected from watch sound as my watch remained connected.

Is anyone familiar with this particular anomaly with Samsung's modern phones? Also, it's not a low battery sound as the phone is still 90% charged.

Samsung Eco System

Hi folks,

New here so forgive me if this isn't in the right area of the forum. I'm all Samssung in terms of Android and recently was gifted a Tab s8+ - great device, but I'm told I can get more out of it? I hear about this Eco system and have watched some videos on YouTube but it still baffles me so coming to the experts here!

Can I use my Note 20 Ultra as a second device/screen i.e. drag files across like I would when I use the tab as a secondary extended or just secondary screen with my laptop?
I tried Samsung Flow and both devices are on the same WiFi but the smart view option allowing me to use my phone on my tab only work when I switch the WiFi from on my tablet to the phones hotspot. Why is this? is this normal?
Samsung's Dex - what is the benefit of using the tab in this mode as opposed to how it is in regular mode?
I have some Galaxy buds Live, should they be able to connect via blue tooth to both phone and tablet?
I'm also looking at potentially purchasing a smart watch (samsung model) and I hear there is a new model. Has anyone tried it? is it worth the money? I don't want to overspend for the sake of it.

Any other tips and tricks you can share are much appreciated :)

Mountain Landscape Wallpaper

Mountain Landscape Wallpaper


ic_launcher_msc_free.png
Experience the breathtaking beauty of live wallpapers that bring stunning mountain landscapes to life on your screen.


msc_free_1024_500_2.jpg

Mountain Landscape Live Wallpapers immerse you in the serene beauty of heavenly landscapes, where the grandeur of mountains and the depth of lakes blend in perfect harmony. Enjoy the captivating beauty of nature with Mountain Landscape Live Wallpapers.

msc_phone_rotate.jpg

Feel the tranquility of this idyllic spectacle, where majestic pink sakura delicately hangs over picturesque lakes, creating a sense of serenity and peace.


msc_phone_1.jpg

Now, with the Mountain Landscape Live Wallpapers app, you can meditate anywhere and anytime, combining the pleasure of observing enchanting mountain landscapes with the soothing sounds of nature (quick double-tap anywhere on the screen to play/pause the sound).

msc_phone_sound.jpg

The automatic day and night mode system allows you to enjoy the app at dawn, noon, in the radiance of sunset, and at any time of the day as the lighting changes.

msc_phone_2.jpg

Key Features:
• Detailed customization options
• Automatic background change over time
• Nature sounds and nightingale's melody (quick double-tap to toggle sound playback)
• Animated sky, clouds, and rainbow
• Dynamic reflection of the sky in lakes
• Moving 3D camera (tilt your device for a 3D effect)
• Animated butterflies
• Large air balloons
• Shimmering stars and meteors
• Battery-efficient performance
• High-quality textures
• 3D parallax effect
• Three types of animated birds


Immerse yourself in the beauty of mountain landscapes with Mountain Landscape Live Wallpapers. Let this app turn your device into a window to the magnificent world of mountains and lakes. Allow yourself to enjoy the glitter, shine, and beauty of live wallpapers wherever you are.


Tracfone Moto 5g Stylus (2021) issue with texting

Sometimes when I try to send a simple text, I get this pop up (see below). If I click the "send text as SMS/MMS" it will work. Does anyone else get this message? Is there a way to make my phone default to the send as SMS? I'm not sure why it does this sometimes but not all the time. I don't want to leave my mobile data on all the time but would love to stop getting this message. Thanks
IMG_20230609_104745842.jpg

Apps how to read files with NDK

Specifically, I am working on integrating StockFish with Android. The significant part of SF is its syzygy - directory where its tablebase is stored.These files are huge (about 1GB) and I do not want to include them in the program body. I want to allow the user to download them and specify their directory so that SF can use them. SF loads one of the files within this directory, one at a time, as needed.
StockFish is a shared library written in C++.
How can this be done with the current APIs?

Google Photos auto backup

Hi all, I have this Samsung A23 and my google photos wasn't backing up my photos for almost a year due to lack of space in the cloud. Recently I signed up google one and the backup of my photos started working again... But the photos are not being backed up automatically as it was before. I mean, when I open the Photos app, it starts backing up. But if I close the app, the backup just stops. As far as I know, I never had to open the Photos app to backup. My photos used to backup almost instantly. But this is not happening anymore. Any clues? Maybe some configuration out of the Photos app?

Thanks for the help!

Remote Spyware?

OK, I'm not technical AT ALL so please excuse me.

Is it possible for a device to be infected remotely with spyware via a photo/video sent via a chat site like Snapchat/Kik?

I have a few anti-virus apps - Norton paid for, AVG and Malwarebytes. These should catch anything nasty right?

Apps Android studio flamingo asking for compileSdkVersion to be set to 34

I have an app that is built using capacitorjs. Now I have updated the capacitor js version to be 5 along with android studio updated with flamingo. Since the update, I get below error:

Dependency 'androidx.core:core:1.12.0-alpha05' requires libraries and applications that
depend on it to compile against version 34 or later of the
Android APIs.

:app is currently compiled against android-33.

Also, the maximum recommended compile SDK version for Android Gradle
plugin 8.0.0 is 33.

Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 34, then update this project to use
compileSdk of at least 34.

Note that updating a library or application's compileSdk (which
allows newer APIs to be used) can be done separately from updating
targetSdk (which opts the app in to new runtime behavior) and
minSdk (which determines which devices the app can be installed
on).

I now updated compileSdkVersion to 34 in :app build.gradle file. and it works fine.

Since 34 is still in dev, will it cause problems for my app? Should I be doing this? Any suggestions?

Setting up a RecyclerView

Noobie here.
I am working on my first app using a Recyclerview. I have an Adapter (SongsAdapter) to make it work. This is my code for the Adapter>

package com.example.musiclyrics;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.snackbar.Snackbar;

public class SongsAdapter extends RecyclerView.Adapter<SongsAdapter.ViewHolder> {
private Context context;
private Cursor cursor;

public SongsAdapter(Context context) {
this.context = context;
}
public void setCursor(Cursor cursor) {
this.cursor = cursor;

notifyDataSetChanged();
cursor.moveToFirst(); // Move cursor to the first row
ViewHolder holder = onCreateViewHolder(null, 0);

onBindViewHolder(holder, 0);
}

@override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.songs_layout, parent, false);
return new ViewHolder(view);
}

@override
public void onBindViewHolder(ViewHolder holder, int position) {

if (cursor != null && cursor.moveToPosition(position)) {

int songNameIndex = cursor.getColumnIndex("SONG_NAME");
int artistIndex = cursor.getColumnIndex("ARTIST");
int durationIndex = cursor.getColumnIndex("DURATION");
int songIdIndex = cursor.getColumnIndex("KEY_ID");

String songName = cursor.getString(songNameIndex);
String artist = cursor.getString(artistIndex);
String duration = cursor.getString(durationIndex);
final int songId = cursor.getInt(songIdIndex);

holder.songNameTextView.setText(songName);
holder.artistTextView.setText(artist);
holder.durationTextView.setText(duration);

holder.itemView.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
// MainActivity.varCurrentSong = songId;
// Handle the click event
}
});
}
cursor.moveToNext()

}

@override
public int getItemCount() {
return (cursor != null) ? cursor.getCount() : 0;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
TextView songNameTextView;
TextView artistTextView;
TextView durationTextView;

public ViewHolder(View itemView) {
super(itemView);
songNameTextView = itemView.findViewById(R.id.txt_songName);
artistTextView = itemView.findViewById(R.id.txt_Artist);
durationTextView = itemView.findViewById(R.id.txt_Duration);
}
}
}

At runtime this appears to work OK but the screen only shows the first record. I have tried about 50 different ideas and suggestions on how to make this work to no avail. Can someone help me out please?
Thanks

Nokia c100 hard reset/pattern bypass

I have a Nokia c100 that has a pattern lock. I need to be able to get in to the phone or hard reset. data preservation not necessary. I tried using the boot loader (holding down power/volume up or/and down, all combinations), nothing. All I got was a small white “fast boot mode” on bottom left of screen. Is this phone trash unless you know the code? I’ve seen a few videos saying it’s impossible, but wanted to see what other people think.
Thanks for all the help!
-Sam

Separated Dad needs to give 4year old and 7 year old a tablet to video chat with me

I am wondering if you guys have any suggestions as to what I can do to prevent them from opening any other aps. I don't want them to download or visit anything on that tablet. I want them to have direct communication with me. Luckily the mom doesn't have a problem with this.

I use Nova Launcher, have used it for years, but its always the same settings for my business. I know I can lock the screen from moving apps etc...
Do you guys know if there is a place, dedicated to child safety features?

Basically I just want to have 1 button on the main screen for them to call or video call (i guess 2 buttons) and that's it. I can do that part. but not child proofing

Filter

Back
Top Bottom