Storing data in Firebase Realtime Database - java

I have a problem with storing data in the Firebase Realtime Database. There are no errors but nothing is stored in the database. I have tried with different guides, tutorial (on yt) posts (found here) but none of them worked. Is there a working way that allows me to solve this problem? Thanks in advance everyone and sorry if my English is not perfect.
public void registration() {
if(!validation())
return;
final ProgressDialog progressDialog = new ProgressDialog(RegisterActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Creating account...");
progressDialog.show();
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
DatabaseReference reff = mDatabase.getReference();
user = new User();
String tableName = "Users";
Map<String, String> userMap = new HashMap<String, String>();
//register user in firebase
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
user.setUser(mFullName.getText().toString().trim());
user.setEmail(mEmail.getText().toString().trim());
userMap.put(fullName, email);
String currentUser = mAuth.getCurrentUser().getUid();
reff.child(tableName).child(currentUser).setValue(userMap);
//The following line make app crush
reff.setValue(userMap, new Firebase.CompletionListener() {
#Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError != null) {
System.out.println("Data could not be saved. " + firebaseError.getMessage());
} else {
System.out.println("Data saved successfully.");
}
}
});
Toast.makeText(RegisterActivity.this, "User successful created", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MenuActivity.class));
finish();
progressDialog.dismiss();
}
else {
Toast.makeText(RegisterActivity.this, "Error! " +
task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
User.java
public class User {
private String user, email, photoUrl, Uid;
public User() { }
public User(String uid, String user) {
Uid = uid;
this.user = user;
}
public User(String user) {
this.user = user;
}
public User(String user, String email, String photoUrl, String uid) {
this.user = user;
this.email = email;
this.photoUrl = photoUrl;
Uid = uid;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getUid() {
return Uid;
}
public void setUid(String uid) {
Uid = uid;
}
}
The error is:
com.google.firebase.database.DatabaseException: Failed to parse node with class class com.example.xxxxxxxx.activities.RegisterActivity$4$1
at com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:103)
at com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:28)
at com.google.firebase.database.snapshot.PriorityUtilities.parsePriority(PriorityUtilities.java:39)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:199)
at com.example.xxxxxxxx.activities.RegisterActivity$4.onComplete(RegisterActivity.java:160)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
logcat:
2021-01-02 17:07:36.549 20191-20213/com.example.inbioaiqua W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-01-02 17:07:36.557 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.562 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.574 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.580 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.592 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.601 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.611 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.617 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.625 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.631 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.639 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.645 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.657 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.663 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.673 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.680 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.689 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.693 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.706 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.713 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.722 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.729 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.738 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:36.849 20191-20213/com.example.inbioaiqua D/FirebaseAuth: Notifying id token listeners about user ( 7LOLWRPcBhVqHm98BVHzpI5FkDG2 ).
2021-01-02 17:07:36.849 20191-20213/com.example.inbioaiqua D/FirebaseAuth: Notifying auth state listeners about user ( 7LOLWRPcBhVqHm98BVHzpI5FkDG2 ).
2021-01-02 17:07:36.874 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.046 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.260 20191-20214/com.example.inbioaiqua D/EGL_emulation: eglMakeCurrent: 0x9eb85360: ver 2 0 (tinfo 0x9eb831a0)
2021-01-02 17:07:37.260 20191-20214/com.example.inbioaiqua W/OpenGLRenderer: Points are too far apart 4.000001

So in your code:
reff.child(tableName).setValue(user)
Here you are trying to set a value for a node that already has branches and Firebase database does not allow that, so what you can do is create another node in the "Users" table to store users. For example:
reff.child(tableName).child("User1"). setValue(user);
Here "User1" is just to label the field and can be a simple integer such as "1" too.

Your code:
reff.setValue(userMap, new Firebase.CompletionListener()
Again, you are trying to set a value of a node with branches which in your case it's the main branch and Firebase database don't allow that. So what you can do is create another node in the reff.
reff.child(tableName).child(YOUR_DESIRED_CHILD).setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>()
Here YOUR_DESIRED_CHILD is field name for your Users childs.
And it should work just fine.

You are passing to the "setValue()" method a CompletionListener object, an option which is not available anymore. To add the user, please use the following lines of code:
reff.setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d("TAG", "User added successfully!");
} else {
Log.d("TAG", task.getException().getMessage()); //Don't ignore potential errors!
}
}
});
And comment or remove the lines that you are using now.

Your DatabaseReference is not initialized, so use the below code on top.
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
DatabaseReference reff = mDatabase.getReference();
And add onComplete listener to setValue().
reff.child(tableName)
.child(currentUser)
.setValue(userMap, new Firebase.CompletionListener() {
#Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError != null) {
System.out.println("User data save failure." + firebaseError.getMessage());
} else {
System.out.println("User data save successful.");
progressDialog.dismiss();
startActivity(new Intent(getApplicationContext(), MenuActivity.class));
finish();
}
}
});

Related

Camera2 Api showing white screen on camera only in android 28 pie device

