I am setting up and testing in-app billing. I managed to purchase the android.test.purchased, and it did what it should. But now I need to consume it to continue my testing. The problem is that I can't reach the inventory.
When this is called I get the result.isFaliure() is called and I can't get the inventory.
IabHelper.QueryInventoryFinishedListener _gotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (_iabHelper == null) return;
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
_isPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Log.d(TAG, "User is " + (_isPremium ? "PREMIUM" : "NOT PREMIUM"));
update();
}
};
It logs the error message
Failed to query inventory: IabResult: Error refreshing inventory
(querying owned items). (response: -1003:Purchase signature
verification failed)
The android.test.purchased is still owned - it won't let me buy it again. My phone has network connection so it's not that.
I have NOT uploaded a signed APK to Google Play, does that matter even if I test with googles static ID's?
Solved it...
It seems there are problems with the static purchase ID's.
Here's a sollution I found in THIS thread:
If you have used the android.test.purchased then one way to get rid of the error is to do the following:-
1. Edit Security.java and change the "return false" line in the
verifyPurchase to "return true" - this is temporary, we'll be
putting it back in a minute.
2. In your QueryInventoryFinishedListener, after the "if
(result.isFailure()) {...}" lines add the following to consume and
get rid of your never ending android.test.purchased item:-
if (inventory.hasPurchase(SKU_ANDROID_TEST_PURCHASE_GOOD)) {
mHelper.consumeAsync(inventory.getPurchase(SKU_ANDROID_TEST_PURCHASE_GOOD),null);
}
3. Run your app so the consunmeAsync happens, this gets rid of the
"android.test.purchased" item on the server.
4. Remove the consumeAsync code (or comment it out). Back in the
Security.java, change the "return true" back to "return false".
I found the answer here:
"Here's a recommendation: Make sure that your Billing Key (base64EncodedPublicKey) is properly saved. That was my problem, after all that..."
base64EncodedPublicKey was from another aplication...
It was solution for me.
Related
Before answer or taking any action just by seeing the question title please read description carefully, I am trying to do this yesterday and today a full day and night but I couldn't find any acceptable solution. Some are deprecated from android some are not working, some are just checking internet is just connected or not. But that's not what I am asking for.
I have applied many Stack Overflow answers in this regard but nothing is working perfectly. The functionality I am asking for is,
say MathActivity.java and activity_math.xml is a page loaded after clicking a button from mainActivity.java. When MathActivity.java is starting after clicking the button its primarily can check active internet connection via the ping method. Though its not working properly,
public boolean checkIntCON() {
try {
Process ipProcess = Runtime.getRuntime().exec("/system/bin/ping -c 1 8.8.8.8");
return (ipProcess.waitFor() == 0);
}
catch (IOException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
return false;
}
But its check just one time when I am entering [I did that work but I don't want that], say user is reading a pdf in activity_math.xml and when user reading this user turned off internet connection, I am also able to listen that functionality when user turn off connection this would be ok but if user again turn on data with internet unavailability then I can't listen this .
I want to get recent and maximum device supported solution to check in continues internet connection. say user is reading a pdf, after five minutes I want to check if the user have an active internet connection or not. Connection should be must transferrable internet connection. I have found AsyncTask solution but its deprecated. The main focus is I want to check user active internet connection after a certain interval.
Here is an image to explain more,
Is there any solution? If any please try to give me in detail code that i just want to copy and paste in project. I have visited all in stack overflow again I am mentioning.
Pass context and call the function, I think this is what you are looking for.
public static boolean isConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
Log.d("VIP", "isConnected: " + capabilities.getTransportInfo() + " down stream " + capabilities.getLinkDownstreamBandwidthKbps() +
" up stream " + capabilities.getLinkUpstreamBandwidthKbps() + " Cellular " + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
+ " WiFi " + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) + " Ethernet " + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET));
return capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET);
} else {
NetworkInfo networkInfo = Objects.requireNonNull(connectivityManager).getActiveNetworkInfo();
boolean b = networkInfo != null && networkInfo.isConnected() && networkInfo.getDetailedState() != NetworkInfo.DetailedState.VERIFYING_POOR_LINK;
Log.d("VIP", "isConnected: else is connected " + b);
return b;
}
}
reposting this question since I didn't get any responses the first time around. Parse doesn't appear to have any simple means of contacting them about this (which is frustrating), so I really hope someone here can help.
I am currently using Parse to create a messaging app. I have two fundamental ParseObjects in addition to the standard ParseUser, a Chatroom and a Message. A Chatroom contains pointers to the two users in the Chatroom. A Message contains the content of the Message, a pointer to the user who posted it, and a pointer to the Chatroom.
First, I create a list of all the Chatrooms that the current user is in. Then, I'm trying to create a second list of the most recent message in all of these Chatrooms (I have made it impossible to make a Chatroom without sending at least one Message first).
My code looks like this:
TextView mostRecent = (TextView) row.findViewById(R.id.mostRecent);
Date dt1 = null;
ParseQuery lastMessage = ParseQuery.getQuery("Message");
ParseObject chatroom = (ParseObject) roomList.get(position);
Log.w("Chatroom ObjectID...", room.getObjectId());
try {
lastMessage.whereEqualTo("chatroom", chatroom.fetchIfNeeded());
List<ParseObject> allMessages = lastMessage.find();
Log.w("# of Messages...", "Size of the list: " + allMessages.size() + ", Count of query: " + allMessages.count());
if (allMessages.size() > 0) {
mostRecent.setText((String) theList.get(theList.size() - 1).get("content"));
dt1 = allMessages.get(allMessages.size() - 1).getCreatedAt();
}
} catch (ParseException err) {
err.printStackTrace();
Log.w("PARSE ERROR", err.getMessage());
}
This code works for every Chatroom where the current user is the one who created the Chatroom and the Message in that Chatroom. However, whenever I have a different user attempt to start a Chatroom and send a Message to the original user, the code fails.
To be clear, the second user successfully creates both a Chatroom and a Message. I've verified that the Chatroom gets successfully added to the original user's list of Chatrooms, and that the Message contains a pointer to the correct Chatroom. However, for whatever reason, the Logs reveal a list size of 0 and a count of 0. I've even tried querying for the second user's exact message on the original user's account, and it claims the thing doesn't exist.
Any ideas? Could this have something to do with ACL? Thanks in advance!
NOTE: I've confirmed that both users are correctly included in the Message's ACL. What gives? Why isn't this working?
You need to wait for the query to fetch the data.
lastMessage.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> allMessages, ParseException e) {
if (e == null) {
Log.w("# of Messages...", "Size of the list: " + allMessages.size() + ", Count of query: " + allMessages.count());
} else {
Log.w("Exception thrown", e.getMessage());
}
}
}
I'm looking into a way to tie a running task id into it's corresponding process ID (pid).
The context is a system service which is deployed as part of the platform that needs to monitor the current activity in the foreground, I can use the entire AOSP platform, but I cannot change it.
I have the following code in my service to get the activity stack:
private List<StackInfo> getStack() throws Exception
{
Log.i(TAG, "getStack");
List<StackInfo> stacks = null;
stacks = mAm.getAllStackInfos();
return stacks;
}
and this is the monitoring thread:
private class MonitorThread extends Thread
{
public void run()
{
while (true)
{
try
{
Log.i(TAG, "In MonitorThread");
Thread.sleep(1000);
StackInfo fore = getStack().get(0);
String name = fore.taskNames[fore.taskIds.length-1];
name = name.substring(0, name.indexOf("/"));
/* Next line is where I have the problem, I'm getting the task id (activity id) instead of the PID for the process */
Log.i(TAG, "Current FG PID: "+fore.taskIds[fore.taskIds.length-1] + " name: "+ name + "\n");
}
catch (Exception e)
{
Log.i(TAG, "---=== EXCEPTION!!! ===---");
Log.i(TAG, e.getMessage());
Log.i(TAG, "---=== END EXCEPTION!!! ===---");
}
}
}
}
These achieve the goal of getting the process name that is currently in the foreground by taking the top most activity name from the active stack and trimming the activity name from the result (e.g activity name com.example/MainActivity belongs to process com.example).
So far I have two methods of achieving this, both are far from ideal:
The bad way:
I can iterate every application in the system and look up the current activity in it's activity stack, once a match is found, I can use the application PID (inefficient, O(M) where M is the total number of tasks)
The even worst way
The task names return as com.package.xxx/activity_name where the part preceding the '/' is the process name (as far as I can tell, anyhow). Once I have that, I can call 'ps | grep com.package.xxx' and parse the output for the PID (I really don't want shell calls)
All I can find online is how to get the opposite - all activities that belong to an application.
Anyone has a better idea?
Thanks!
You can get your activity PID by:
int id= android.os.Process.myPid();
To find the PID of Others activities check this link. With ActivityManager you can find all running processes, find the desired activity and then get it's PID...
Here I am trying to get ASSET details in simple java
Here is the code
MXSession session = MXSession.getSession();
session.setHost("localhost:13400/MXServer");
session.setUserName(user);
session.setPassword(pwd);
session.connect();
The connection was successful.
Then I tried to get the asset details with the code
MboSetRemote assetMboSet = session.getMboSet("ASSET");
assetMboSet.setOrderBy("ASSETNUM");
MboRemote assetMbo;
for(int j=0; ((assetMbo = assetMboSet.getMbo(j)) != null); j++)
{
String assetNum = assetMbo.getString("ASSETNUM");
String location = assetMbo.getString("LOCATION");
String desc = assetMbo.getString("DESCRIPTION");
System.out.println(assetNum + " - " + location + " - " + desc);
}
it is giving me the error and could not proceed further in the line
MboSetRemote assetMboSet = session.getMboSet("ASSET");
saying
Exception in thread "main" psdi.util.MXSystemException: system#unknownerror
at psdi.util.RMISession.getMboSet(RMISession.java:330)
Please suggest me how to proceed
My friend I just tried your code scripth and it works fine, here is a snapshot of my environment which shows your work.
This problem may occur, If the admin mode is on OR you need to change take a look at sessions, to do that.
you can go to the users application.
Select action > manage sessions.
You can view users who are currently logged into the system.
You can log out a user from the system or log out and block a user from the system.
You can see the login history of users.
I am writing an Android application to read input from a HID USB foot pedal (press the pedal, get a message, do something).
The UsbManager is not recognizing the device. The foot pedal may be throwing an error in Android kernel when it plugs in, because I see this error message in the logcat:
"EventHub could not get driver version for /dev/input/mouse0, not a typewriter"
However, I know the foot pedal works, because when I plug it in and press it, it changes the focus to the next button on the activity... So I know it is communicating with my Nexus tablet and apparently its default action is to move the focus to the next button/object. I don't think there are any problems with my code, since it will recognize other USB devices, just not this foot pedal. I can actually tell when it's pressed by checking for when the focus changes, but that won't work for what I want since this app will run in the background as a service. I've tried setting an intent filter for this specific USB device (I know its product id and vendor id). However, it still shows no connected devices and the pop-up message that is supposed to ask the user to confirm launching the application never shows up. I've tried just listing all the connected USB devices as well, but I always get an empty list.
Is there any way to intercept input from this device so I can tell when the foot pedal gets pressed, even though Android's USB Manager will not recognize it?
For completeness, here is my code. I am testing on a Galaxy Nexus 10 tablet:
public int list_usb_devices()
{
int device_count = 0;
UsbManager mUsbManager;
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
String LOG_TAG = "USB";
for (UsbDevice device : mUsbManager.getDeviceList().values()) {
//This code is never reached...
Log.d(LOG_TAG, "Detected device: " + device.toString());
Log.d(LOG_TAG, "Model: " + device.getDeviceName());
Log.d(LOG_TAG, "Id: " + device.getDeviceId());
Log.d(LOG_TAG, "Class: " + device.getDeviceClass());
Log.d(LOG_TAG, "Protocol: " + device.getDeviceProtocol());
Log.d(LOG_TAG, "VendorId: " + device.getVendorId());
Log.d(LOG_TAG, "ProductId: " + device.getProductId());
CharSequence text = device.toString();
show_toast(text);
device_count++;
}
return device_count;
}
I did some research in the Android source and it seems that all HID boot devices (mouse, keyboard etc.) are blacklisted and can therefore not be accessed using the USBManager API.
Here is the relevant part from the UsbHostManager.java , see here: http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/com/android/server/usb/UsbHostManager.java/?v=source
/* returns true if the USB device should not be accessible by applications */
private boolean isBlackListed(int clazz, int subClass, int protocol) {
// blacklist hubs
if (clazz == UsbConstants.USB_CLASS_HUB) return true;
// blacklist HID boot devices (mouse and keyboard)
if (clazz == UsbConstants.USB_CLASS_HID &&
subClass == UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
return true;
}
return false;
}