Hi everyone,
Question 1:
When I try to run this code:
I get this error:
What is wrong with this code? Does the translated starter.java has something that troubles it?
Question 2:
If I remove the last function in java (HasTextCopied) everything runs fine but if I move this code (without the HasTextCopied function) in a class it does not work...
I could use some help...
Thanks in advance...
Question 1:
When I try to run this code:
B4X:
Public Sub GetText As String
Dim jo As JavaObject
jo.InitializeContext
Dim sOk As String
sOk = jo.RunMethod("GetTextFromClipboard", Null)
Return sOk
End Sub
Public Sub SetText(txt As String) As Boolean
Dim jo As JavaObject
jo.InitializeContext
Dim bOk As Boolean
bOk = jo.RunMethod("SetTextToClipboard", Array As String(txt))
Return bOk
End Sub
#IF JAVA
import android.content.ClipboardManager;
import android.content.ClipData;
import android.content.ClipDescription;
public Boolean SetTextToClipboard(String txt) {
try{
ClipboardManager myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData myClip;
myClip = ClipData.newPlainText("text", txt);
myClipboard.setPrimaryClip(myClip);
return true;
}
catch(Exception ex){
return false;
}
};
public String GetTextFromClipboard() {
ClipboardManager myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData myClip = myClipboard.getPrimaryClip();
ClipData.Item item = myClip.getItemAt(0);
String txt = item.getText().toString();
return txt;
};
public Boolean HasTextCopied() {
ClipboardManager myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (!(myClipboard.hasPrimaryClip())) {
return false;
} else if (!(myClipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {
return false;
} else {
return true;
}
};
#End If
I get this error:
B4X:
B4A Version: 7.80
Parsing code. (0.00s)
Compiling code. (0.04s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. (0.05s)
Compiling generated Java code. Error
javac 1.8.0_172
src\dhqi\ctrlc\application\main.java:464: error: cannot find symbol
} else if (!(myClipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {
^
symbol: variable MIMETYPE_TEXT_PLAIN
location: class main
Note: src\dhqi\ctrlc\application\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
What is wrong with this code? Does the translated starter.java has something that troubles it?
Question 2:
If I remove the last function in java (HasTextCopied) everything runs fine but if I move this code (without the HasTextCopied function) in a class it does not work...
I could use some help...
Thanks in advance...