I am using camera2 api and it is working fine on pre Pie android version but it is showing white screen when opening camera on android pie devices. I have checked on emulator, A10 devices.
Kindly help me
app build.gradle
compileSdkVersion 29
defaultConfig {
applicationId "xxx.xxx.xxx.xxx"
minSdkVersion 23
targetSdkVersion 29
}
I have also declared permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera2.full" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Here is the logs:
2020-01-06 21:43:04.354 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:04.960 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1246ms; Flags=1, IntendedVsync=863946795696, Vsync=864596795670, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=864606099000, AnimationStart=864606243100, PerformTraversalsStart=864606749200, DrawStart=865124397700, SyncQueued=865125104600, SyncStart=865126372900, IssueDrawCommandsStart=865126580100, SwapBuffers=865128343100, FrameCompleted=865194693500, DequeueBufferDuration=135000, QueueBufferDuration=1984000,
2020-01-06 21:43:04.995 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:05.037 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:05.094 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:05.229 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=853ms; Flags=0, IntendedVsync=864625292593, Vsync=865241959235, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=865246522400, AnimationStart=865246651100, PerformTraversalsStart=865257381400, DrawStart=865345430100, SyncQueued=865345513800, SyncStart=865347226700, IssueDrawCommandsStart=865347728400, SwapBuffers=865348734300, FrameCompleted=865480205200, DequeueBufferDuration=5031000, QueueBufferDuration=9624000,
2020-01-06 21:43:05.256 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:08.829 4923-5340/com.iris.idrs.smartcapture I/CConversion: Creating output document: /data/user/0/com.iris.idrs.smartcapture/cache/temp/output.pdf
2020-01-06 21:43:08.899 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:08.965 4923-5012/com.iris.idrs.smartcapture D/OpenGLRenderer: endAllActiveAnimators on 0xbbc70100 (RippleDrawable) with handle 0xbfb7f490
2020-01-06 21:43:09.018 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:13.564 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:16.035 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:16.352 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.353 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.394 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.424 4923-4923/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) identical 1 line
2020-01-06 21:43:16.425 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.474 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.602 4923-4923/com.iris.idrs.smartcapture W/StaticLayout: maxLineHeight should not be -1. maxLines:2 lineCount:2
2020-01-06 21:43:16.878 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1553ms; Flags=1, IntendedVsync=875568052075, Vsync=876284718713, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=876287357500, AnimationStart=876287533900, PerformTraversalsStart=876287961000, DrawStart=876918332800, SyncQueued=876919028800, SyncStart=876926725800, IssueDrawCommandsStart=876946153900, SwapBuffers=876951883200, FrameCompleted=877129627800, DequeueBufferDuration=132000, QueueBufferDuration=1326000,
2020-01-06 21:43:16.880 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:17.027 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:31.548 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:43:31.551 4923-4961/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) FinalizerDaemon identical 7 lines
2020-01-06 21:43:31.552 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:43:42.533 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=902633, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:43.110 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.283 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=1026ms; Flags=1, IntendedVsync=902505438851, Vsync=902772105507, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=902785072800, AnimationStart=902785162200, PerformTraversalsStart=902785352700, DrawStart=903355162800, SyncQueued=903361009100, SyncStart=903363119200, IssueDrawCommandsStart=903363531400, SwapBuffers=903370175800, FrameCompleted=903534179400, DequeueBufferDuration=64210000, QueueBufferDuration=23339000,
2020-01-06 21:43:43.283 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.287 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=902692, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:43.793 4923-4923/com.iris.idrs.smartcapture W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
2020-01-06 21:43:43.794 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 75 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:44.175 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:43.376 4923-4923/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) identical 7 lines
2020-01-06 21:43:43.376 4923-4923/com.iris.idrs.smartcapture W/ViewRootImpl[CConversionActivity]: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=902692, downTime=902633, deviceId=-1, source=0x101 }
2020-01-06 21:43:47.715 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:48.918 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:49.436 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346907648 ==== Initialization complete
2020-01-06 21:43:49.722 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: Background concurrent copying GC freed 2020(149KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 9MB/15MB, paused 1.459ms total 272.922ms
2020-01-06 21:43:49.772 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346907968 ==== Initialization complete
2020-01-06 21:43:49.802 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346900368 ==== Initialization complete
2020-01-06 21:43:49.888 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:50.151 4923-4923/com.iris.idrs.smartcapture E/CCaptureActivity: The camera encountered an error: 4
2020-01-06 21:43:50.198 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:50.266 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: NativeAlloc concurrent copying GC freed 5180(277KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 23MB/29MB, paused 1.626ms total 100.079ms
2020-01-06 21:43:52.168 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 45 frames! The application may be doing too much work on its main thread.
2020-01-06 21:43:52.961 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:53.167 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:43:54.084 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:04.197 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 57 frames! The application may be doing too much work on its main thread.
2020-01-06 21:44:08.168 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:44:08.172 4923-4961/com.iris.idrs.smartcapture I/chatty: uid=10088(com.iris.idrs.smartcapture) FinalizerDaemon identical 7 lines
2020-01-06 21:44:08.172 4923-4961/com.iris.idrs.smartcapture W/System: A resource failed to call destroy.
2020-01-06 21:44:51.860 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=973ms; Flags=1, IntendedVsync=971138216354, Vsync=971588216336, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=971604458900, AnimationStart=971604599700, PerformTraversalsStart=971605101500, DrawStart=972056683900, SyncQueued=972057201200, SyncStart=972057276400, IssueDrawCommandsStart=972057444900, SwapBuffers=972059625400, FrameCompleted=972111965000, DequeueBufferDuration=621000, QueueBufferDuration=1859000,
2020-01-06 21:44:51.861 4923-4923/com.iris.idrs.smartcapture I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
2020-01-06 21:44:51.951 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:51.998 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
2020-01-06 21:44:52.081 4923-5012/com.iris.idrs.smartcapture I/OpenGLRenderer: Davey! duration=732ms; Flags=0, IntendedVsync=971597490482, Vsync=972097490462, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=972112842700, AnimationStart=972112945800, PerformTraversalsStart=972114580600, DrawStart=972248683500, SyncQueued=972248764000, SyncStart=972251096700, IssueDrawCommandsStart=972253391700, SwapBuffers=972254863000, FrameCompleted=972332311000, DequeueBufferDuration=136000, QueueBufferDuration=17695000,
2020-01-06 21:44:52.081 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
I/CCaptureActivity: Capture size selected: 960 x 1280
2020-01-06 21:44:55.241 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346895328 ==== Initialization complete
2020-01-06 21:44:55.286 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346899568 ==== Initialization complete
2020-01-06 21:44:55.320 4923-4923/com.iris.idrs.smartcapture I/CCapture: Instance 3346553712 ==== Initialization complete
2020-01-06 21:44:55.846 4923-4964/com.iris.idrs.smartcapture I/rs.smartcaptur: NativeAlloc concurrent copying GC freed 66(54KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 23MB/29MB, paused 1.424ms total 473.768ms
2020-01-06 21:44:55.938 4923-5012/com.iris.idrs.smartcapture D/EGL_emulation: eglMakeCurrent: 0xe2ee8a20: ver 3 0 (tinfo 0xdee597c0)
I have also noticed sometimes it work only first time and then second time it shows white screen.
Here is the capture activity code
public class CCaptureActivity extends AppCompatActivity
{
/**
* Activity creation handler.
* #param argSavedInstanceState Instance saved during previous session (unused).
*/
#Override
protected void onCreate ( final Bundle argSavedInstanceState )
{
super.onCreate ( argSavedInstanceState );
// Fetch the UI elements which will be updated programatically during activity runtime.
setContentView ( R.layout.activity_capture );
m_objDocumentAreaView = (CDocumentAreaView) findViewById ( R.id.corners_view );
m_objCameraView = (CCameraView) findViewById ( R.id.camera_view );
// Select the camera to use and initialize it as well as its preview and the needed handlers.
m_objPreviewImageListener = new CCaptureAnalysisRunner ();
setupCameraViewListener ();
setupCameraStatusCallback ();
m_objPreviewThread = new HandlerThread ( "PreviewUpdate" );
m_objCameraManager = (CameraManager) getSystemService ( Context.CAMERA_SERVICE );
getCamera ();
m_objHardwareStatus.onCreate ( this );
}
#Override
protected void onResume ()
{
super.onResume ();
m_objHardwareStatus.onResume ();
m_objIdrsCapture.onResume ( this );
openCamera ();
}
#Override
protected void onPause ()
{
m_objIdrsCapture.onPause ();
m_objHardwareStatus.onPause ();
closeCamera ();
super.onPause ();
}
private class CCaptureAnalysisRunner implements ImageReader.OnImageAvailableListener
{
public void onImageAvailable ( final ImageReader argImageReader )
{
final Image objCapturedImage = argImageReader.acquireLatestImage ();
// The image may be null sometimes, so skip processing in such case
if ( null != objCapturedImage )
{
final boolean bDocumentExposureOk = m_objHardwareStatus.isExposureOk ();
final boolean bCameraFocusSet = ( bDocumentExposureOk && m_objHardwareStatus.isFocusSet ());
final boolean bDeviceStable = ( bCameraFocusSet && m_objHardwareStatus.isDeviceStable ());
final CIdrsCapture.CWorker objWorker = (( bDeviceStable || m_bForceCapture ) ? m_objIdrsCapture.tryLock () : null );
if ( objWorker != null )
{
Log.i ( "CCaptureActivity", "An image is available and will be processed" );
objWorker.setCurrentCapture ( objCapturedImage );
objCapturedImage.close ();
AsyncTask.execute ( new Runnable ()
{
#Override
public void run ()
{
onImageAnalysisCompleted ( objWorker, objWorker.detectDocumentCorners ());
}
});
}
else
{
objCapturedImage.close ();
}
// In any case, the indicators must be updated
runOnUiThread ( new Runnable ()
{
#Override
public void run ()
{
if ( m_objDocumentAreaView.reduceIntensity ())
{
m_objCornersFlag.setChecked ( false );
m_objAreaFlag.setChecked ( false );
}
m_objExposureFlag.setChecked ( bDocumentExposureOk );
m_objFocusFlag.setChecked ( bCameraFocusSet );
m_objStabilityFlag.setChecked ( bDeviceStable );
m_objDocumentAreaView.invalidate ();
m_objExposureFlag.invalidate ();
m_objFocusFlag.invalidate ();
m_objStabilityFlag.invalidate ();
}
});
}
}
private void onImageAnalysisCompleted (final CIdrsCapture.CWorker argWorker, final CIdrsCapture.DocumentCorners argDocumentCorners)
{
if ( ! m_objIdrsCapture.isCaptureSelected ())
{
runOnUiThread(new Runnable()
{
#Override
public void run()
{
m_objCornersFlag.setChecked(argDocumentCorners.bCornersFound);
m_objAreaFlag.setChecked(argDocumentCorners.bTargetAreaOk);
if (argDocumentCorners.bCornersFound)
{
m_objDocumentAreaView.setDetectedCorners(argDocumentCorners.xiCorners, argDocumentCorners.bTargetAreaOk);
}
m_objDocumentAreaView.invalidate();
m_objCornersFlag.invalidate();
m_objAreaFlag.invalidate();
}
});
try
{
if (( argDocumentCorners.bCornersFound && argDocumentCorners.bTargetAreaOk ) || m_bForceCapture )
{
final int iCaptureQuality = m_bForceCapture ? 100 : argWorker.evaluateQuality ();
boolean bCurrentCaptureSelected = false;
boolean bCurrentCaptureForced = false;
synchronized ( m_objCaptureSelectionLock )
{
if (iCaptureQuality >= CAPTURE_QUALITY_THRESHOLD && ! m_objIdrsCapture.isCaptureSelected ())
{
argWorker.selectCapture();
bCurrentCaptureSelected = true;
if ( m_bForceCapture )
{
bCurrentCaptureForced = true;
m_bForceCapture = false;
}
}
}
// Update the controls only if no capture are currently selected or if this capture is the one selected
final boolean bCurrentCaptureSelectedFinal = bCurrentCaptureSelected;
final boolean bCurrentCaptureForcedFinal = bCurrentCaptureForced;
if ( bCurrentCaptureSelected || ! m_objIdrsCapture.isCaptureSelected ())
{
runOnUiThread(new Runnable()
{
#Override
public void run()
{
if ( ! bCurrentCaptureForcedFinal )
{
m_objImageQualityBar.setProgress(iCaptureQuality);
}
if ( bCurrentCaptureSelectedFinal )
{
m_objDocumentAreaView.setCaptureValidated();
}
m_objImageQualityBar.invalidate();
m_objCameraView.invalidate();
}
});
if ( bCurrentCaptureSelected )
{
final String strSelectedImagePath = CPathProvider.getInternalPathSelectedImage ();
argWorker.saveSelectedCapture ( strSelectedImagePath );
final Intent objCaptureCorrectionIntent = new Intent ( CCaptureActivity.this, CAdjustmentActivity.class );
objCaptureCorrectionIntent.putExtra ( "EXTRA_CAPTURED_IMAGE", strSelectedImagePath );
if ( argDocumentCorners.bCornersFound )
{
objCaptureCorrectionIntent.putExtra ( "EXTRA_DETECTED_CORNERS", argDocumentCorners.xiCorners );
}
CCaptureActivity.this.startActivity ( objCaptureCorrectionIntent );
}
}
}
}
finally
{
// Unlock the worker before exiting
argWorker.unlock ();
}
}
}
}
/**
* Setup the listener class that links the view to the camera.
*/
private void setupCameraViewListener ()
{
m_objCameraView.setSurfaceTextureListener ( new TextureView.SurfaceTextureListener ()
{
/**
* Surface texture available handler.
* #param argSurfaceTexture The surface texture (unused)
* #param iWidth Surface texture width (unused)
* #param iHeight Surface texture height (unused)
*/
#Override
public void onSurfaceTextureAvailable ( final SurfaceTexture argSurfaceTexture, final int iWidth, final int iHeight )
{
// No need to use the provided parameters - simply open the camera.
openCamera ();
}
#Override
public void onSurfaceTextureSizeChanged ( final SurfaceTexture argSurfaceTexture, final int iWidth, final int iHeight )
{
}
#Override
public boolean onSurfaceTextureDestroyed ( final SurfaceTexture argSurfaceTexture )
{
return true;
}
#Override
public void onSurfaceTextureUpdated ( final SurfaceTexture argSurfaceTexture )
{
}
});
}
/**
* Setup the camera status callback listener.
*/
private void setupCameraStatusCallback ()
{
m_objCameraStateCallback = new CameraDevice.StateCallback ()
{
/**
* Camera open handler.
* #param argCameraDevice The camera opened.
*/
#Override
public void onOpened ( final CameraDevice argCameraDevice )
{
m_objCameraDevice = argCameraDevice;
startCamera ();
}
#Override
public void onDisconnected ( final CameraDevice argCameraDevice )
{
}
#Override
public void onError ( final CameraDevice argCameraDevice, final int iError )
{
if ( m_objCameraDevice != null && m_objCameraDevice.getId ().equals ( argCameraDevice.getId ()))
{
Log.e ( "CCaptureActivity", "The camera encountered an error: " + iError );
}
}
};
}
private void getCamera ()
{
try
{
// Parse all available cameras and select the first rear-facing found.
m_strCameraId = null;
CameraCharacteristics objCameraCharacteristics = null;
final String[] xstrCameraIds = m_objCameraManager.getCameraIdList ();
for ( final String strCurrentCameraId : xstrCameraIds )
{
objCameraCharacteristics = m_objCameraManager.getCameraCharacteristics ( strCurrentCameraId );
if ( objCameraCharacteristics.get ( CameraCharacteristics.LENS_FACING ) == CameraCharacteristics.LENS_FACING_BACK )
{
m_strCameraId = strCurrentCameraId;
break;
}
}
if (m_strCameraId == null)
{
Log.e("CCaptureActivity", "Could not find device back camera");
}
final StreamConfigurationMap objStreamConfigurationMap = objCameraCharacteristics.get ( CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP );
m_iCameraOrientation = objCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Finally, retrieve the capture and preview sizes.
m_objCaptureSize = selectCaptureSize ( objStreamConfigurationMap.getOutputSizes ( ImageFormat.YUV_420_888 ), m_iCameraOrientation );
m_objPreviewSize = selectPreviewSize ( objStreamConfigurationMap.getOutputSizes ( SurfaceTexture.class ), m_objCaptureSize );
Log.i ("CCaptureActivity", "Capture size selected: " + m_objCaptureSize.getHeight () + " x " + m_objCaptureSize.getWidth ());
m_objIdrsCapture.setCharacteristics ( m_objCaptureSize, m_iCameraOrientation );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred while retrieving the device camera", argException );
}
}
private void openCamera ()
{
try
{
// Start or restart the preview handler if needed
if ( ! m_objPreviewThread.isAlive() || m_objPreviewThread.isInterrupted ())
{
m_objPreviewThread.start();
}
m_objPreviewThreadHandler = new Handler ( m_objPreviewThread.getLooper ());
m_objImageReader = ImageReader.newInstance ( m_objCaptureSize.getWidth (), m_objCaptureSize.getHeight (), ImageFormat.YUV_420_888, 2 );
m_objImageReader.setOnImageAvailableListener ( m_objPreviewImageListener, m_objPreviewThreadHandler );
m_objDocumentAreaView.setCaptureSize ( m_objCaptureSize, m_iCameraOrientation );
m_objCameraView.setCaptureSize ( m_objCaptureSize );
m_objCameraManager.openCamera ( m_strCameraId, m_objCameraStateCallback,null );
m_bCameraOpen = true;
}
catch ( final SecurityException argSecurityException )
{
Log.e ( "CCaptureActivity", "A security exception occurred while opening the device camera", argSecurityException );
}
catch (final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred while opening the device camera", argException );
}
}
private void startCamera ()
{
if ( m_objCameraDevice == null || ! m_objCameraView.isAvailable () || m_objPreviewSize == null )
{
return;
}
final SurfaceTexture argSurfaceTexture = m_objCameraView.getSurfaceTexture ();
if ( argSurfaceTexture == null )
{
return;
}
argSurfaceTexture.setDefaultBufferSize ( m_objPreviewSize.getWidth (), m_objPreviewSize.getHeight ());
final Surface argSurface = new Surface ( argSurfaceTexture );
try
{
m_objCaptureRequestBuilder = m_objCameraDevice.createCaptureRequest ( CameraDevice.TEMPLATE_PREVIEW );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred when creating the capture request", argException );
}
m_objCaptureRequestBuilder.addTarget ( argSurface );
m_objCaptureRequestBuilder.addTarget ( m_objImageReader.getSurface ());
try
{
m_objCameraDevice.createCaptureSession ( Arrays.asList ( argSurface, m_objImageReader.getSurface ()),
new CameraCaptureSession.StateCallback ()
{
#Override
public void onConfigured ( final CameraCaptureSession argCameraCaptureSession )
{
m_objCameraCaptureSession = argCameraCaptureSession;
onCaptureSessionConfigured ();
}
#Override
public void onConfigureFailed ( final CameraCaptureSession argCameraCaptureSession )
{
Log.e ("CCaptureActivity", "The camera capture session could not be successfully created." );
}
},
null );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occurred when creating the capture session", argException );
}
}
/**
* Callback that will start capture session once it is configured.
*/
private void onCaptureSessionConfigured ()
{
if ( m_objCameraDevice == null )
{
return;
}
m_objCaptureRequestBuilder.set ( CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO );
try
{
m_objCameraCaptureSession.setRepeatingRequest ( m_objCaptureRequestBuilder.build (),
m_objHardwareStatus,
m_objPreviewThreadHandler );
}
catch ( final Exception argException )
{
Log.e ( "CCaptureActivity", "An exception occured while starting capture session", argException );
}
}
private void closeCamera ()
{
if ( m_bCameraOpen )
{
m_objCameraDevice.close ();
m_bCameraOpen = false;
}
if( m_objCameraCaptureSession != null )
{
m_objCameraCaptureSession.close();
}
}
private Size selectCaptureSize ( final Size [] xargSizes, final int iCameraOrientation )
{
// Retrieve the screen dimensions to know its aspect ratio
final DisplayMetrics objDisplayMetrics = new DisplayMetrics ();
getWindowManager().getDefaultDisplay ().getMetrics ( objDisplayMetrics );
final float fScreenRatio = (float) objDisplayMetrics.widthPixels / objDisplayMetrics.heightPixels;
Size objMaxSizeSameRatio = null;
Size objMaxSizeAnyRatio = null;
// Now iterates on the list to find the largest (in area) below the accepted limit
for (final Size objCurrent : xargSizes )
{
final int iAreaSize = objCurrent.getHeight () * objCurrent.getWidth ();
final float fSizeRatio;
if ( iCameraOrientation == 0 || iCameraOrientation == 180)
{
fSizeRatio = (float) objCurrent.getWidth () / objCurrent.getHeight ();
}
else
{
fSizeRatio = (float) objCurrent.getHeight () / objCurrent.getWidth ();
}
if ( iAreaSize < CAPTURE_SIZE_MAX_PIXELS )
{
// Search with same ratio
if ( fSizeRatio == fScreenRatio &&
( objMaxSizeSameRatio == null || ( objMaxSizeSameRatio.getWidth () * objMaxSizeSameRatio.getHeight () < iAreaSize )))
{
objMaxSizeSameRatio = objCurrent;
}
// Search as well without taking the ratio into account
if ( objMaxSizeAnyRatio == null || ( objMaxSizeAnyRatio.getWidth () * objMaxSizeAnyRatio.getHeight () < iAreaSize ))
{
objMaxSizeAnyRatio = objCurrent;
}
}
}
return objMaxSizeSameRatio != null ? objMaxSizeSameRatio : objMaxSizeAnyRatio;
}

Android studio Mail issue

I have set up classes in my app to send a mail based on the user's name email and message. It seems in app as if it's working fine but no actual email is being sent. Can Anybody help? Thank you in advance.
Here is the Gmail class i have set:
public class GMail {
final String emailPort = "587"; // this is gMail's smtp port number
final String smtpAuth = "true";
final String starttls = "true";
final String emailHost = "smtp.gmail.com";
String fromEmail;
String fromPassword;
List<String> toEmailList;
String emailSubject;
String emailBody;
Properties emailProperties;
Session mailSession;
MimeMessage emailMessage;
// this will be the constructor of the email
public GMail(String fromEmail, String fromPassword, List<String> toEmailList, String emailSubject, String emailBody)
{
this.fromEmail = fromEmail;
this.fromPassword = fromPassword;
this.toEmailList = toEmailList;
this.emailBody = emailBody;
//setting the server settings for Gmail
emailProperties = System.getProperties();
emailProperties.put("mail.smtp.port", emailPort);
emailProperties.put("mail.smtp.auth", smtpAuth);
emailProperties.put("mail.smtp.starttls.enable", starttls);
Log.i("Gmail", "Mail server properties are now set.");
}
public MimeMessage createEmailMessage() throws AddressException,
MessagingException, UnsupportedEncodingException{
mailSession = Session.getDefaultInstance(emailProperties, null);
emailMessage = new MimeMessage(mailSession);
emailMessage.setFrom(new InternetAddress(fromEmail, fromEmail));//address setup
for(String toEmail : toEmailList){
Log.i("GMail", "toEmail" + toEmail);
emailMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(toEmail));
}
emailMessage.setSubject(emailSubject); //email Subject
emailMessage.setContent(emailBody, "text/html");
return emailMessage;
}
public void sendEmail() throws AddressException, MessagingException
{
Transport transport = mailSession.getTransport("smtp");
transport.connect(emailHost, fromEmail, fromPassword);
Log.i("Gmail", "allrecipients: " + emailMessage.getAllRecipients());
transport.close();
Log.i("Gmail", "Your Email has successfully been sent.");
}
}
Here's my SendMailTask class
public class SendMailTask extends AsyncTask {
private ProgressDialog statusDialog;
private Activity sendMailActivity;
public SendMailTask(Activity activity) {
sendMailActivity = activity;
}
// make the method for showing dialog progress
protected void onPreExecute() {
statusDialog = new ProgressDialog(sendMailActivity);
statusDialog.setMessage("Setting up..");
statusDialog.setIndeterminate(false);
statusDialog.setCancelable(false);
statusDialog.show();
}
//method for creation and sending of email
#Override
protected Object doInBackground(Object... args) {
try{
Log.i("SendMailTask", "Setting up your email ..");
publishProgress("Processing all your information ..");
GMail androidEmail = new GMail(args[0].toString(),
args[1].toString(), (List) args[2], args[3].toString(),
args[4].toString());
publishProgress("Preparing your information ..");
androidEmail.createEmailMessage();
publishProgress("Sending your information ..");
androidEmail.sendEmail();
publishProgress("Information sent.");
Log.i("SendMailTask", "Information sent.");
}catch(Exception e){
publishProgress(e.getMessage());
Log.e("SendMailTask", e.getMessage(), e);
}
return null;
}
// creating method for dialog messages.
#Override
public void onProgressUpdate(Object... values){
statusDialog.setMessage(values[0].toString());
}
//method to get rid of the dialog message.
#Override
public void onPostExecute(Object result){
statusDialog.dismiss();
}
}
and here is the class that im trying to get the mail sent from:
public class HelpPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help_page2);
final EditText mail1 = findViewById(R.id.email1);
final EditText mail2 = findViewById(R.id.email2);
final EditText nameIn = findViewById(R.id.hName1);
final Button btnSub = findViewById(R.id.helpBtn);
final EditText msgIn = findViewById(R.id.hMsg);
final String password = "xxxxxxxx";
final String sendemail = "come2gopj#gmail.com";
final String recemail = "c2grecieve#gmail.com";
final boolean connt;
ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED){
// Connection affirmative:)
connt = true;
}
else {
connt = false;
Toast.makeText(getApplicationContext(), "You're not connected to the internet",
Toast.LENGTH_LONG).show();
}
btnSub.setOnClickListener(
arg0 -> {
//method to make sure all fields are checked
if(nameIn.getText().toString().equals("")||mail1.getText().toString().equals("")||mail2.getText().toString().equals("")||msgIn.getText().toString().equals(""))
{
Toast.makeText(getApplicationContext(), "Please check you've filled all fields.",
Toast.LENGTH_LONG).show();
}
else if(connt!=true){
Toast.makeText(getApplicationContext(), "You're internet connection needs to be checked",
Toast.LENGTH_LONG).show();
}
else{
if(mail1.getText().toString().equals(mail2.getText().toString())){
Log.i("SendMailActivity", "Send Button Clicked.");
//declaring the recieving, password and sending of the email
List<String> toEmailList = Arrays.asList(recemail.split("\\s*,\\s*")); //Recipient List
Log.i("SendMailActivity", "To List: " + toEmailList);
String emailSubject = ((EditText) findViewById(R.id.hName1)).getText().toString();
String emailEmail = ((EditText) findViewById(R.id.email1)).getText().toString();
String emailBody = "User's Email : " + ((EditText) findViewById(R.id.email1)).getText().toString() + "\n" +
"User's message: "+((EditText) findViewById(R.id.hMsg)).getText().toString();
new SendMailTask(HelpPage.this).execute(sendemail, password,toEmailList,emailSubject,emailBody,emailEmail);//send the email with all the relevant data included
startActivity(new Intent(getApplicationContext(),AfterMail.class)); //this will start the next activity that i have included after the mail is sent
}
else{//method for checking the email inputs
Toast.makeText(getApplicationContext(), "Your emails don't match please try again.",
Toast.LENGTH_LONG).show();
}
}
});
}
These are the messages i get in the run dialog after I've pressed the send button:
I/SendMailActivity: Send Button Clicked.I/SendMailActivity: To List: [c2grecieve#gmail.com]
I/SendMailTask: Setting up your email ..
I/Gmail: Mail server properties are now set.
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
I/.myapplication: Background concurrent copying GC freed 24080(6MB) AllocSpace objects, 5(92KB) LOS objects, 49% free, 2MB/4MB, paused 1.019ms total 105.897ms
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy#af22bc6
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
I/chatty: uid=10085(com.example.myapplication2) RenderThread identical 5 lines
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
I/GMail: toEmailc2grecieve#gmail.comD/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
I/Choreographer: Skipped 34 frames! The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
D/EGL_emulation: eglMakeCurrent: 0xe1205120: ver 3 1 (tinfo 0xe1203320)
I/Gmail: allrecipients: [Ljavax.mail.internet.InternetAddress;#80121b1
I/Gmail: Your Email has successfully been sent.I/SendMailTask: Information sent.
I finally figured out what I was missing. in the GMail.java file i was missing 1 line of code to get the email to actually send. `transport.sendMessage(emailMessage, emailMessage.getAllRecipients());
That was the line i was missing. `

My app shuts down when I don't give any input though I have mentioned the code for it

The app created finds whether the number is triangular or not. For more details, refer https://en.wikipedia.org/wiki/Triangular_number
Now, when I click on the button without giving any input in the TextView, the app shuts down abruptly. It shouldn't so because I already have an if statement for an empty string in the code.
package com.example.numbershapes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
class Number {
int number;
public boolean isTriangular() {
int x = 1;
int triangularNmbr = 1;
while (triangularNmbr < number) {
x++;
triangularNmbr += x;
}
if(triangularNmbr == number) {
return true;
}
else {
return false;
}
}
}
public class MainActivity extends AppCompatActivity {
public void testNumber(View view)
{
EditText usersNumber =
(EditText)findViewById(R.id.usersNumber);
String message = "";
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
}
Number myNumber = new Number();
myNumber.number =
Integer.parseInt(usersNumber.getText().toString());
//will display on logcat
System.out.println(myNumber.isTriangular());
if(myNumber.isTriangular()){
message = myNumber.number + " is triangular" ;
}
else{
message = myNumber.number + " is not triangular" ;
}
Toast.makeText(getApplicationContext(), message,
Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Also, I'm getting an error in Event Log. "Can't bind to local 8600 for debugger".
Can anybody explain what is it?
This is how the app looks
**
Logcat details when the app shuts down
**
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6662)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2019-09-08 00:38:56.005 4718-4718/? I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2599)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2707)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1460)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.os.Looper.loop() (Looper.java:154)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
2019-09-08 00:38:56.005 4718-4718/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
2019-09-08 00:38:56.142 1314-1322/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-09-08 00:38:56.190 4718-4734/com.example.numbershapes I/OpenGLRenderer: Initialized EGL, version 1.4
2019-09-08 00:38:56.190 4718-4734/com.example.numbershapes D/OpenGLRenderer: Swap behavior 1
2019-09-08 00:38:56.192 4718-4734/com.example.numbershapes W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-09-08 00:38:56.192 4718-4734/com.example.numbershapes D/OpenGLRenderer: Swap behavior 0
2019-09-08 00:38:56.320 4718-4734/com.example.numbershapes D/EGL_emulation: eglCreateContext: 0x8d11ba20: maj 2 min 0 rcv 2
2019-09-08 00:38:56.596 4718-4734/com.example.numbershapes D/EGL_emulation: eglMakeCurrent: 0x8d11ba20: ver 2 0 (tinfo 0x9b763770)
2019-09-08 00:38:56.634 4718-4718/com.example.numbershapes W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
2019-09-08 00:38:56.693 4718-4734/com.example.numbershapes D/EGL_emulation: eglMakeCurrent: 0x8d11ba20: ver 2 0 (tinfo 0x9b763770)
2019-09-08 00:38:56.996 1601-1621/? I/ActivityManager: Displayed com.example.numbershapes/.MainActivity: +1s767ms
2019-09-08 00:38:57.010 1671-1862/? D/EGL_emulation: eglMakeCurrent: 0xa8e855a0: ver 2 0 (tinfo 0xa8e83640)
2019-09-08 00:38:57.035 1601-1751/? I/WindowManager: Destroying surface Surface(name=com.android.systemui/com.android.systemui.recents.RecentsActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.destroyOrSaveSurface:2100 com.android.server.wm.WindowManagerService.tryStartExitingAnimation:3024 com.android.server.wm.WindowManagerService.relayoutWindow:2904 com.android.server.wm.Session.relayout:224 android.view.IWindowSession$Stub.onTransact:286 com.android.server.wm.Session.onTransact:145
2019-09-08 00:38:57.192 1601-1621/? I/WindowManager: Destroying surface Surface(name=Starting com.example.numbershapes) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.destroyOrSaveSurface:2100 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
2019-09-08 00:38:58.432 1360-1394/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5063852 , only wrote 4803840
2019-09-08 00:39:00.016 1671-1862/? D/EGL_emulation: eglMakeCurrent: 0xa8e855a0: ver 2 0 (tinfo 0xa8e83640)
2019-09-08 00:39:00.232 4718-4718/com.example.numbershapes D/AndroidRuntime: Shutting down VM
2019-09-08 00:39:00.241 4718-4718/com.example.numbershapes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.numbershapes, PID: 4718
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:5610) 
at android.view.View$PerformClick.run(View.java:22265) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:533)
at java.lang.Integer.parseInt(Integer.java:556)
at com.example.numbershapes.MainActivity.testNumber(MainActivity.java:36)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:5610) 
at android.view.View$PerformClick.run(View.java:22265) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
2019-09-08 00:39:00.241 1360-1393/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 4803995 , only wrote 4803840
2019-09-08 00:39:00.244 1601-1612/? W/ActivityManager: Force finishing activity com.example.numbershapes/.MainActivity
2019-09-08 00:39:00.325 1601-4290/? I/OpenGLRenderer: Initialized EGL, version 1.4
2019-09-08 00:39:00.325 1601-4290/? D/OpenGLRenderer: Swap behavior 1
2019-09-08 00:39:00.327 1601-4290/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-09-08 00:39:00.327 1601-4290/? D/OpenGLRenderer: Swap behavior 0
2019-09-08 00:39:00.347 1601-4290/? D/EGL_emulation: eglCreateContext: 0x8ec4d1c0: maj 2 min 0 rcv 2
2019-09-08 00:39:00.368 1601-4290/? D/EGL_emulation: eglMakeCurrent: 0x8ec4d1c0: ver 2 0 (tinfo 0x8e191ff0)
2019-09-08 00:39:00.405 1601-4290/? D/EGL_emulation: eglMakeCurrent: 0x8ec4d1c0: ver 2 0 (tinfo 0x8e191ff0)
2019-09-08 00:39:00.758 1601-1614/? W/ActivityManager: Activity pause timeout for ActivityRecord{aa667d7 u0 com.example.numbershapes/.MainActivity t26 f}
2019-09-08 00:39:00.803 1314-1322/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 2691072
2019-09-08 00:39:00.842 1314-1314/? E/EGL_emulation: tid 1314: eglCreateSyncKHR(1901): error 0x3004 (EGL_BAD_ATTRIBUTE)
2019-09-08 00:39:01.450 2026-2273/? D/EGL_emulation: eglMakeCurrent: 0xa8e85420: ver 2 0 (tinfo 0xa8e838e0)
2019-09-08 00:39:01.938 2026-2273/? W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
2019-09-08 00:39:01.952 1601-1614/? I/ActivityManager: Killing 3960:com.google.android.apps.photos/u0a63 (adj 906): empty for 3445s
2019-09-08 00:39:02.006 1601-1658/? D/ActivityManager: cleanUpApplicationRecord -- 3960
2019-09-08 00:39:03.453 1360-1394/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5110293 , only wrote 4957920
2019-09-08 00:39:14.093 1601-1614/? W/ActivityManager: Activity destroy timeout for ActivityRecord{aa667d7 u0 com.example.numbershapes/.MainActivity t26 f}
2019-09-08 00:39:14.098 1601-1614/? I/WindowManager: Destroying surface Surface(name=com.example.numbershapes/com.example.numbershapes.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.removeLocked:1456 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2484 com.android.server.wm.WindowManagerService.removeWindowLocked:2442 com.android.server.wm.WindowManagerService.removeWindowLocked:2311 com.android.server.wm.AppWindowToken.removeAllWindows:530 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:326
2019-09-08 00:39:16.767 1314-1326/? W/SurfaceFlinger: Timed out waiting for hw vsync; faking it
2019-09-08 00:39:17.955 1601-1621/? I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
When I run it it throws an exception. Your line number may differ but the reason is the same:
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:620)
at java.lang.Integer.parseInt(Integer.java:643)
at stackoverflow57836483.MainActivity.testNumber(MainActivity.java:39)
problematic line is:
myNumber.number = Integer.parseInt(usersNumber.getText().toString());
But the real reason occurs earlier.
Here you already know the input is invalid but you continue execution and parsing it as a number.
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
}
You should put everything that comes after into else { } except showing Toast. Correct code would be:
public void testNumber(View view)
{
EditText usersNumber = (EditText)findViewById(R.id.usersNumber);
String message = "";
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
} else { // ELSE STARTS HERE...
Number myNumber = new Number();
myNumber.number = Integer.parseInt(usersNumber.getText().toString());
//will display on logcat
System.out.println(myNumber.isTriangular());
if(myNumber.isTriangular()){
message = myNumber.number + " is triangular" ;
}
else{
message = myNumber.number + " is not triangular" ;
}
} // AND ENDS HERE
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}

