I am developing a mobile application that need to implement mqtt. I need to publish the data to the mqtt broker, but it always fail to be published when i try to publish the image data which is the byte array of the image.
It didn't show any error when publish, but it did not published any data on the broker when I try to publish the message. The message can only be published when image data is removed from the payload which is the pichex.
Each data published on the mqtt broker need to be converted into hex ascii code. The byte array of image also need to be converted into hex ascii string code before publish to the broker as it is the requirement of the project.
private void publish(){
String command = "000000";
String reserve = "303030303030303030303030303030303030303030303030";
String tag = "tag";
name = eTname.getText().toString();
price = eTprice.getText().toString();
type = TypeS.getSelectedItem().toString();
desc = eTdesc.getText().toString();
userid = MainActivity.getGetuserid();
String namehex = toHexString(name);
String pricehex = toHexString(price);
String typehex = toHexString(type);
String deschex = toHexString(desc);
String useridhex = toHexString(userid);
Bitmap PicBitmap = ((BitmapDrawable)iVpic.getDrawable()).getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PicBitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] picbyte = bos.toByteArray();
String pichex = bytesToHex(picbyte);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
Date currentTime = Calendar.getInstance().getTime();
String currentTimeString = df.format(currentTime);
String payload = "{command:" + command + ", reserve:" + reserve + ", Client ID:" + serverConnectTo + ", Posted name:" + namehex +
", Posted Price:" + pricehex + ", Posted Type:" + typehex + ", Posted Description:" + deschex
+ ", Posted Picture:" + pichex + ", Date Time Posted:" + currentTimeString + ", User ID:" + useridhex + "}";
byte[] encodedPayload = new byte[0];
try {
encodedPayload = payload.getBytes();
MqttMessage message = new MqttMessage(encodedPayload);
message.setQos(qos);
mqttClient.publish(topic, message);
} catch (MqttException e) {
e.printStackTrace();
}
}
public static String toHexString(String input) {
return String.format("%x", new BigInteger(1, input.getBytes()));
}
public static String bytesToHex(byte[] in) {
final StringBuilder builder = new StringBuilder();
for(byte b : in) {
builder.append(String.format("%02x", b));
}
return builder.toString();
}
The hex string value of the picture that need to be published is:
89504e470d0a1a0a0000000d49484452000005dc0000046508020000002ce5923a0000000373424954080808dbe14fe00000200049444154789cecbd617723c971b41b91550dcecaf6bde7feff3ff99ed7d60e89ae8cb81fb21a046738eb5dd9d648de7c3ca74d8140a3d16842aa4064046da3699aa6699aa6699aa6699aa6f9fb123ffb009aa6699aa6699aa6699aa669fe8cb428d3344dd3344dd3344dd3344df3136851a6699aa6699aa6699aa6699ae627d0a24cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f408b324dd3344dd3344dd3344dd3343f8116659aa6699aa6699aa6699aa6697e022dca344dd3344dd3344dd3344dd3fc045a94699aa6699aa6699aa6699aa6f909b428d3344dd3344dd3344dd3344df3136851a6699aa6699aa6699aa6699ae627d0a24cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f408b324dd3344dd3344dd3344dd3343f8116659aa6699aa6699aa6699aa6697e022dca344dd3344dd3344dd3344dd3fc045a94699aa6699aa6699aa6699aa6f909b428d3344dd3344dd3344dd3344df3136851a6699aa6699aa6699aa6699ae627d0a24cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f408b324dd3344dd3344dd3344dd3343f8116659aa6699aa6699aa6699aa6697e022dca344dd3344dd3344dd3344dd3fc045a94699aa6699aa6699aa6699aa6f909b428d3344dd3344dd3344dd3344df3136851a6699aa6699aa6699aa6699ae627d0a24cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f408b324dd3344dd3344dd3344dd3343f8116659aa6699aa6699aa6699aa6697e022dca344dd3344dd3344dd3344dd3fc045a94699aa6699aa6699aa6699aa6f909b428d3344dd3344dd3344dd3344df3136851a6699aa6699aa6699aa6699ae627d0a24cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f408b324dd3344dd3344dd3344dd3343f8116659aa6699aa6699aa6699aa6697e02f3671f40d3344dd334efd8fef476927fe723699aa6699aa669fea769a74cd3344dd3344dd3344dd334cd4fa04599a6699aa6699aa6699aa6699a9f007f64936e9aa6699ae6bfceffd6ff9eed71aaa6699aa6699aff3aed94699aa6699aa6699aa6699aa6f90974d06fd3344dd3fc0ff2479d323f72a0fcb3386eda41d3344dd3344df3fb69a74cd3344dd3344dd3344dd334cd4fa09d324dd334cd3f0e02e2f76dffd1d00f6eff8d4315003300c00100140d00bcf656de1813340002a0f77fbcb6a2c3fce4fcf0a3b1c6bfcbbff2cd7eb09ff53b0c00e3e36dff2c0699c73bf5d3afa2ffeaf56c80bf7bfb47f967793b9ba6699ae69f9d16659aa6699a7f08840404f8f76d11df8a028f1d95b0f1ad4a221b1f876bc881f7b1a06f17a13f9ac29116be1fd2a1ae95efd3fe4100b157dcdf2cbc251880616094624204692851a7822421844192b4e120609990ec12659c701808d2e400b49f58d8c7493e6b460fa1e71b02248c0fff0000593bfab0ae37c8083fbda8c770d5b75356b46d40833f941e6c5fe7874f0fff5ce7fad178d456b21c00fce15dae03defb34b27efa8342c88feffefb658f6faf493d6d7fdf113d092d3244c477dbf10321f38f427faecbf4745ad3344dd3fcf7d2a24cd3344df30f857edff68faca9fd2e95d87eacea9f7ffee4417e3cf8039f3c84c256165442cfd32373bb60b616f05826bb9ec11fc50e1ab400818265c4a5cb2004386107606400b658af2261264823499a2aed263c002088787f9eefe598ebf4d01f45193e8e09803faceb83012760204a5279fc3ee2c9cb53f7787e033e39cf7efaf947f7fa6fe1f1127eeb78fe30bcb67fece0bfbfaa8bdff4ce3c2ee33ff4547f137c1719bf77de344dd3344df3df468b324dd334cd3f0e7f406a11fcae1becdb1ede930f8e8beb37d7ddf97cf3e507f86e99cb3fb8f265d9771e5acef5033fc82e4f7e1f8b60c0861d0410cfde0463ab29306cc35652a8bb03591a90edeb1cc80049030eda41879d00288204b7c981e5d7783a09fbac6c4bcf77ee0a7d761e9c008cbc5e65c0b1c7a6f6d68008d4d604307ec3b4719d2e3f7efe1b0383b71b259e5ed96ff007aeb73ae1df8b26efc7c9efefffed2e9eee5f7b90afcb8cef27fac329faccb0c2ba3900e2fb2d3fbdfd37f9d64f435c7f5d0e501fb6faee96921da3c59aa6699aa6f95b6851a6699aa6f987803f5842fb7371247e674acab593a79f7fd320f37b77e86fa496bde4f677a2ccb5d6fd60a588e774182cba06a904972d0690418009b0e68a980b166c486599b10540a897a3c7cb34610719b1a36a68925b9121be1365ea883476bacd9553b32d323f3c57ba13a083e425338579e5e3f83a1ebbb4a2271bcea767d2d710d3b61d919fff4f941fb7503d396ef0dff0167f47d997f0b40d50f68f148fff5cf1f19308755dcef9b4c565aafab85b1a105d7a5b001fb6c02004c4c7ed374ffc24a93c5edd472ebd53bf77fba371c2a6699aa6697e9316659aa6699a7f107eb488fdcf1d2b359cb3e76cfce497f96617bf31b8c4672fcdfb7e2ebe5db2fa7dd90c97c5410abc4b3397b1e2c10727821e712c1610e6b96f96390c0b346c7098212060e55bd8b56b695d4f7165a9ec85f17ed5368023af27211911d8f932789c193dfb6554d136212a1c8f8c924fd40d07a859278db1137e38f6e9535624f1f5300134e23de7e69b9dbdcf8925ec876664e71f0c
This is the image that need to publish
The size of the picture is about 100KB.
The message can be published only when the image data is removed from the payload which is the pichex:
String payload = "{command:" + command + ", reserve:" + reserve + ", Client ID:" + serverConnectTo + ", Posted name:" + namehex + ", Posted Price:" + pricehex + ", Posted Type:" + typehex + ", Posted Description:" + deschex + ", Date Time Posted:" + currentTimeString + ", User ID:" + useridhex + "}";
The message can be received by subscriber if pichex is removed:
{command:000000, reserve:303030303030303030303030303030303030303030303030, Client ID:Server, Posted name:627572676572, Posted Price:392e3939, Posted Type:6e6f6f646c65, Posted Description:616a6468, Date Time Posted:2018-10-14 08.09.29, User ID:696b6f6d61}
Related
Is it possible to save a logcat entry in a sqlite database?
If a user got an error I want to read the logs without having the phone connected to adb.
This is how I write logs: Log.d(TAG, "An error occured", e)
Thanks
Creating a log file will be better option to read error
public void mlogFile(String pActivityName, String pOperation, String pData) {
File lLogFilePath, lLogFile;
Date lDate;
CharSequence lCurrfolder;
FileWriter lFileWriter;
BufferedWriter lBuffWriter;
String lActivity, lOperation;
try {
lDate = new Date();
lCurrfolder = DateFormat.format("yyyyMMdd", lDate.getTime());
lLogFilePath = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "CSPDCLData/" + lCurrfolder + "/");
if (!lLogFilePath.exists()) {
lLogFilePath.mkdirs();
}
lLogFile = new File(lLogFilePath, "ADDLogfile.txt");
lFileWriter = new FileWriter(lLogFile, true);
lBuffWriter = new BufferedWriter(lFileWriter);
lActivity = pActivityName.length() != 0 ? ADDPadding(pActivityName, 25, ' ', 'L') + "~ " : "";
lOperation = pOperation.length() != 0 ? " : " + pData : "";
lBuffWriter.append(DateFormat.format("kk:mm:ss", lDate.getTime()) + " " + lActivity + pOperation + lOperation + "\n");
lBuffWriter.flush();
lBuffWriter.close();
lFileWriter.close();
} catch (IOException ex) {
Toast.makeText(this, "ERROR: " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}
}
And at the time of error add this line
logFile(getClass().getSimpleName(),"methodName()", "An error occured"+ e.getMessage());
I'm installing Hybrid Ranking algorithm for Linked Data Extraction & Context on Android. Documents you can search Google for the keywords above.
And now I'm installing semantic similarity between two uri1 and uri2.
Input: two DBpedia URIs
Output: a value representing their similarity
private float similarity(String uri1, String uri2) {
float wikipedia = wikiS(uri1, uri2);
float abtract = abtractS(uri1, uri2);
float google = engineS(uri1, uri2, google);
float yahoo = engineS(uri1, uri2, yahoo);
float bing = engineS(uri1, uri2, bing);
float dilicious = engineS(uri1, uri2, dilicicous);
return wikipedia + abtract + google + yahoo + bing + dilicious;
}
And with each child function, I have to query data using SPARQL dbpedia, google, yahoo, bing, dilicious using provided API. The results obtained will be calculated to the parser and returns the corresponding float value.
Example for abtractS(uri1, uri2) below:
private float abstractS(String uri1, String uri2, final float wikiS){
String url = createUrlAbstractS(uri1, uri2);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
float abtractS = 0.0f;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray data = jsonObject.getJSONObject("results").getJSONArray("bindings");
if(data.length() == 0){
showLogAndToast("No result");
}else{
JSONObject element = data.getJSONObject(0);
String label1 = element.getJSONObject("label1").getString("value");
String abtract1 = element.getJSONObject("abtract1").getString("value");
String label2 = element.getJSONObject("label2").getString("value");
String abtract2 = element.getJSONObject("abtract2").getString("value");
abtractS = calWordContained(label1, abtract2) + calWordContained(label2, abtract1) + wikiS;
//TODO: RESULT ABTRACTS HERE. How next?
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(request);
return 0.0f;//HERE: no results
}
private float calWordContained(String label, String abtract){
if(label.length() == 0 || abtract.length() == 0){
return 0.0f;
}
List<String> words = Arrays.asList(label.split(" "));
int count = 0;
float length = words.size();
for(int i = 0; i < length; i++){
if(abtract.toLowerCase().contains(words.get(i).toLowerCase())){
count++;
}
}
return (count/length);
}
public String createUrlAbstractS(String uri1, String uri2){
private String BASE_URL_DBPEDIA = "http://dbpedia.org/sparql?default-graph-uri=&query=";
String query = createQueryAbstractS(uri1, uri2);
String url = "";
try {
url = Config.BASE_URL_DBPEDIA + URLEncoder.encode(query, "UTF-8") + Config.RESULT_JSON_TYPE;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return url;
}
private String createQueryAbstractS(String uri1, String uri2){
String query = Config.PREFIX_DBPEDIA + " \n" +
"prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n" +
"\n" +
"\n" +
"select ?label1, ?label2, ?abtract1, ?abtract2 where\n" +
"{\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri1 + "> rdfs:label ?label1 ;\n" +
" dbpedia-owl:abstract ?abtract1 .\n" +
" FILTER langMatches(lang(?abtract1),'en') . \n" +
" FILTER langMatches(lang(?label1),'en') .\n" +
" }\n" +
" }\n" +
"\n" +
"\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri2 + "> rdfs:label ?label2 ;\n" +
" dbpedia-owl:abstract ?abtract2 .\n" +
" FILTER langMatches(lang(?label2),'en') . \n" +
" FILTER langMatches(lang(?abtract2),'en') .\n" +
" }\n" +
" }\n" +
"}";
return query;
}
but how to do this on, I could not get the results I wanted in the similarity function (uri1, uri2). Therefore it will affect the results in different functions.
So I'm asking is: how can I get all the results of the function Wikis, abtractS, engine (google), engine (bing), engine (yahoo), engine (dilicious) in a simple way Best. I currently do on Android and data load times is very important.
Thank you very much!
I am trying to add Oauth1 Authorization in my android app using volley
in the postman when i add the details like oauth_consumer_key, oauth_consumer_secret , token_key token_secret like the picture below
it generate a header like below picture and response received successfully.
Postman generated header
Authorization:OAuth oauth_consumer_key="4e77abaec9b6fcda9kjgkjgh44c2e1",oauth_token="2da9439r34104293b1gfhse2feaffca9a1",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1482470443",oauth_nonce="cCbH5b",oauth_version="1.0",oauth_signature="A1QPwTATVF4x3cN0%2FN46CZrtSKw%3D"
Problem
I googled a lot to create oauth signature like postmasn created to attach volley ServerConnectionChannel but failed.
oauth_signature="A1QPwTATVF4x3cN0%2FN46CZrtSKw%3D"
Current code
public void doSendJsonRequest(final ERequest ERequest) {
requestMethod = String.valueOf(ERequest.method);
requestUrl = String.valueOf(ERequest.mReqUrl);
if(requestMethod.equals(Request.Method.GET)){
requestMethod = "GET";
}else if(requestMethod.equals(Request.Method.POST)){
requestMethod = "POST";
}else if(requestMethod.equals(Request.Method.PUT)){
requestMethod = "PUT";
}else if(requestMethod.equals(Request.Method.DELETE)){
requestMethod = "DELETE";
}
Long tsLong = System.currentTimeMillis()/1000;
final String ts = tsLong.toString();
final String kk = requestMethod+"&" + encode(requestUrl)+"&";
final String kk = encode("GET"+"&"
+ requestUrl+"&"
+ OAUTH_CONSUMER_KEY + "=\"4e77abaec9b6fcda9b11e89a9744c2e1\"&"
+OAUTH_NONCE + "=\"" + getNonce()+ "\"&"
+OAUTH_SIGNATURE_METHOD + "=\""+OAUTH_SIGNATURE_METHOD_VALUE+"\"&"
+OAUTH_TIMESTAMP + "=\"" + ts + "\"&"
+OAUTH_TOKEN +"=\"2da943934104293b167fe2feaffca9a1\"");
RequestQueue queue = VolleyUtils.getRequestQueue();
try {
JSONObject jsonObject = ERequest.jsonObject;
EJsonRequest myReq = new EJsonRequest(ERequest.method, ERequest.mReqUrl, jsonObject, createReqSuccessListener(ERequest), createReqErrorListener(ERequest)) {
public Map < String, String > getHeaders() throws AuthFailureError {
// Long tsLong = System.currentTimeMillis()/1000;
// String ts = tsLong.toString();
String strHmacSha1 = "";
String oauthStr = "";
strHmacSha1 = generateSignature(kk, oAuthConsumerSecret, oAuthTokenSecret);
strHmacSha1 = toSHA1(strHmacSha1.getBytes());
Log.e("SHA !",strHmacSha1);
oauthStr ="OAuth "+ OAUTH_CONSUMER_KEY + "=\"4e77abaec9b6fcda9b11e89a9744c2e1\","
+OAUTH_TOKEN +"=\"2da943934104293b167fe2feaffca9a1\","
+OAUTH_SIGNATURE_METHOD + "=\""+OAUTH_SIGNATURE_METHOD_VALUE+"\","
+OAUTH_TIMESTAMP + "=\"" + ts + "\","
+OAUTH_NONCE + "=\"" + getNonce()+ "\","
+OAUTH_VERSION + "=\"" + OAUTH_VERSION_VALUE + "\","
+OAUTH_SIGNATURE + "=\"" + strHmacSha1+ "\"";
Log.e("VALUE OF OAuth str",oauthStr);
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json");
params.put("Authorization",oauthStr);
// params.put("Authorization",getConsumer().toString());
return params;
}
};
myReq.setRetryPolicy(new DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 4,
BABTAIN_MAX_RETRIES,
BABTAIN_BACKOFF_MULT));
myReq.setHeader("Cache-Control", "no-cache");
//myReq.setHeader("Content-Type", "application/json");
queue.add(myReq);
} catch (Exception e) {
e.printStackTrace();
}
private String generateSignature(String signatueBaseStr, String oAuthConsumerSecret, String oAuthTokenSecret) {
byte[] byteHMAC = null;
try {
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec spec;
if (null == oAuthTokenSecret) {
String signingKey = encode(oAuthConsumerSecret) + '&';
spec = new SecretKeySpec(signingKey.getBytes(), "HmacSHA1");
} else {
String signingKey = encode(oAuthConsumerSecret) + '&' + encode(oAuthTokenSecret);
spec = new SecretKeySpec(signingKey.getBytes(), "HmacSHA1");
}
mac.init(spec);
byteHMAC = mac.doFinal(signatueBaseStr.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
String base64 = Base64.encodeToString(byteHMAC, Base64.DEFAULT);
return base64.trim();
}
private String toSHA1(byte[] convertme) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
}
catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}
return byteArrayToHexString(md.digest(convertme));
}
private String byteArrayToHexString(byte[] b) {
String result = "";
for (int i=0; i < b.length; i++)
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
return result;
}
this code create a signature like :oauth_signature="42a611860e29e893a435b555e7a9559a704f4e94" and it failed to get autherization.
getting error like : BasicNetwork.performRequest: Unexpected response code 401 for url
?How to generate oauth_signature like postman provided using volley..
?how can i improve this code ?Is any libraries or default function to do that
?How we add oauth1 signature in volley..
Please Help.. Thank you
I just found a github example for generating signature corresponding to nonce in Oauth1 and successfully integrate into my project
here is the link : https://github.com/rameshvoltella/WoocommerceAndroidOAuth1
I have an app that reads notifications to the driver while driving. I am trying to parse the various notifications. Those that use the old 'tickerText' work fine but several apps like Skype don't support that. Instead, the text in the notification after the first message just says something like "3 new messages". Not very helpful. I want the last message string instead. I wrote this:
public class Catcher extends NotificationListenerService {
File file;
String dir;
File save;
int count = 0;
#Override
public void onCreate() {
super.onCreate();
dir = Environment.getExternalStorageDirectory() + "/NotCatch";
save = new File(dir);
if(!save.exists()){
save.mkdirs();
}
//Toast.makeText(this, dir + " " + file.getName(), Toast.LENGTH_LONG).show();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
file = new File(save, "NotCatch" + count + ".txt");
count++;
String temp = "";
String[] lines;
Notification not = sbn.getNotification();
temp += "Category: " + not.category+ "\n";
temp+= "TickerText: " + not.tickerText + "\n";
temp += "Extras..."+ "\n";
Bundle bun = not.extras;
temp+= "BigText: " + bun.getString(Notification.EXTRA_BIG_TEXT)+ "\n";
temp+= "SummaryText: " + bun.getString(Notification.EXTRA_SUMMARY_TEXT)+ "\n";
temp+= "InfoText: " + bun.getString(Notification.EXTRA_INFO_TEXT)+ "\n";
temp+= "Text: " + bun.getString(Notification.EXTRA_TEXT)+ "\n";
temp+= "TextLines: " + bun.getString(Notification.EXTRA_TEXT_LINES)+ "\n";
temp+= "SubText: " + bun.getString(Notification.EXTRA_SUB_TEXT) + "\n";
temp+= "Title:" + bun.getString(Notification.EXTRA_TITLE) +"\n";
temp+= "Big Title:" + bun.getString(Notification.EXTRA_TITLE_BIG) +"\n";
/* lines = bun.getString(Notification.EXTRA_TEXT_LINES).split("\n");
temp += "Lines... \n" ;
int cnt = 0;
for (String line : lines) {
temp+= cnt + ": " + line + "\n";
cnt++;
}*/
Looper.prepare();
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(temp.getBytes());
fos.close();
Toast.makeText(this,"File written", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
This is just what I have so far for testing of course. I can get the bundle from the notification but it can't get the string array of the message lines. It looks like this in the debugger. 'bun' below is the 'Bundle' from the 'Notification'.
My question is this. How do I get the array of strings that start with "some message text - 4"? This is the bundle from an Android Notification.
I finally was able to get the strings this way
CharSequence[] lines = bun.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
for(CharSequence line : lines){
temp+= "line: " + line.toString() + "\n";
}
Since the strings you are trying to retrieve are contained in the ArrayMap mMap (according to the debugger image), and as implementations of Map are serializable, you'll want to do the following to first retrieve that map:
ArrayMap map = bun.getSerializableExtra("mMap");
Then, you should be able to get the array of strings you want (which according to the debugger image is an array of CharSequence objects) with the following:
CharSequence[] messages = (CharSequence[]) map.valueAt(1);
An interesting read on bundles and maps:
https://medium.com/the-wtf-files/the-mysterious-case-of-the-bundle-and-the-map-7b15279a794e#.kf3m2haa3
I am writing an Android application in which I am using Jackrabbit WebDAV Library.
With help of this WebDAV library, I can download and upload files from and to server. This works as expected.
Now I want to get a byte array from file with specific offset from the server. For this what I have tried is:
byte buffer[] = null;
Log.d(TAG, "downloadBytes '" + fileUri + "' byteOffset '" + byteOffset + "' byteOffset '" + byteCount);
HttpClient httpClient = new HttpClient();
GetMethod httpMethod = new GetMethod(fileUri);
httpMethod.addRequestHeader("Accept-Ranges", "bytes");
int total = byteOffset + byteCount;
String bytesMessage = "bytes=" + byteOffset + "-" + total;
Log.d(TAG, "bytesMessage " + bytesMessage);
httpMethod.addRequestHeader("Range", bytesMessage);
httpMethod.addRequestHeader("Cache-Control", "no-cache, no-store");
httpClient.executeMethod(httpMethod);
This works as expected.
Similarly, I want to update file on server with byte array by specifying offset, but this doesn't appear to work; the server returns a 400 Bad Request error code.
byte buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50};
Log.d(TAG, "downloadBytes '" + fileUri + "' byteOffset '" + byteOffset + "' byteCount '" + byteCount);
HttpClient httpClient = new HttpClient();
PutMethod httpMethod = new PutMethod(fileUri);
httpMethod.addRequestHeader("Accept-Ranges", "bytes");
int total = byteOffset + byteCount;
String bytesMessage = "bytes=" + byteOffset + "-" + total;
Log.d(TAG, "bytesMessage " + bytesMessage);
httpMethod.addRequestHeader("Range", bytesMessage);
httpMethod.addRequestHeader("Cache-Control", "no-cache, no-store");
httpMethod.addRequestHeader("Overwrite", "T");
InputStream is = new ByteArrayInputStream(buffer);
RequestEntity requestEntity = new InputStreamRequestEntity(is, "text/plain");
httpMethod.setRequestEntity(requestEntity);
httpClient.executeMethod(httpMethod);
What am I missing in the request header?
Following are correct headers, using this I am able update webdav server resources with offset and byte length.
HttpClient httpClient = new HttpClient();
PutMethod httpMethod = new PutMethod(fileUri);
httpMethod.addRequestHeader("Accept-Ranges", "bytes");
int total = byteOffset + byteCount;
int range = total-1;
String rangeMessage = "bytes=" + byteOffset +"-" + range;
Log.d(TAG, "rangeMessage " + rangeMessage);
String lengthMessage = Integer.toString(byteCount);
String contentRangeMessage = "bytes " + byteOffset +"-" + range + "/*";
Log.d(TAG, "contentRangeMessage " + contentRangeMessage);
Log.d(TAG, "lengthMessage " + lengthMessage);
httpMethod.addRequestHeader("Content-Length", lengthMessage);
httpMethod.addRequestHeader("Content-Range", contentRangeMessage);
httpMethod.addRequestHeader("Cache-Control", "no-cache, no-store");
httpMethod.addRequestHeader("Overwrite", "T");