انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
تبدیل کدهای کلید 2651 به Service

تبدیل کدهای کلید 2651 به Service

#1
به نام خدا
سلام، یک سوال داشتم. می خواستم ببینم که میشه کد های   کلید  2651  به Service تبدیل کرد؟

من خودم کد های زیرو نوشته ام ولی کار نمیکنه.

میشه مگین چه تغیری در این کد ها بدم تا بتونم این دادرو تبدیل به Service کنم و در دیتابیس ذخیره کنم (البته بخش دیتابیس درسته)؟

اینم کدهایی که من نوشتم.
کد پی‌اچ‌پی:
package service;


import java.io.UnsupportedEncodingException;

import mix.DB;
import mix.JSONParser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.kelidestan.json.R;


public class 
Get_list_group extends Service {
    
private static 
String url;

    
    private 
mix.DB crdb;
    private 
mix.mport db;
    

    
//JSON Node Names
    
private static final String json_name "GROUP";
    private static final 
String json_node_name_1 "group_name";
    private static final 
String json_node_name_2 "id";
    private static final 
String json_node_name_3 "avatar_url";
    
    
JSONArray kelidestan null;
    public 
String app_id_string;

    public 
String[] json_string_1_all;
    public 
String[] json_string_2_all;
    public 
String[] json_string_3_all;
    
    public 
int json_length;
    public 
ListView lv;
    
    
    

    public 
Handler mHandler;
    public 
boolean continue_or_stop;
  
    
    
    
   
    @
Override
    
public int onStartCommand(Intent intentint flagsint startId) {


        
crdb =new DB(this);
        
crdb.getWritableDatabase();
        
db =new mix.mport(this);
        
db.open();
        
        
mHandler = new Handler();
        
continue_or_stop true;
        
        
    
    
         
        

        
url "http://192.168.1.99/app/group.php?id=1&pass=1254";
        
        
                 
                 new 
Thread(new Runnable() {
                        @
Override
                        
public void run() {
                            
// TODO Auto-generated method stub
                            
while (continue_or_stop) {
                                try {
                                    
Thread.sleep(1); // every 5 seconds
                                    
mHandler.post(new Runnable() {

                                        @
Override
                                        
public void run() {
                          
                                            new 
JSONParse().execute();
       
                                        
                                        }
                                    });
                                } catch (
Exception e) {
                                    
// TODO: handle exception
                                
}
                            }
                        }
                    }).
start();
            
        
        
        
        
        
        return 
Service.START_FLAG_REDELIVERY;
    }
    
    
    public class 
JSONParse extends AsyncTask<StringStringJSONObject> {
       @
Override
       
public void onPreExecute() {
           
super.onPreExecute();
           
pDialog = new ProgressDialog(Get_list_group.this);
           
pDialog.setMessage("Getting Data ...");
           
pDialog.setIndeterminate(false);
           
pDialog.setCancelable(true);
           
pDialog.show();
       }
       @
Override
       
public JSONObject doInBackground(String... args) {
           
JSONParser jParser = new JSONParser(); 
           
// Getting JSON from URL
           
JSONObject json jParser.getJSONFromUrl(url);
           return 
json;
       }
        @
Override
        
public void onPostExecute(JSONObject json) {
            
pDialog.dismiss();
            try {
                   
// kelidestan

                
kelidestan json.getJSONArray(json_name);
                   
// build String
                   
json_length kelidestan.length();
                   
json_string_1_all = new String [kelidestan.length()];
                   
json_string_2_all = new String [kelidestan.length()];
                   
json_string_3_all = new String [kelidestan.length()];
                   for(
int i 0kelidestan.length(); i++){
                       
JSONObject c kelidestan.getJSONObject(i);
                       
// Storing JSON item in a Variable --> with UTF-8 for persian words
                       
json_string_1_all[i] = new String(c.getString(json_node_name_1).getBytes("ISO-8859-1"), "UTF-8");
                       
json_string_2_all[i] = new String(c.getString(json_node_name_2).getBytes("ISO-8859-1"), "UTF-8");
                       
json_string_3_all[i] = new String(c.getString(json_node_name_3).getBytes("ISO-8859-1"), "UTF-8");
                   }
                   
                   
// show data in ListView
                   
setListAdapter(new MyAdapter(Get_list_group.this
                              
R.layout.list_layout_gp
                              
R.id.textView1,
                              
json_string_1_all));    
                   
lv getListView();
                  
           
           } catch (
JSONException e) {
               
e.printStackTrace();
           } catch (
UnsupportedEncodingException e1) {
               
e1.printStackTrace();
           }
        }
        private 
ListView getListView() {
            
// TODO Auto-generated method stub
            
return null;
        }
        private 
void setListAdapter(MyAdapter myAdapter) {
            
// TODO Auto-generated method stub
            
        
}
   }
    
    
    private class 
MyAdapter extends ArrayAdapter<String>{

        public 
MyAdapter(Context contextint resourceint textViewResourceId,
                
String[] strings) {
            
super(contextresourcetextViewResourceIdstrings);
            
// TODO Auto-generated constructor stub
        
}
        


        
        @
Override
        
public View getView(int positionView convertViewViewGroup parent) {
            
LayoutInflater inflater = (LayoutInflatergetSystemService(Context.LAYOUT_INFLATER_SERVICE);
            
View row inflater.inflate(R.layout.list_itemparentfalse);
            
            final 
String text json_string_1_all[position];
            final 
String id json_string_2_all[position];
            final 
String avatar_url json_string_3_all[position];
            
int loader R.drawable.ic_launcher;
            
ImageView image = (ImageView)  row.findViewById(R.id.img);
            
imag_loder.ImageLoader imgLoader = new imag_loder.ImageLoader(getApplicationContext());
            
imgLoader.DisplayImage(avatar_urlloaderimage);
                
                



            
            
TextView tv_1 = (TextViewrow.findViewById(R.id.textView1);
            
tv_1.setText(text);
            
            
            
            
            
            new 
CountDownTimer(5000,1000){
                 @
Override
                 
public void onTick(long millisUntilFinished){}

                 @
Override
                     
public void onFinish(){
                     
                     
                
db.inser(textid"1254"avatar_url);
              
                     
Toast.makeText(getApplicationContext(), "dfggf"Toast.LENGTH_LONG).show(); 
                     
                     
                     
                     
                     
                     
                 }
            }.
start();





                
                

             

            
            
            
            
            
            return 
row;
            
            
            
            
            
        }
        
        
        
        
        
    }


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

ممنون میشم اگر کمکم کنید
پاسخ
 سپاس شده توسط شماره مجازی امارات


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان