Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > android รันบน emulator รันได้ พอติดตั้งลงเครื่องจริง แอพเด้งออก



 

android รันบน emulator รันได้ พอติดตั้งลงเครื่องจริง แอพเด้งออก

 



Topic : 134465



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์




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
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2019-11-06 13:21:44 By : aumebun View : 1525 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

มีดักจับ Write Log Exception ไว้ไหม๊ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-11-07 11:37:25 By : mr.win
 


 

No. 2

Guest


เจอปัญหาเหมือนกันครับ ใครพอมีวิธีแก้ไขบ้าง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-02-06 15:41:45 By : ชัยเชษฐ
 

 

No. 3



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ส่วนใหญ่ก็คือ android ที่ไปลง เวอชั่นต่ำกว่า Virtual Machine
คือคอมไพล์ ด้วย v29 แต่ไม่ใช้บน v16
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-02-06 17:31:01 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : android รันบน emulator รันได้ พอติดตั้งลงเครื่องจริง แอพเด้งออก
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่