With android AccessibilityService able to paste in other app EditText Field, but with browser testfields (Emulator Default Browser or Samsung deault Browser) its not working, throwing error:
Cannot perform this action on a not sealed instance.
In android chrome browser with some singnup textfield its working but not for all textfields.
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
if (source != null && ( event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED ) ) {
// || event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED ) &&
//event.getClassName().equals("android.widget.EditText")
//) {
ctx = getApplicationContext();
ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "XYZ");
clipboard.setPrimaryClip(clip);
source.performAction(AccessibilityNodeInfo.ACTION_PASTE);
//Not Working, always return false.
//Tried with other options
Bundle argumentsTest = new Bundle();
argumentsTest.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "Bundle Test Data");
source.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT,argumentsTest )
// Not Working, throw java.lang.IllegalStateException exception
//Message: "Cannot perform this action on a not sealed instance"
}
}
I don't beleive you're trying to do what you think you're trying to do.
When you set the "text" of an accessibilityNodeInfo, what you're chaning is the text property of that object, as it pertains to your accessibility service. THIS DOES NOT mean, that you are changing the text of the EditText box, that the accessibilityNodeInfo object references. By the time your accessibility service gets this object, the two objects are quite separate from each other. Even if your code were to run successfully, you would not be getting the results you are expecting. Now, as for why you cannot perform this action, knowing this it should be obvious. For an accessibility service to be able to modify the nodes it has, doesn't really make sense. So they become sealed (think of this as a run time enforcement of a constant). Accessibility nodes become sealed and unsealed at various points in their lifetime. The parts of the framework that have access to unsealed node infos are View classes and private APIs. Any accessibility service related tasks are going to be dealing with sealed, read-only instances.
As for why your original solution is not working, I believe that we do not have enough information. The "ACTION_PASTE" approach is (approximately) the correct approach, HOWEVER, there are an abundance of issues when doing so with web browsers. Browser version, Android version, device version, website, etc all play a role. Especially if your set up is old enough to not use the new WebView (pure chromium webview, rather than the old 4.+ approach of odd embedded mobile WebViews based on outdated versions of WebKit, which will now never be updated). I recommend testing your code on an up to date Nexus device, using at least Android 5.0 and seeing if your code works. If you cannot do this, report version information for your set up. If you already are, on what website?
What have I done so far:
I am currenctly facing some problems with the launchers.
My application adds shortcuts to the workspace of the launcher (homescreen).
But on some devices (Samsum Duos) for example, the titles and /or icons
are changed back after reboot to my default application one.
So I am currently going through 1000s of lines code in the android
source to identify the problem, but was not able to find it.
I saw in InstallShortcutReceiver
a comment in line 183 that the "name" provided by Intent.EXTRA_SHORTCUT_NAME can in
some situations be used only for comparison etc and will be replaced
with the applications default name.
// This name is only used for comparisons and notifications, so fall back to activity name
// if not supplied
But (my Samsum Duos is rooted) I could find the complete information's
about the cell position and shortcutInfo's inside of the launcher.db.
So it was not gone, after reboot, but maybe only not correct initialized!
First Question:
Does anybody know the reason for a custom, programmatically created shortcut to change the title and or icon back to the application's one that created it?
Next story:
I noticed that this issue was reproducible on my Samsum Duos, so I decided
to exclude the Devices Launcher from my "save launcher" list.
To receive the default launcher I am doing the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = null;
try {
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); //can return null!
}catch(RuntimeException e){
ExceptionHandler.logAndSendException(e);//package manager has died
return false;
}
But the problem now is, that it always returns that the default launchers
package is: com.android.launcher2.Launcher, which would be the standard
android stock launcher. But I know that Samsum uses the TouchWiz home
launcher, whos Package is located under com.sec.android.app.launcher!
That is also where I found the launcher.db and all its ShortcutInfo's.
2. Second Question
How do I get reproducible the correct default launcher package to identify
which launcher is used?
edit:
I kind of fixed the second problem. Somehow the ResolveInfo I get from
the PackageManager seems to be not reliable.
For the Samsum Duos I get:
resolveInfo.activityInfo.name = com.android.launcher2.Launcher
resolveInfo.activityInfo.packageName = com.sec.android.app.launcher //this is what I need
But for the Redmi MIUI:
resolveInfo.activityInfo.name = com.miui.home.launcher.Launcher //this time I would need this
resolveInfo.activityInfo.packageName = com.miui.home //the packageName is not complete!
I need an unique identifier for the launcher! So I thought activityInfo.name would be the
way to go, but it isn't in some situations. And the packageManager seems to apply to too many devices. Any suggestions?
Cheers!
How can I get the current input device in my application in java? I want to know is the remote or the game controller, that is being used.
It is an android application that I want to run on Amazon FireTV. Unlike the Amazon Kindle there is no touchscreen but you can use a remote or a game controller. I would like to know if it is possible to detect what kind of input device the user is currently using.
The code I have until now is a standard Cordova Application code, but when I know how to detect the current input device I would make a plugin to pass the value to the javascript code. That is not the problem.
As mentioned in the comments you should provide steps you have already taken or code you have already written to address this functionality as that will help us tweak the most appropriate answer.
As a general rule, you can look at the official docs to identify controllers on Fire TV.
https://developer.amazon.com/public/solutions/devices/fire-tv/docs/identifying-controllers
Basically, you need to write the identification code in your Cordova plugin as follows:
int hasFlags = InputDevice.SOURCE_GAMEPAD | InputDevice.SOURCE_JOYSTICK;
boolean isGamepad = inputDevice.getSources() & hasFlags == hasFlags;
This will allow you to find out if it's a gamepad. For a Fire TV remote the code you need is:
int hasFlags = InputDevice.SOURCE_DPAD;
bool isRemote = (inputDevice.getSources() & hasFlags == hasFlags)
&& inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC;
The InputDevice class is available on the Android developer site:
http://developer.android.com/reference/android/view/InputDevice.html
So you basically need to import that in your plugin class to ensure the above code works fine.
import android.view.InputDevice;
i HAVE STARTED A NEW video STREAM PROJECT USING java LANGUAGE .I will put you in the scope of my two questions but keep know now that I will ask you about vedio capturing and detection ,not sending videos .
1-I have downloaded the jmf studio and registry . the problem in the jmf regestry .jfm registry cannot detect my pc cam .how can i detect it, or as i read in other words , where the jmf.properties can be put to run the registry well.
2- as i go forward to write the java code , i used this code to detect the cam:
Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList ( new
YUVFormat() );
// Iterating list
for(CaptureDeviceInfo temp : list){
// Checking whether the current device supports VfW
// VfW = Video for Windows
if(temp.getName().startsWith("vfw:")){
System.out.println("Found :
"+temp.getName().substring(4));// Selecting the very first device that supports VfW
cam = temp;
System.out.println("Selected :
"+cam.getName().substring(4));
break;
}
}
System.out.println("Put it on work!...");
// Getting the MediaLocator for Selected device.
// MediaLocator describes the location of media content
locator = cam.getLocator();///
this is just a snap shot, look now ,as no device can be detected the locator stay null, now my question is there a realation between the jmf registry and in general any project that will use this function to detect devices. sorry for this long question .
note : as i try all the answers of this question which i have founded on the stack overflow or others with no success , i have been forced to ask it a gain .
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I saw the stock Android-Developer licensing library instructions, but the overview seems to omit several key steps in the process and fails to fully explain how to get something working.
Can someone provide an explicit set of operations that worked to get the licensing library set up on an Android app so it checks to ensure that a user has paid for an app in Google Play before allowing use?
I have been working on implementing licensing in my app for some time now and finally have it working. I wanted to share some of the things I found helpful for getting started and some problems and solutions that I found with everyone. The android dev tutorial I have linked below is ok, but it wasn't that useful for me, so I decided to make a tutorial. Enjoy, and I hope it helps you!
Link to developer page here.
1. Getting started
Things you will need.
1.1 Your Base64 unique application key
How to get it:
a. Go to your developer console. Link.
b. If you haven't already created an application draft for your app, do it now.
c. Once you have created the draft, it is a good idea to upload your .apk as Alpha or Beta. Leave it unpublished.
d. Click Services & APIs
e. Scroll down and find YOUR LICENSE KEY FOR THIS APPLICATION
f. Copy the key into your app like this:
private static final String BASE64_PUBLIC_KEY = "YOUR LICENSE KEY FOR THIS APPLICATION";
Make sure that there are no spaces.
1.2 A salt
a. What is a salt?
A salt is random data that is additional input when hashing a password. They are used to defend against dictionary attacks and rainbow table attacks.
b. How do I get one?
This is a good link to generate a random salt. There should be exactly 20 random integers, so put 20 in for the amount of random strings to generate, each string should be 2 characters long (used for this example, it doesn't have to be). Check numeric digits, and check Identical strings are allowed. They can be negative numbers too. Try to remove any redundancy, e.g. 00 -> 0, for the sake of consistency.
c. Where do I put the salt?
When declaring variables just put this code in, except with your random salt.
private static final byte[] SALT = new byte[] {YOUR RANDOM SALT, COMMA SEPARATED, 20 INTEGERS};
2. Importing the LVL (Licensing) library into Eclipse and the code you need
2.1 Importing the library
a. Open Android SDK Manager
b. Go to Extras
c. Install Google Play Licensing Library
d. Find your SDK install path which is listed at the top of the SDK manager.
e. Once you are there, navigate to: <sdk>/extras/google/play_licensing
f. In eclipse, click file then import, then Existing Android Code Into Workspace and when it asks you for the file path, navigate to the play_licensing folder and click on library.
g. Once the project named library has been imported, right click it, then hit properties. Click Android on the left and navigate to the bottom and check Is Library, then hit apply. This lets eclipse know that you can use this project code as a library.
h. Right click on your app that you are adding licensing to, and click properties, then hit Android. Go to the bottom and click library and add it to the build path. This should import the library to the Android Dependencies folder.
i. Your project is set up to go to the next step.
2.2 Variables to declare along with your SALT and KEY
private Handler mHandler;
private LicenseChecker mChecker;
private LicenseCheckerCallback mLicenseCheckerCallback;
boolean licensed;
boolean checkingLicense;
boolean didCheck;
2.3 The code
Paste this code near the bottom of your app. This implementation will notify the user if the license is not valid and prompt them to buy the app or exit it.
private void doCheck() {
didCheck = false;
checkingLicense = true;
setProgressBarIndeterminateVisibility(true);
mChecker.checkAccess(mLicenseCheckerCallback);
}
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
#Override
public void allow(int reason) {
// TODO Auto-generated method stub
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
Log.i("License","Accepted!");
//You can do other things here, like saving the licensed status to a
//SharedPreference so the app only has to check the license once.
licensed = true;
checkingLicense = false;
didCheck = true;
}
#SuppressWarnings("deprecation")
#Override
public void dontAllow(int reason) {
// TODO Auto-generated method stub
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
Log.i("License","Denied!");
Log.i("License","Reason for denial: "+reason);
//You can do other things here, like saving the licensed status to a
//SharedPreference so the app only has to check the license once.
licensed = false;
checkingLicense = false;
didCheck = true;
showDialog(0);
}
#SuppressWarnings("deprecation")
#Override
public void applicationError(int reason) {
// TODO Auto-generated method stub
Log.i("License", "Error: " + reason);
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
licensed = true;
checkingLicense = false;
didCheck = false;
showDialog(0);
}
}
protected Dialog onCreateDialog(int id) {
// We have only one dialog.
return new AlertDialog.Builder(this)
.setTitle("UNLICENSED APPLICATION DIALOG TITLE")
.setMessage("This application is not licensed, please buy it from the play store.")
.setPositiveButton("Buy", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"http://market.android.com/details?id=" + getPackageName()));
startActivity(marketIntent);
finish();
}
})
.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNeutralButton("Re-Check", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
doCheck();
}
})
.setCancelable(false)
.setOnKeyListener(new DialogInterface.OnKeyListener(){
public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
Log.i("License", "Key Listener");
finish();
return true;
}
})
.create();
}
2.4 Getting your device id
There has been some debate about this in the past about whether or not to use the sim serial or TelephonyManager.getDeviceId(); but it is generally recommended you use the following code to get the ANDROID_ID of your device for maximum compatibility.
String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
Log.i("Device Id", deviceId); //AN EXAMPLE OF LOGGING THAT YOU SHOULD BE DOING :)
2.5 Creation of the license checker
a. Before you call doCheck(); you must put this code in your app to make sure everything gets created properly.
mHandler = new Handler();
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), BASE64_PUBLIC_KEY);
When I was doing my implemetation of LVL, I read that if you are having problems with Licensing, you can change the first this in the mChecker = new LicenseChecker(this... to getApplicationContext(), mine seemed to work without it, but just in case.
2.6 Adding permissions
a. There are two permissions that you need to add to your applications manifest file.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.CHECK_LICENSE"/>
2.7 Make sure you have the proper imports!
You have probably already done this, but I figured it would be a good place for you to check.
2.8 How to call the license to be checked
a. Simply call doCheck(); whenever you want to check the license. For example if the app is on its first run, do the check.
3. How do I test the licensing to make sure it works before publishing it?
3.1 Configuring the testing device
a. I have my personal phone that I also use for testing. It is recommended that there be only one Google account registered on the phone, historically it makes things a little easier. You can check the accounts by going to Settings -> Accounts.
3.2 Configuring the developer console
a. Open your developer console and go to Settings on the left hand side.
b. Find License Testing
c. Make sure that your email address is listed under Gmail accounts with testing access
d. Now, you can change the test response to whatever you like for testing purposes. The app should respond accordingly. Remember that if you are saving the data via SharedPrefs you will need to clear your app data every time you test it. Make sure that you click save after you change the test response or nothing will happen! I forgot about this multiple times and I ended up with a migraine, then I saw that stinking save button. Lol.
4. Things to try
4.1 Conditional license checking
a. You can try this code if you are saving the didCheck data in SharedPreferences.
if(didCheck==false){
Toast.makeText(this, "Checking application license...", Toast.LENGTH_SHORT).show();
doCheck();
Log.i("Checking!", "Checking license!");
}
4.2 Encrypting your SharedPreferences using SecurePreferences
a. Go to this link.
b. Copy and paste the code from SecurePreferences.java into a class with the exact same name into your project.
c. Read the ReadMe.md for info on implementing this.
5. Troubleshooting
Licensing can be one heck of a headache to troubleshoot, simply because there are many more things that can go wrong. For example, there could be network problems or server problems that make you want to rip your hair out. Use of proper logging will help with this, you can also get the server response codes if there is a problem and you can trace it to the server or your app. I have had to do this on multiple occasions.
5.1 I can't get my app to return anything from the server
Possible Fixes:
a. Make sure that your app has the correct KEY.
b. Make sure you are logging each step of the progress
c. Check your log for anything from the licensing service. It can be useful for figuring out where something went wrong.
d. Make sure allow() and dontAllow() and applicationError() have #Override tags.
5.2 My app always says LICENSED or NOT_LICENSED no matter what I set it to in the test response
a. The best cure I have for this is just to wait. It seems that if you do lots of testing in a short period of time, it will always send you server code 291 which is the retry code. I waited overnight and everything worked fine the next morning.
b. You can clear the data (not just cache) of the Google Play app and the Google Play Services app. Then open play back up and accept all the licenses and try again.
c. Clear your app data.
5.3 List of server response codes for debugging
You should get these decimal values for int reason if you log them. Use this table to reference what the server is actually sending to your app.
LICENSED = Hex: 0x0100, Decimal: 256
NOT_LICENSED = Hex: 0x0231, Decimal: 561
RETRY = Hex: 0x0123, Decimal: 291
LICENSED_OLD_KEY = Hex: 0x2, Decimal: 2
ERROR_NOT_MARKET_MANAGED = Hex: 0x3, Decimal: 3
ERROR_SERVER_FAILURE = Hex: 0x4, Decimal: 4
ERROR_OVER_QUOTA = Hex: 0x5, Decimal: 5
ERROR_CONTACTING_SERVER = Hex: 0x101, Decimal: 257
ERROR_INVALID_PACKAGE_NAME = Hex: 0x102, Decimal: 258
ERROR_NON_MATCHING_UID = Hex: 0x103, Decimal: 259
5.4 Room for more! They will come!
I hope this helps you guys! I tried to share my headaches and fixes with you guys as best I can and I hope this helps!
If I made any errors, be sure to tell me about them so I can get them fixed ASAP!