'App works on Android studio but not on device
I made an app to help my elderly father to share photos from whatsapp to Google photos.
I learned programming to do it so it's my first program... Took a while but it runs in android studio and on many phones -
Just not on my father's ! :-(
I tried to update he's phone but it didn't work.
What do i need to check so i can find out?
EDIT:
sorry - i am such a beginner that i don't even know what to look for to upload...
i am attaching the "about software" of my fathers non-working phone:
and the "about software" of my son's phone - which works:
and this is the android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.beser.qs3">
<uses-permission android:name="anandroid.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="אריאל, תשמור לי"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.QS3">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.qs3.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
<activity
android:name="com.beser.qs3.MainActivity"
android:label=" "
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and this line:
@RequiresApi(Build.VERSION_CODES.O)
also, here is my wife's phone error log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.beser.qs3/com.beser.qs3.MainActivity}: java.lang.IllegalArgumentException: fromIndex(0) > toIndex(-1)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3322)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3471)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2058)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.IllegalArgumentException: fromIndex(0) > toIndex(-1)
at java.util.ArrayList.subListRangeCheck(ArrayList.java:1018)
at java.util.ArrayList.subList(ArrayList.java:1008)
at com.beser.qs3.data_list.load(data_list.kt:69)
at com.beser.qs3.MainActivity.onCreate(MainActivity.kt:40)
at android.app.Activity.performCreate(Activity.java:7916)
at android.app.Activity.performCreate(Activity.java:7903)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3297)
... 11 more
EDIT2:
here is the onCreate method:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE),
1)
}
setContentView(R.layout.activity_main)
myDataset = data_list().load()
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view_id)
recyclerView.adapter = RvAdaptor(myDataset,this,applicationContext)
recyclerView.layoutManager = GridLayoutManager(applicationContext,2)
}
and the datalist object:
@RequiresApi(Build.VERSION_CODES.O)
fun load(): MutableList<Image_data> {
var imagelist = mutableListOf<Image_data>()
var i = 0
var j = 0
var dir : File
var files : List<File>
var file: File
var max : Int
var image_date: Date
var slot_date: Date
var test_max = 0
dir = File("/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images")
if (dir.isDirectory){
files = dir.listFiles().reversed()
max = files.lastIndex
if (max > 50) max = 50
while (i <= max) {
file = files[i]
image_date = Date(file.lastModified())
slot_date = image_date
j = 0
test_max = imagelist.lastIndex
if (test_max != -1) slot_date = imagelist[0].date
//(testModified.after(lastModified)) = dont put it here
// (j = test_max) = reached end of the line (+1) -> get out with this j (=end of line +1)
// (test_max = -1) = empty list = get out with j = 0
while ((slot_date.after(image_date)) and (j <= test_max) and (test_max != -1)) {
j++
if (j<=test_max) slot_date = imagelist[j].date
}
if (file.isFile) imagelist.add(j, Image_data(file.absolutePath, image_date, false))
i++
}
}
i = 0
dir = File("/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video")
if (dir.isDirectory) {
files = dir.listFiles().reversed()
max = files.lastIndex
if (max > 50) max = 50
while (i <= max) {
file = files[i]
image_date = Date(file.lastModified())
slot_date = image_date
j = 0
test_max = imagelist.lastIndex
if (test_max != -1) slot_date = imagelist[0].date
//(testModified.after(lastModified)) = dont put it here
// (j >= test_max) = reached end of the line (+1) -> get out with this j (=end of line +1)
// (test_max = -1) = empty list = get out with j = 0
while ((slot_date.after(image_date)) and (j <= test_max) and (test_max != -1)) {
j++
if (j<=test_max) slot_date = imagelist[j].date
}
if (file.isFile) imagelist.add(j, Image_data(file.absolutePath, image_date, false))
i++
}
}
return imagelist.subList(0,min(50,imagelist.lastIndex))
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
