I'm using the APK expansion file in my application with the APEZProvider. This works on every device except Huawei devices. If the user wants to open a video it always comes to a RuntimeException and the video can't be played.
It happens on all Huawei devices (Android version is 8.0).
Is this a known issue with Huawei devices and how can I solve this problem?
Luckily this code is open source, so you can debug it yourself. The source code is here.
The relevant section:
int len = projection.length;
intProjection = new int[len];
for (int i = 0; i < len; i++) {
if (projection[i].equals(FILEID)) {
intProjection[i] = FILEID_IDX;
} else if (projection[i].equals(FILENAME)) {
intProjection[i] = FILENAME_IDX;
} else if (projection[i].equals(ZIPFILE)) {
intProjection[i] = ZIPFILE_IDX;
} else if (projection[i].equals(MODIFICATION)) {
intProjection[i] = MOD_IDX;
} else if (projection[i].equals(CRC32)) {
intProjection[i] = CRC_IDX;
} else if (projection[i].equals(COMPRESSEDLEN)) {
intProjection[i] = COMPLEN_IDX;
} else if (projection[i].equals(UNCOMPRESSEDLEN)) {
intProjection[i] = UNCOMPLEN_IDX;
} else if (projection[i].equals(COMPRESSIONTYPE)) {
intProjection[i] = COMPTYPE_IDX;
} else {
throw new RuntimeException();
}
Interesting things about this. Firstly, the line numbers don't match your line numbers. Secondly, the package name doesn't match the package name. Are you using the latest version? The bug may already have been fixed. The update which changed the package name also says "Updated for Marshmallow" which if you are getting breaks might explain why you are getting them on recent phones.
Related
I implemented IBM watson Assistant and it works perfectly fine on android debug. Problem comes when I build a signed apk. It always says Unauthorized. I don't think its the key because its working fine on debug mode. I need some help because the project is live.
What I have tried so far is to change the key in IBM cloud and tried other keys but it raises not found exception of which i think is caused by wrong key. Im I supposed to allow something in IBM cloud for signed apk? or is there a certificate from signed apk that I have to upload in IBM cloud?
Im using IBM watson Assistant v2
private Assistant watsonAssistant;
private Response<SessionResponse> watsonAssistantSession;
private void createServices() {
watsonAssistant = new Assistant("2020-04-01", new IamAuthenticator(getString(R.string.assistant_apikey)));
watsonAssistant.setServiceUrl(getString(R.string.assistant_url));
}
private void sendMessage(){
Thread thread = new Thread(() -> {
try {
if (watsonAssistantSession == null) {
ServiceCall<SessionResponse> call = watsonAssistant.createSession(new CreateSessionOptions.Builder().assistantId(getString(R.string.normal_assistant_id)).build());
watsonAssistantSession = call.execute();
}
MessageInput input = new MessageInput.Builder()
.text(userInput)
.build();
MessageOptions options = new MessageOptions.Builder()
.assistantId(getString(R.string.normal_assistant_id))
.input(input)
.sessionId(watsonAssistantSession.getResult().getSessionId())
.build();
Response<MessageResponse> response = watsonAssistant.message(options).execute();
if (response.getResult().getOutput() != null && !response.getResult().getOutput().getGeneric().isEmpty()) {
List<RuntimeResponseGeneric> responses = response.getResult().getOutput().getGeneric();
for (RuntimeResponseGeneric r : responses) {
switch (r.responseType()) {
case "text":
aiResponse = r.text();
aiConversationList.add(new AIConversation(r.text(), "ai", System.currentTimeMillis()));
break;
default:
Log.e("Error", "Unhandled message type");
}
}
runOnUiThread(() -> {
sendConvoToServer(userInput, aiResponse);
txtWelcomeAI.setVisibility(View.VISIBLE);
aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
userInputTxt.setEnabled(true);
pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
aStatus.setText("online");
});
}
} catch (Exception e) {
e.printStackTrace();
Log.e("IBM_EXCEPTION", e.toString());
aiConversationList.add(new AIConversation("Oops! Something went wrong", "ai", System.currentTimeMillis()));
aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
runOnUiThread(() -> {
pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
aStatus.setText("online");
userInputTxt.setEnabled(true);
});
}
});
thread.start();
}
In case anyone else will have a problem between debug and release apks like the one I had, try to check if you have done obfuscation. If so, then obfuscation is probably a problem. At least it was for me. So, either disable obfuscation from your build.gradle on app level or add some rules in proguard-rules
in android Asmack i want to set invisible user.
and i used from every mode but it didn't works. after that i used from Type ..
when i set type unavailable, it works . but there is a problem .. my pocket listener doesn't work .. and i cant get any thing from user .. What can i do .. Thanks a lot.
Type type = Presence.Type.available;
Mode OWN = Mode.available;
if (DB_STATUS.avibilaty.toString().equals("")) {
OWN = Mode.available;
} else if (DB_STATUS.avibilaty.toString().equals("away")) {
OWN = Mode.away;
} else if (DB_STATUS.avibilaty.toString().equals(
"available")) {
OWN = Mode.available;
} else if (DB_STATUS.avibilaty.toString().equals(
"unavailable")) {
type = Presence.Type.unavailable;
} else if (DB_STATUS.avibilaty.toString().equals("busy")) {
OWN = Mode.dnd;
}
Presence presence = new Presence(type);
presence.setMode(OWN);
I have an Android app to which I am trying to add DNS SRV record detection. I know it is possible, based on the existence of apps such as DNS Lookup, which I have installed, and it works just fine.
I am using dnsjava and this code runs fine as a stand-alone Java application on my machine, but when I run it on my Android device, I just get the "Error!" message:
Lookup lookup = new Lookup(serviceName, Type.SRV, DClass.IN);
Resolver resolver = new SimpleResolver();
lookup.setResolver(resolver);
lookup.setCache(null);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
String responseMessage = null;
String listingType = null;
for (int i=0; i < records.length; i++) {
if (records[i] instanceof SRVRecord) {
listingType = ((SRVRecord) records[i]).toString()
}
}
System.out.println("Found!");
System.out.println("Response Message: "+responseMessage);
System.out.println("Listing type: "+listingType);
} else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
System.out.println("Not found.");
} else {
System.out.println("Error!");
}
Any ideas why this isn't working?
Using a very different setup for SRV lookup in Android; I found they always failed with a 'not found', unless I add the following to my Android Manifest:
<uses-permission android:name="android.permission.INTERNET" />
I am not allowed to comment -- otherwise I would.
Make more else if statements, for example:
else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
System.out.println("Not found.");
} else if (lookup.getResult() == Lookup.TRY_AGAIN) {
System.out.println("Error!1");
} else if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) {
System.out.println("Error!2");
} else if (lookup.getResult() == Lookup.UNRECOVERABLE) {
System.out.println("Error!3");
}
Also, try changing: DClass.IN to DClass.ANY
Still new to Java/android so trying to figure out the best way to code a multilevel if statement. What I'm trying to do is for a combat system that needs to check if player/npc is alive. If they are alive it then will check to see if they scored a critical hit. If they didn't critical hit then will see if they hit or missed.
combat = mydbhelper.getCombat();
startManagingCursor(combat);
if (playerCurHp == 0) {
combat.moveToPosition(11);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (playerCritFlag.equals("Critical")) {
combat.moveToPosition(2);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (playerHitFlag.equals("Hit")) {
combat.moveToPosition(1);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
if (playerHitFlag.equals("Miss")) {
combat.moveToPosition(3);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
}
}
if (npcCurHp == 0) {
combat.moveToPosition(10);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (npcCritFlag.equals("Critical")) {
combat.moveToPosition(5);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (npcHitFlag.equals("Hit")) {
combat.moveToPosition(4);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
if(npcHitFlag.equals("Miss")) {
combat.moveToPosition(6);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
}
}
Is what I'm using. Was working when I had the if statements all separate. But it would check each one and do actions I don't need (If they hit, pull String, if crit pull another, then if dead pull again). Trying to make it stop when it finds the "Flag" that matches. When doing my rolls if the player hits it sets the flag to "Hit" like below code.
Random attackRandom = new Random();
int attackRoll = attackRandom.nextInt(100);
totalAtt = attackRoll + bonusAttack + weaponAtt + stanceAtt;
Random defensiveRandom = new Random();
int defenseRoll = defensiveRandom.nextInt(100);
npcDef = defenseRoll + npcDodge + npcBonusDodge;
if (totalAtt > npcDef) {
playerHitFlag = "Hit";
playerDamage();
} else {
playerHitFlag = "Miss";
npcAttack();
}
At the end it takes these playerCombatStory and npcCombatStory strings and uses them to setText to show the player what happened on that turn of combat.
I think you are looking for the else if statement:
if (condition) {
}
else if (other_condition) {
}
else if (another_condition) {
}
else {
// There can only be one else statement in a given if-else block
}
Your question isn't clear. But meaningful advice can still be offered.
Personally, I find this code hard to read. I think it'll be hard to maintain in the future as your logic becomes more complex.
I think you need to decouple the logic of what's done from how you decide. Encapsulate what's done in a Command object and use a map or state machine to look up what to do.
I would change the type of npcCritFlag to int or enum. Then use switch statement with case
This should look much better and easier to understand
I had gotten reports from a few users that they couldn't login to our app (which makes HTTP calls to our site) or visit our website in their browser, so I added some code to our latest build to check what IP our host name is resolving to. I've gotten reports from several different users now that they get 127.0.0.1 for our hostname when the app starts, which obviously isn't going to work.
They claim they aren't running any proxy software, and this happens on both 2.1 and 2.2. This also happens on both wifi & 3g, which makes me suspect it is some piece of software on their phone that is interfering with DNS resolution somehow. Does anyone know of any popular software that might do that? Or does anyone have any ideas about how to identify which software might be doing it?
Thanks,
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.TXTRecord;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
public class DNSLookUpActivity extends Activity {
private String url = "https://spectracore.americanlogistics.com/rdac/AdmissionController/CheckMddAdmission";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
funDNS(url);
}
private static void funDNS(String url) {
try {
Lookup lookup = new Lookup(url, Type.ANY);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
String responseMessage = null;
String listingType = null;
for (int i = 0; i < records.length; i++) {
if (records[i] instanceof TXTRecord) {
TXTRecord txt = (TXTRecord) records[i];
for (Iterator j = txt.getStrings().iterator(); j
.hasNext();) {
responseMessage += (String) j.next();
}
Log.e("TXRecord ", "" + responseMessage);
} else if (records[i] instanceof ARecord) {
listingType = ((ARecord) records[i]).getAddress()
.getHostAddress();
Log.e("ARecord address : ", "" + listingType);
}
}
}
} catch (TextParseException e) {
e.printStackTrace();
}
}
}
Need android ask version 2.3.3 or above
Get their DNS config, and try their DNS servers directly with dig or nslookup. This is not perfect, but it has a good chance of showing you the problem.
dnsjava/org.xbill.DNS is too big for android app, Scott Means's DNSQuery is promiseful:
http://smeans.com/programming/dns-queries-in-java/