|
Let us see the code you have done so far , so we correct it
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Hello,
I have a super simple php script that runs successfully when I paste the url into a browser (windows, chrome).
(http:
My php code has values hardcoded in it and these values are successfully inserted into mySql database (running on a WAMP).
At this point EVERYTHING is hardcoded in the php.
I appreciate any help, I think I am missing something fundamental (new to android development).
Problem:
I can not access/run this same script from my andoroid app. Do I need to run it async? I simply have the below code in a function that is run when the button is clicked on the phone (using an emulator so phone displays app while I am in debug mode in Android.)
Clues:
It bombs out on the last line. Strangely debug (IOException) value is blank.
Manifest has:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
*************Code Snippet
URL url;
HttpURLConnection connection = null;
url = new URL("http://xxx.xxx.xxx/myscript.php");
connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(3000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.connect(); <---DIES HERE
************End Code
|
|
|
|
|
Member 13416547 wrote: Strangely debug (IOException) value is blank. Where are you catching this at? I do not see any reference to it in the code snippet you've shown.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Sorry David, below is the full function. When I run the app on the phone it just closes down. (I reworked code and it doen't go to CATCH now.) If I comment out the
connection.connect(); line, it runs thru with no error. If I paste the url (http://xxx.xxx.xxx/myscript.php) into a browser it works and inserts a record into my table.
private void Testphp2() {
try {
URL url;
HttpURLConnection connection = null;
url = new URL("http://xxx.xxx.xxx/myscript.php");
connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(3000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
Toast.makeText(getApplicationContext(), "About to try", Toast.LENGTH_LONG).show();
connection.connect();
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "error" , Toast.LENGTH_LONG).show();
}
}
|
|
|
|
|
|
Member 13416547 wrote: (I reworked code and it doen't go to CATCH now.) Because you are trying to catch a specific exception. Try using Exception instead. Have you considered the exception's getMessage() method?
Also, I suggest using Log.d() calls instead of popping up Toast messages when debugging.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks David, I will look at using Exception & getMessage as well as log.d (I am new to android dev as you can probably tell.)
|
|
|
|
|
if any one know then tell me.
when application is in background, then how to read notification?
|
|
|
|
|
Notification messages are only received in onMessageReceived() when the app is in the foreground. When the app is in the background, an automatically generated notification is displayed. When the user taps on the notification they are returned to the app.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks for reply.
But actually I want to update one value in sqlite after getting a notification. I had done code with this in message received method but problem is that, when app is in background, then I will get notification but can't update value in sqlite.
So tell me any solution.
|
|
|
|
|
Otherwise tell me how to get text or title from notification.
Or notification on click listener.
|
|
|
|
|
Malashree Halade wrote: Otherwise tell me how to get text or title from notification. The RemoteMessage parameter that is passed to onMessageReceived() .
See here for more.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
i wnt some link which i got android app develoment .
|
|
|
|
|
? ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Have you tried Google? Have you tried the CodeProject articles section?
|
|
|
|
|
|
Good Day All
i have a Navigation Drawer which is defined like this
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:background="#0099ff"
android:layout_height="fill_parent" />
and when one of my drawer item is selected i have this code
FragmentTransaction fragmentTx = this.FragmentManager.BeginTransaction();
Fragment1 aDifferentDetailsFrag = new Fragment1();
fragmentTx.Add(Resource.Id.content_frame, aDifferentDetailsFrag);
<pre>
fragmentTx.Commit();
Toast.MakeText(this, "Home:", ToastLength.Long).Show();</pre>
and Fragment1 is defined like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
<pre>
android:paddingLeft="12dp"
android:paddingRight="12dp">
<Button
android:textSize="24dp"
android:textColor="#FFF"
android:id="@+id/btn_details_file_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HOME" />
and the cs is defined like this
public class Fragment1 : Fragment
{
<pre>
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.Inflate(Resource.Layout.Fragment1, null, false);
}
}</pre>
when i run this , i only get a toast message, the Fragment1 does not show which has a button that is having text "home"
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Good Day Everyone
I have an activity class defined like this
[Activity(Label = "Activity_Home", MainLauncher = false, Icon = "@drawable/lenderlogo", Theme = "@style/MyTheme")]
public class Activity_Home : ActionBarActivity
{
and the activity is hosting a Tab that display its content from a fragment. A fragment is defined separately and it has a button that is defined like this
<Button
android:textSize="10sp"
android:textColor="#FFF"
android:id="@+id/btn_details_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="btn_details_saveClick"
android:text="Continue" />
as you can see i have a click event that is triggered when the button is clicked. The code to handle the event of the button is defined in the fragment class file like this
Button btn_details_save = FindViewById<Button>(Resource.Id.btn_details_save);
btn_details_save.Click += delegate
{
btn_details_saveClick();
};
and he function itself is defined like this
public void btn_details_saveClick()
{
}
Now when i run the application, the button is click the button the following error occurs
AndroidRuntime(19059): java.lang.IllegalStateException: Could not find method btn_details_saveClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class Button with id 'btn_details_save'
Please note that this is C# code , which means i am using xamarin ,but the error is Android related not Xamarin.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
My first concern is that you are declaring the click handler twice: once in the layout file, and again in code. Use one or the other, but not both.
Second, you need to change btn_details_saveClick() to accept a View parameter. This is what the error message is actually telling you.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks for your reply David
"My first concern is that you are declaring the click handler twice: once in the layout file, and again in code. Use one or the other, but not both."
I thought we have to add the click event on the layout file and add hookup the event to the button also in the initialization of the Activity. i learned, thanks. i am coming from asp.net background
i have changed my function in my frament page to be like this
public void btn_details_saveClick(View view)
{
had
and i ran it and i got the Error
java.lang.IllegalStateException: Could not find a method btn_details_saveClick(View) in the activity class android.support.v7.widget.TintContextWrapper for onClick handler on view class android.support.v7.widget.AppCompatButton with id 'btn_details_save'
i have also have a example project( 9mb) on this link Example Project
To Reproduce the Error
1) Open the drawer
2) Click on loan application and click the button "Continue" and you will get an Error
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
modified 30-Aug-17 18:00pm.
|
|
|
|
|
Does the btn_details_saveClick() method belong to the same class that 'owns' the layout?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
If you are defining the click-handler in the .xml file, the click-handler must be implemented in the activity not the fragment. If you are defining the click-handler in the .cs file, the click-handler can be implemented in the fragment.
You'll notice in that example that the btn_details_saveClick() method is contained within the activity PersonalDetailsView rather than the fragment PageFragment .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thank you David i fixed the issue
after making the PersonalDetailsView inherit from Fragment, all started to work.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Good evening
I need to insert notifications in my Android application. This is something similar to RSS service.
Therefore I have inserted NotificationCompat.Builder, and Pendig Intent to this purpose. When user selects corresponding item the application is restarted and updated.
But I have a problem, I don't have idea how to fire the notification. I'm thinking to start something like a Timer, every 15-30 minutes connect to server and look for new event released. If there is one, I'll fire Notification through the corresponded object.
Is this a best prtacice? Is there any better way to do?
I would appreciate any sugestions.
Thanks a lot.
|
|
|
|