TextToSpeech is giving "Language is not supporting" error in API 23

I'm setting up TextToSpeech to my app.It's working well on API 26 and above but not working on API 23.It's giving language not supporting error.
My logcat:
07-31 16:22:04.872 6935-7000/com.caneraltuner.tarihkitabm D/EGL_emulation: eglMakeCurrent: 0xaa94e480: ver 3 0 (tinfo 0xaa951d00)
07-31 16:22:04.876 6935-7000/com.caneraltuner.tarihkitabm D/EGL_emulation: eglMakeCurrent: 0xaa94e480: ver 3 0 (tinfo 0xaa951d00)
07-31 16:22:04.897 6935-7000/com.caneraltuner.tarihkitabm D/EGL_emulation: eglMakeCurrent: 0xaa94e480: ver 3 0 (tinfo 0xaa951d00)
07-31 16:22:04.906 6935-7000/com.caneraltuner.tarihkitabm D/EGL_emulation: eglMakeCurrent: 0xaa94e480: ver 3 0 (tinfo 0xaa951d00)
And my codeblock:
public void speakOut(View view) {
mTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
Locale locale = new Locale("tr", "TR");
int result = mTTS.setLanguage(locale);
if (result == TextToSpeech.LANG_MISSING_DATA) {
Toast.makeText(getApplicationContext(), "Hata", Toast.LENGTH_SHORT).show();
} else if (result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(getApplicationContext(), "Dil Desteklenmiyor", Toast.LENGTH_SHORT).show();
} else {
mTTS.speak(leaderInfoText.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
} else {
Toast.makeText(getApplicationContext(), "Ses Yüklenemedi", Toast.LENGTH_SHORT).show();
}
}
});
}

