java – Strange problems with the Spring RestTemplate in Android application

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png”;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png”;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png”;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php”, { postid: jpostid, thisid : jthisid , rating: 2, count: 3 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

I begin to use RESTful api of the Spring Framework in my android client application. But I have encountered with problems when I tried to execute HTTP request via postForObject/postForEntity methods. Here is my code:

public String _URL = \"https://noticemed.com/app/mobile/login\";
public void  BeginAuthorization(View view)
{     
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON);
         HttpEntity<String> _entity = new HttpEntity<String>(requestHeaders);
        RestTemplate templ = new RestTemplate();
        templ.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
        templ.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
        ResponseEntity<String> _response = templ.postForEntity(_URL,_entity,String.class); //HERE APP CRASHES
        String _body = _response.getBody();

And here is a stack trace in logcat after app crashing.

enter image description here

As you see there is no definite error message.

So the question what am I doing wrong? How to fix this? May there is other way to do it?

I really need a help. Thanks in advance!

Rating: 2 out of 5 based on 3 ratings

The post java – Strange problems with the Spring RestTemplate in Android application appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/java-strange-problems-with-the-spring-resttemplate-in-android-application.html

java – Android File Read and Write

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 3, count: 4 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

I am new to Android programming and so kingly pardon me if this question sounds stupid. I want to read and write from a file in an Android Program. I am aware of how to do that in Java.

Having read the documentation I wrote the following code. However I am unable to locate where this file is. According to the documentation it should be in folder data/data/package_name.

I have Samsung Galaxy S2. I launched the application, then closed it. When I went looking for the file I could not find it. I looked in My Files/data. But there is no data folder inside this data folder. What am I doing wrong?

Thank you for the help.

Sources:
1. http://developer.android.com/training/basics/data-storage/files.html
2. http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html#overview

public class MainActivity extends Activity {

private void writeFileToInternalStorage() {
      String eol = System.getProperty(\"line.separator\");
      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new OutputStreamWriter(openFileOutput(\"myfile.txt\", MODE_WORLD_WRITEABLE)));
        writer.write(\"This is a test1.\" + eol);
        writer.write(\"This is a test2.\" + eol);
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
        if (writer != null) {
        try {
          writer.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
        }
      }
}   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    writeFileToInternalStorage();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

Rating: 3 out of 5 based on 4 ratings

The post java – Android File Read and Write appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/java-android-file-read-and-write.html

android – why some configuration in AndroidManifest goes inside “application” section and some not?

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 1, count: 3 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

While writing Android manifest some configuration I must put inside \”application\” section (eg. list of activities) and some outside it (eg. uses-sdk). Why? Is there any general rule what goes inside \”application\” section and what outside? Or was it pure random arbitrary decision by Android creators?

Rating: 1 out of 5 based on 3 ratings

The post android – why some configuration in AndroidManifest goes inside "application" section and some not? appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/android-why-some-configuration-in-androidmanifest-goes-inside-application-section-and-some-not.html

android – First Application Install time

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 4, count: 3 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

I have been trying to get the first install time of a certain package in the android system! ( third party application ) I used package info to get details and from that, FirstInstallTime() method to get the date and time. but it returns a log value that I have no idea converting! can any one help me to convert this value to a date time value!

Thank you.

Rating: 4 out of 5 based on 3 ratings

The post android – First Application Install time appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/android-first-application-install-time.html

How to use StartForeground for service android

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 2, count: 3 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

I have a Main activity, which can start a service using this command

startService(new Intent(Main.this, Myservice.class));

and Myservice class is like this

   public class Myservice extends Service {
private ShakeListener mShaker;
String startell;
SharedPreferences prefs;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    // TODO Auto-generated method stub


    //Something

}

@Override
public void onStart(Intent intent, int startId) {
    // TODO Auto-generated method stub

    //Do Something to detecting shake
            //Show my notification


}


@Override
public void onDestroy() {
    // TODO Auto-generated method stub

    //Stop Shake detection
            //stop notification


    super.onDestroy();
}


}

and my applications works fine, but after about one hour, service stops automatically, i mean after about one hour shake detection dose not work any more. :(

I googled a bit and I found I should use StartForeground, but I didn\’t find how.

Now, how should I use StartForeground in my code?

Rating: 2 out of 5 based on 3 ratings

The post How to use StartForeground for service android appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/how-to-use-startforeground-for-service-android.html

Android vs Java causing some confusion for me when creating methods

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 1, count: 4 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

I was helping a friend on his Java homework today, and I guess I didn\’t realize there being a difference between plain Java and Java in Android. Quick write up of the program:

    public class myClass{
public static void Main (String[] args){
doThis();
}
public void doThis(){
System.out.println(\"Did this\");
}
}

But when running that, I got a complaint that I needed to make the doThis() method to be static. Why is that? When I develop some basic things in Android, I never have to use the static keyword.

Note: This could stem from the fact that I\’m intimidated by what static actually means.

Rating: 1 out of 5 based on 4 ratings

The post Android vs Java causing some confusion for me when creating methods appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/android-vs-java-causing-some-confusion-for-me-when-creating-methods.html

design – Can android activity be designed without having to override all kinds of lifecycle methods?

function starhover(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starhover.png&#8221;;
}
function starout(thisid) {
document.getElementById(thisid).src=”http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/star.png&#8221;;
}
function starup() {
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}
function stardown(jthisid) {
document.getElementById(jthisid).src = “http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/starclick.png&#8221;;
var jpostid=document.getElementById(jthisid).className;
$.post(“http://androidask.phpfogapp.com/wp-content/plugins/wp-reviewstars-premium/updatepostmeta.php&#8221;, { postid: jpostid, thisid : jthisid , rating: 4, count: 3 });
document.getElementById(‘stargroup’).innerHTML=’thank you for your vote!’;
}

When I write my activities on android, I have to override a lot of \”lifecycle\” methods, such as #code#Pm9uQ3JlYXRlPA==#/code#, onActivityResult:

class MyAcitivity extends Activity {

    @Override
    public void onCreate(...) {}

    @Override
    public void onStart(...) {}

    @Override
    public void onActivityResult(...) {}

    @Overide
    public void onBackPressed(...) {}
}

I don\’t like this, because I found my logical code are split to everywhere in my class. I do some operation in this method, but I have to handle the result in another method.

Is it the only way to design Activity like this? Is there any other solution can let me do the same without overriding methods from super classes?


Update

I do some operation in this method, but I have to handle the result in another method.

For example:

public void onCreate(...) {
    startActivityForResult(new Intent(this, AnotherAcitity.class), INTENT_ANOTHER);
}

public void onActivityResult(...) {
    if(requestCode == INTENT_ANOTHER)  {
        // do something
    }
}

Update again

I know how to use these lifecycle methods, what I\’m thinking is the \”design\”. Is there any different way to design android (in theory) without \”overriding lifecycle methods\” to write activities. Does ios and win8 on mobiles use the same design as android? If I develop an ios or win8 application, do I have to override all kinds of lifecycle methods as I do on android?

Rating: 4 out of 5 based on 3 ratings

The post design – Can android activity be designed without having to override all kinds of lifecycle methods? appeared first on Android ASK.

via Android ASK http://androidask.phpfogapp.com/design-can-android-activity-be-designed-without-having-to-override-all-kinds-of-lifecycle-methods.html