|
|
|
android รันบน emulator รันได้ พอติดตั้งลงเครื่องจริง แอพเด้งออก |
|
|
|
|
|
|
|
android studio รันเทสได้ปกติ แต่พอ build apk มาลงที่เครื่องจริง แอพเด้งตลอด ลองหลายเครื่องก็เด้งหมด
CassavaActivity
package com.example.cassavaarea;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import static com.example.cassavaarea.R.id.listView1;
import static com.example.cassavaarea.R.id.listView2;
public class CassavaActivity extends AppCompatActivity {
@SuppressLint({"ResourceType", "ObsoleteSdkInt"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cassava);
String[] MONTH = { "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม",
"มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน",
"ธันวาคม" };
String[] DAY = { "วันอาทิตย์", "วันจันทร์", "วันอังคาร", "วันพุธ", "วันพฤหัสบดี", "วันศุกร์",
"วันเสาร์"};
// Current Date
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MM-YYYY");
String formattedDate = df.format(c.getTime());
// txtResult
TextView result = (TextView) findViewById(R.id.txtResult);
//result.setText(formattedDate);
int pDay;
int pMonth;
int pYear;
int wDay;
Date date = new Date();
Calendar cal = Calendar.getInstance();
pDay = cal.get(Calendar.DAY_OF_MONTH);
wDay = cal.get(Calendar.DAY_OF_WEEK);
pMonth = cal.get(Calendar.MONTH);
pYear = cal.get(Calendar.YEAR)+543;
System.out.println("Current Date : " + date.toString());
result.setText(DAY[wDay-1] +" ที่ "+pDay +" "+ MONTH[pMonth]+" พ.ศ. "+pYear);
TextView txttext = (TextView) findViewById(R.id.txttext);
txttext.setText("** ราคา (หน่วย : บาท/กก.)");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
} else {
// คำสั่งสำหรับรองรับ API ต่ำกว่า 11 ลงไป
}
// listView1
final ListView lisView1 = (ListView)findViewById(listView1);
final ListView lisView2 = (ListView)findViewById(listView2);
/** JSON return
* [{"MemberID":"1","Name":"Weerachai","Tel":"0819876107"},
* {"MemberID":"2","Name":"Win","Tel":"021978032"},
* {"MemberID":"3","Name":"Eak","Tel":"0876543210"}]
*/
String url = "http://web.co.th/showAllData.php";
String url1 = "http://web.co.th/showAllData1.php";
try {
JSONArray data = new JSONArray(getJSONUrl(url));
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject e = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("StarchPriceTo", e.getString("StarchPriceTo"));
map.put("CassavaPriceAVR", e.getString("CassavaPriceAVR"));
MyArrList.add(map);
}
SimpleAdapter sAdap;
sAdap = new SimpleAdapter(CassavaActivity.this, MyArrList, R.layout.activity_column,
new String[] {"StarchPriceTo", "CassavaPriceAVR"}, new int[] {R.id.StarchPriceTo, R.id.CassavaPriceAVR});
lisView1.setAdapter(sAdap);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
JSONArray data1 = new JSONArray(getJSONUrl(url1));
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map1;
for(int i = 0; i < data1.length(); i++){
JSONObject e = data1.getJSONObject(i);
map1 = new HashMap<String, String>();
map1.put("StarchPriceTo1", e.getString("StarchPriceTo1"));
map1.put("CassavaPriceAVR1", e.getString("CassavaPriceAVR1"));
MyArrList.add(map1);
}
SimpleAdapter sAdap1;
sAdap1 = new SimpleAdapter(CassavaActivity.this, MyArrList, R.layout.activity_column1,
new String[] {"StarchPriceTo1", "CassavaPriceAVR1"}, new int[] {R.id.StarchPriceTo1, R.id.CassavaPriceAVR1});
lisView2.setAdapter(sAdap1);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getJSONUrl(String url) {
StringBuilder str = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) { // Download OK
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} else {
Log.e("Log", "Failed to download result..");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_cassava
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@mipmap/back_page">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="ราคาหัวมันวันนี้"
android:textColor="#FFFFFF"
android:textSize="70px"/>
<TextView
android:id="@+id/txtResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="result"
android:textColor="#FFFFFF"
android:textSize="50px" />
<TextView
android:id="@+id/txttext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="**ราคา (หน่วย : บาท/กก.)"
android:textColor="#FFFFFF"
android:textSize="40px"/>
<TextView
android:id="@+id/txtnull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text=""
android:textColor="#FFFFFF"
android:textSize="40px"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1">
<ListView
android:id="@+id/listView1"
android:layout_width="0dp"
android:layout_weight="1"
android:divider="@null"
android:layout_height="match_parent"
android:layout_gravity="left"></ListView>
<TextView
android:id="@+id/wait"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="55px"
android:text=""/>
<ListView
android:id="@+id/listView2"
android:layout_width="0dp"
android:layout_weight="1"
android:divider="@null"
android:layout_height="match_parent"
android:layout_gravity="right"></ListView>
</LinearLayout>
</TableLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cassavaarea">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/logo_head"
android:label="@string/app_name"
android:roundIcon="@mipmap/cassava"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CassavaActivity"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:parentActivityName=".MenuActivity"
android:label="@string/app_name" />
<activity
android:name=".SoilActivity"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:parentActivityName=".MenuActivity"
android:label="@string/app_name" />
<activity
android:name=".MenuActivity"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:label="@string/app_name" />
</application>
</manifest>
Tag : Mobile, Ms SQL Server 2005, Ms SQL Server 2014, Android, JAVA, Mobile
|
ประวัติการแก้ไข 2019-11-06 13:22:23
|
|
|
|
|
Date :
2019-11-06 13:21:44 |
By :
aumebun |
View :
1650 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีดักจับ Write Log Exception ไว้ไหม๊ครับ
|
|
|
|
|
Date :
2019-11-07 11:37:25 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เจอปัญหาเหมือนกันครับ ใครพอมีวิธีแก้ไขบ้าง
|
|
|
|
|
Date :
2020-02-06 15:41:45 |
By :
ชัยเชษฐ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่วนใหญ่ก็คือ android ที่ไปลง เวอชั่นต่ำกว่า Virtual Machine
คือคอมไพล์ ด้วย v29 แต่ไม่ใช้บน v16
|
|
|
|
|
Date :
2020-02-06 17:31:01 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|