Android - MediaPlayer : How to separating fastForward to another method (that later will be call)?

Here's my snippets :
public class MainActivity extends AppCompatActivity {
private int seekForwardTime = 5000;
private int seekBackwardTime = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekForward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View v) {
Toast.makeText(getApplicationContext(), "Seek Forward music", Toast.LENGTH_SHORT).show();
forwardSong(mediaPlayer);
}
});
}
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
}
As per title, I want to separate Fast Forward (seek 5 second forward for each press) behavior from seekForward.OnClickListener to another method (forwardSong).
But, when I trigger seekForward, instead of seeking, it kills mediaPlayer. So I have to press 'play' button again and start from beginning of song.
Am I missed something? I'm happy to receive any solution and/or advice.
ps : please ignore the Log statement, I'm just do some test before.
Thanks!
Edit - 09/08/2017
As requested, here's the logcat
08-09 16:36:01.688 2707-2707/? I/art: Not late-enabling -Xcheck:jni (already on)
08-09 16:36:01.688 2707-2707/? W/art: Unexpected CPU variant for X86 using defaults: x86
08-09 16:36:01.781 2707-2707/? W/System: ClassLoader referenced unknown path: /data/app/com.example.android.musicplayer-2/lib/x86
08-09 16:36:01.791 2707-2707/? I/InstantRun: starting instant run server: is main process
08-09 16:36:01.856 2707-2707/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-09 16:36:02.094 2707-2707/com.example.android.musicplayer D/MediaPlayer: setSubtitleAnchor in MediaPlayer
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer I/OpenGLRenderer: Initialized EGL, version 1.4
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 1
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 0
08-09 16:36:02.219 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglCreateContext: 0xa1328e80: maj 2 min 0 rcv 2
08-09 16:36:02.264 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:36:02.333 2707-2707/com.example.android.musicplayer W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
08-09 16:36:02.343 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.717 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.747 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:48.672 2707-2707/com.example.android.musicplayer V/currentPosition: 707
08-09 16:58:48.673 2707-2707/com.example.android.musicplayer V/main activity: else state
08-09 16:58:49.669 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:50.684 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:51.667 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:53.631 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
I'm confused. Why it entering else statement?
Modify your forwardSong function the following way :
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getDuration()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
The following condition is the problem, it will be always false and the mediaplayer will always seek to the end of your media file because of your else statement.
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition())

Categories