App launched from phone doesn't behave as from android studio - Android Studio

App launched from phone doesn't behave as from android studio
Function load data works fine on phone when app is run from android studio via USB, but not when launched from the icon on the phone.
private fun loadSteps() {
val file = File(filesDir, "data.txt")
// Read data from the file
if (file.exists()) {
val input = FileInputStream(file)
val buffer = ByteArray(input.available())
input.read(buffer)
input.close()
// Convert the JSON string to a list of DataBlock
val json = String(buffer)
allSteps = DataBlock.fromJson(json) ?: mutableListOf()
}
val today = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.time
if (allSteps.isEmpty()) {
// Add a new DataBlock with today's date and steps = 0
allSteps.add(DataBlock(today, 0))
} else {
val latestDate = allSteps.last().date
var latestCalendar = Calendar.getInstance().apply { time = latestDate }
val currentDate = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}
// Add new DataBlocks for missing dates between the latest date and today
while (latestCalendar.before(currentDate)) {
latestCalendar.add(Calendar.DATE, 1)
allSteps.add(DataBlock(latestCalendar.time, 0))
}
}
}
This part work ok
if (file.exists()) {
val input = FileInputStream(file)
val buffer = ByteArray(input.available())
input.read(buffer)
input.close()
// Convert the JSON string to a list of DataBlock
val json = String(buffer)
allSteps = DataBlock.fromJson(json) ?: mutableListOf()
}
but the rest of the code doesn't get executed. This is my first app and I ran into a wall.
Any thoughts?
Thanks for your reply!
Problem solved:
I have called this function within onCreate, so when app resumed or started it did not got called.

Related

[APP] Netflix APK

Just leaked. Whether it works or not seems to be hit or miss.
See 2 posts down for apk.
Just leaked where? This thread is useless without a link.
Where is it?
Sorry...here is the actual apk
Thank you....checking it out now.
It let me log in and could view my queue but when tried to play 3 different movies it said could not reach the netflix service. Good find though. Maybe it will start working soon.
Just tested, no dice. streaming doesn't seem to be working correctly
Sent from my Captivate
I just get either an endless loading screen or an error regarding not reaching the netflix server...
I heard someone has it working on their Fascinate.
I tried it on my captivate running cognition 4.1.1 but it didn't work
Sent from my SAMSUNG-SGH-I897 using XDA Premium App
Its the foot print the phone leaves. I logged into my account and it showed sgh-i897 as an obsolete device on my account. Any chance we can get the binary embedded in the app for a compatible device?
Sent from my SAMSUNG-SGH-I897 using XDA Premium App
didnt work for me :/
Doesn't work. Dammit.
jferg5 said:
Its the foot print the phone leaves. I logged into my account and it showed sgh-i897 as an obsolete device on my account. Any chance we can get the binary embedded in the app for a compatible device?
Sent from my SAMSUNG-SGH-I897 using XDA Premium App
Click to expand...
Click to collapse
Yeah, it seems to be a drm issue, maybe we can find a possible work around?
Sent from my Galaxy S Captivate with Serendipity
wont even let me sign in:/
Just found this thread with the DRM files and Revolution system dump (full):
http://forum.xda-developers.com/showthread.php?t=994768
so my Java script isn't that great, but as far as I can tell, the nrdp.js file might lead us in the right direction.
In the script it is grabbing a lot of information about the device and passing across.
Pulled from the file
Code:
if (typeof nrdp != 'undefined')
{
return;
}
nrdp = new Object();
nrdp.debug = ##NRDP_DEBUG##;
nrdp.exit = function()
{
n_device_api.exit();
};
nrdp.device = new Object();
nrdp.device.getSoftwareVersion = function()
{
return String(n_device_api.getSoftwareVersion());
};
nrdp.device.getCertificationVersion = function()
{
return String(n_device_api.getCertificationVersion());
};
nrdp.device.getESN = function()
{
return String(n_device_api.getESN());
};
nrdp.device.getESNPrefix = function()
{
return String(n_device_api.getESNPrefix());
};
nrdp.device.setUIVersion = function(version)
{
n_device_api.setUIVersion(version);
};
nrdp.device.isScreensaverOn = function()
{
return (n_device_api.isScreensaverOn() == 'true');
};
nrdp.device.hasPointer = function()
{
return (n_device_api.hasPointer() == 'true');
};
nrdp.device.hasKeyboard = function()
{
return (n_device_api.hasKeyboard() == 'true');
};
nrdp.device.hasOnScreenKeyboard = function()
{
return (n_device_api.hasOnScreenKeyboard() == 'true');
};
nrdp.device.getLanguage = function()
{
return String(n_device_api.getLanguage());
};
nrdp.device.launchUrl = function(url)
{
n_device_api.launchUrl(url);
};
nrdp.device.notifyOnLogin = function()
{
n_device_api.notifyOnLogin();
};
nrdp.device.notifyOnLogout = function()
{
n_device_api.notifyOnLogout();
};
nrdp.device.injectKey = function(keyCode)
{
n_device_api.injectKey(keyCode);
};
nrdp.device.isConnected = function()
{
return (n_device_api.isConnected() == 'true');
};
nrdp.webapi = new Object();
nrdp.webapi.getConsumerKey = function()
{
return n_web_api.getConsumerKey();
};
nrdp.webapi.getConsumerSecret = function()
{
return String(n_web_api.getConsumerSecret());
};
nrdp.webapi.hmacSha1 = function(key, plaintext, handler)
{
try
{
if (typeof(handler) !== 'undefined' && handler !== null)
{
var encValue = n_web_api.hmacSha1(key, plaintext);
handler(encValue);
}
}
catch (e)
{
console.log('ERROR: ' + e);
}
};
nrdp.video = new Object();
nrdp.video.setGlobalEventListener = function(listener)
{
var events = String(n_video_api.getEvents());
var eventArray = events.split(" ");
if(typeof(listener) != 'undefined' && listener != null)
{
for(i = 0; i < eventArray.length; i++){
document.addEventListener(eventArray[i], listener, false);
}
} else {
for(i = 0; i < eventArray.length; i++){
document.removeEventListener(eventArray[i], nrdp.video._globalEventListener, false);
}
}
nrdp.video._globalEventListener = listener;
};
nrdp.video.addEventListener = function(type, listener, useCapture)
{
document.addEventListener(type, listener, useCapture);
};
nrdp.video.removeEventListener = function(type, listener, useCapture)
{
document.removeEventListener(type, listener, useCapture);
};
nrdp.video.dispatchEvent = function(evt)
{
document.dispatchEvent(evt);
};
nrdp.video._dispatchEvent = function(evt_type, evt_name)
{
var evt = document.createEvent(evt_type);
evt.initEvent(evt_name, true, true);
nrdp.video.dispatchEvent(evt);
};
nrdp.video._dispatchProgressEvent = function(evt_type, evt_name, loaded, total)
{
var evt = document.createEvent(evt_type);
evt.initEvent(evt_name, false, false);
evt.loaded = loaded;
evt.total = total;
evt.lengthComputable = true;
evt.loadedItems = 0;
evt.totalItems = 0;
nrdp.video.dispatchEvent(evt);
};
nrdp.video.getLastPlayedMovieData = function()
{
return eval('(' + String(n_video_api.getLastPlayedMovieData()) + ')');
};
nrdp.debug = new Object();
nrdp.debug.console = new Object();
nrdp.debug.console.log = function(message)
{
console.log(message);
};
nrdp.debug.console.warn = function(message)
{
console.log('WARN: ' + message);
};
nrdp.debug.console.error = function(message)
{
console.log('ERROR: ' + message);
};
The day this is hacked is the day netflix removes it from the list of allowable streaming apps.
Did some packet sniffing and found references to this XML:
http://uiboot.netflix.com/apps/android/config
Code:
<config>
<current_version>1</current_version>
<min_version>1</min_version>
<mandatory>true</mandatory>
<current_version_url>http://mcdn.netflix.com/us/mobile/android/01/netflix-01-release.apk</current_version_url>
<size>2943920</size>
</config>
The "current_version_url" is not found though.. Looks like they pulled it after the leak or something.
It's probably due to the fact that they intially released the Netflix APK to run only on Phones with a Snapdragon Processor, not a hummingbird.
At least that's what I read in the news a week or two ago.
id10terror said:
Did some packet sniffing and found references to this XML:
http://uiboot.netflix.com/apps/android/config
Code:
<config>
<current_version>1</current_version>
<min_version>1</min_version>
<mandatory>true</mandatory>
<current_version_url>http://mcdn.netflix.com/us/mobile/android/01/netflix-01-release.apk</current_version_url>
<size>2943920</size>
</config>
The "current_version_url" is not found though.. Looks like they pulled it after the leak or something.
Click to expand...
Click to collapse
So, I toyed around with the 'current_version_url' you mentioned and changed the end to the following "...android/02/netflix-02-release.apk" and it downloaded.
I loaded it on my cappy...I can browse around and whatnot but still no watch instantly. It just sits there...doesn't even say loading.

Help on appending to a file

Hi guys. I am trying to save sensor data to a file and figured out how to do it. Only thing is how do I keep updating the file and append new data without over writing?
I created two functions, one for saving and one for appending:
Code:
public void saveToFile(String accelLine, String gyroLine) throws IOException {
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File Dir = new File(root.getAbsolutePath());
if(!Dir.exists()) {
Dir.mkdir();
}
senLine = accelLine + gyroLine;
File file = new File(Dir, "senData.txt");
FileOutputStream fos = new FileOutputStream(file);
fos.write(senLine.getBytes());
fos.write('\n');
fos.close();
Toast.makeText(getApplicationContext(), "Initial Data Saved!", Toast.LENGTH_LONG).show();
newFile = 0;
senLine = "";
}
Code:
public void appendToFile(String accelLine, String gyroLine) throws IOException {
senLine = accelLine + gyroLine;
FileOutputStream fos = openFileOutput("senData.txt", Context.MODE_APPEND);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(senLine);
osw.write('\n');
osw.flush();
osw.close();
Toast.makeText(getApplicationContext(), "More Data Saved!", Toast.LENGTH_LONG).show();
newFile = 0;
senLine = "";
}
Maybe my implementation is wrong? Could someone tell me what did I do wrong? Its my first time with Android and Java. Sorry!

Problem in Bluetooth transmitting comparisation

Hi. I want to ask some comparison problem in Android studio. I have implement a bluetooth data receiving code in Android studio to receive data from Arduino. If it receive "abcde", an audio should be play (mysound). But it can't play as expected. May I ask what is the problem in the below code? Thank you.
Arduino:
BT.println("abcde");
Android:
h = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case RECIEVE_MESSAGE: // if receive massage
byte[ ] readBuf = (byte[ ]) msg.obj;
String strIncom = new String(readBuf, 0, msg.arg1); // create string from bytes array
sb.append(strIncom); // append string
int endOfLineIndex = sb.indexOf("\r\n"); // determine the end-of-line
//txtArduino.setText(strIncom);
if (endOfLineIndex > 0) { // if end-of-line,
String sbprint = sb.substring(0, endOfLineIndex); // extract string
sb.delete(0, sb.length()); // and clear
txtArduino.setText(sbprint); // update TextView
if(sbprint=="abcde"){
mySound.start();}
break;
}
};
};

Parse Json from URL - Google Finance Quote - PROBLEM

Hi there,
I have an issue with writing my app. I want to obtain the data (as shown below) and get the corresponding value from it. When I run my app on the emulator it crashes when I click the button, precisely on this line:
Code:
JSONObject jsonObject = json.getJSONObject(0);
Can someone at least, please skim through and let me know what I could be doing wrong. It must be something simple, because I am not trying to break into CIA from my phone.
This is a data from the link:
HTML:
// [ { "id": "304466804484872" ,"t" : "GOOG" ,"e" : "NASDAQ" ,"l" : "759.66" ,"l_fix" : "759.66" ,"l_cur" : "759.66" ,"s": "0" ,"ltt":"4:00PM EDT" ,"lt" : "Sep 9, 4:00PM EDT" ,"lt_dts" : "2016-09-09T16:00:03Z" ,"c" : "-15.66" ,"c_fix" : "-15.66" ,"cp" : "-2.02" ,"cp_fix" : "-2.02" ,"ccol" : "chr" ,"pcls_fix" : "775.32" } ]
Here is my class:
Code:
public JSONArray getJson(String url){
// Read response to string
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL Url = new URL(url);
connection = (HttpURLConnection) Url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line+"\n");
}
is.close();
result = sb.toString();
} catch(Exception e) {
return null;
}
// Convert string to object
try {
String token[] = result.split("//");
JSONArray jarr = new JSONArray (token[1]);
} catch(JSONException e){
return null;
}
return jarr;
}
This is how I use it on a click of a button:
Code:
quotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Constructing a URL
String urlprefix = "http://finance.google.com/finance/info?client=ig&q=";
String Symbol = editTextSymbol.getText().toString();
String Exchange = editTextExchange.getText().toString();
String url = urlprefix + Exchange + ":" + Symbol;
JSONArray json = getJson(url);
try {
JSONObject jsonObject = json.getJSONObject(0);
String id = jsonObject.getString("id");
EditTextQuoteTime.setText(id);
} catch (JSONException e){
EditTextQuoteTime.setText("ERROR");
}
//try {
// String id = json.getString("id");
// EditTextQuoteTime.setText(id);
//} catch (JSONException e){
// EditTextQuoteTime.setText("ERROR");
// }
}
});
I know I may have asked a question that is widely available online, but most of the posts are from the time before which the libraries were updated and parsing from the URL changed. Most of the posts are slightly different and I feel I am missing something.
I think I have a main problem with decoding the actual JSON string which is shown in the HTML above. I don't know how to omit the first few signs and then get my string from there. Can anyone help, please?

[HELP] why Zygisk need to force dlopen /system/bin/app_process

1. Why use android_dlopen_ext in the first_stage_entry function to force open /system/bin/app_process?
2. Why dlclose immediately after dlopen in second_stage_entry? Why do it?
// native/jni/zygisk/entry.cpp
static void first_stage_entry() {
android_logging();
ZLOGD("inject 1st stage\n");
char path[PATH_MAX];
char buf[256];
char *ld = getenv("LD_PRELOAD");
if (char *c = strrchr(ld, ':')) {
*c = '\0';
strlcpy(path, c + 1, sizeof(path));
setenv("LD_PRELOAD", ld, 1); // Restore original LD_PRELOAD
} else {
unsetenv("LD_PRELOAD");
strlcpy(path, ld, sizeof(path));
}
// Force the linker to load the library on top of ourselves, so we do not
// need to unmap the 1st stage library that was loaded with LD_PRELOAD.
int fd = xopen(path, O_RDONLY | O_CLOEXEC);
// Use fd here instead of path to make sure inode is the same as 2nd stage
snprintf(buf, sizeof(buf), "%d", fd);
setenv(MAGISKFD_ENV, buf, 1);
struct stat s{};
xfstat(fd, &s);
android_dlextinfo info {
.flags = ANDROID_DLEXT_FORCE_LOAD | ANDROID_DLEXT_USE_LIBRARY_FD,
.library_fd = fd,
};
// 通过 inode 在 maps 中搜索 /sbin/magisk(app_process) 对应的内存区域
auto [addr, size] = find_map_range(path, s.st_ino);
if (addr && size) {
// 下面使用 android_dlopen_ext 重复加载 /sbin/magisk,
// 通过 reserved_addr 强制覆盖内存.
info.flags |= ANDROID_DLEXT_RESERVED_ADDRESS;
info.reserved_addr = addr;
// The existing address is guaranteed to fit, as 1st stage and 2nd stage
// are exactly the same ELF (same inode). However, the linker could over
// estimate the required size and refuse to dlopen. The estimated size
// is not accurate so size the size to unlimited.
info.reserved_size = -1;
}
setenv(INJECT_ENV_2, "1", 1);
// Force dlopen ourselves to make ourselves dlclose-able.
// After this call, all global variables will be reset.
// 重复加载 /sbin/magisk 到内存, 覆盖之后全局变量将被重置
// 这里为什么要强制 dlopen? 只是为了以后可以使用 dlclose 释放 zygisk 吗????
android_dlopen_ext(path, RTLD_LAZY, &info);
}
Code:
// // native/jni/zygisk/entry.cpp
static void second_stage_entry() {
zygisk_logging();
ZLOGD("inject 2nd stage\n");
char path[PATH_MAX];
MAGISKTMP = getenv(MAGISKTMP_ENV);
int fd = parse_int(getenv(MAGISKFD_ENV));
snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
xreadlink(path, path, PATH_MAX);
android_dlextinfo info {
.flags = ANDROID_DLEXT_USE_LIBRARY_FD,
.library_fd = fd,
};
// 这里的dlopen并不会重新调用 zygisk_init, 这里是假的dlopen? 只是为了下一行的 dlclose?
// 为什么要这样做?
// Why do this?
self_handle = android_dlopen_ext(path, RTLD_LAZY, &info);
dlclose(self_handle);
close(fd);
unsetenv(MAGISKTMP_ENV);
unsetenv(MAGISKFD_ENV);
sanitize_environ();
hook_functions();
}

Categories

Resources