如何添加在GPRS微调无线网络连接选项 [英] How to add Wi-Fi option in GPRS spinner

查看:98
本文介绍了如何添加在GPRS微调无线网络连接选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用APN的GPRS连接显示器。我codeA微调中,我获得了Telenor公司的GPRS,MMS Telenor公司Telenor公司和WAP。 **我想在此微调添加Wi-Fi选项。当我选择Wi-Fi选项设备开始检测无线网络连接。

In my application i am using "apn" for GPRS connection display. I code a spinner in which i get the Telenor GPRS, Telenor MMS and Telenor WAP. **I want to add Wi-Fi option in this spinner. and when i select Wi-Fi option device start sensing Wi-Fi.

问:我如何添加Wi-Fi的选项在我的微调? ** 这是我的code

Q: How can i add option of Wi-Fi in my spinner?? ** This is my Code

Spinner GPRS;
String [] name_of_GPRS__available;
int [] apn_id;         public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.configuration); 

    EnumerateAPNs();

   /* this is a android enviroment in which you can develop an android application in which you 
    * share all your basic necessities of thrkife bghhr4y2ghrrr*/

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    GPRS = (Spinner)findViewById(R.id.GPRS);
            ArrayAdapter<?> spinner_array = new ArrayAdapter<Object>(this,android.R.layout.simple_dropdown_item_1line,name_of_GPRS__available);
    spinner_array.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());     
    Editor prefsEditor = prefs.edit();     
    prefsEditor.putString("Object", name_of_GPRS__available.toString());  
    prefsEditor.commit(); 
    GPRS.setAdapter(spinner_array);
    //GPRS.setOnItemSelectedListener(MyOnItemSelectedListener());
    GPRS.setOnItemSelectedListener(new MyOnItemSelectedListener());`

    GPRS.setAdapter(spinner_array);
    //GPRS.setOnItemSelectedListener(MyOnItemSelectedListener());
    GPRS.setOnItemSelectedListener(new MyOnItemSelectedListener());

 public void onItemSelected(AdapterView<?> parent, View view, 
          final int position, long id) {
        // An item was selected. You can retrieve the selected item using
        // parent.getItemAtPosition(position)
      SetDefaultAPN(apn_id[position]);

          Toast.makeText(parent.getContext(), "ETracking System Selects " +          
      parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();  
      }


        public void onNothingSelected(AdapterView<?> parent) {
        // Another interface callback
    }

      public boolean SetDefaultAPN(int id)
      {
          boolean res = false;
          ContentResolver resolver = Configuration.this.getContentResolver();
          ContentValues values = new ContentValues();

          values.put("apn_id", id); 
          try
          {
              resolver.update(Uri.parse("content://telephony/carriers/preferapn"), values, null, null);
              Cursor c = resolver.query(
                    Uri.parse("content://telephony/carriers/preferapn"), 
                      null, 
                      "_id="+id, 
                      null, 
                      null);
              if(c != null)
              {
                  res = true;
                  c.close();
              }
          }
          catch (SQLException e)
          {
              //Log.d("TAG", e.getMessage());
          }
           return res;

      }

    /*
       * Enumerate all APN data
       */
      private void EnumerateAPNs()
      {
          Cursor   c = this.getContentResolver().query(
                Uri.parse("content://telephony/carriers/current"), null, null, null, null);
          if (c != null) 
          {

              //String s = "All APNs:\n";
              //Log.d("TAG", s);
                try 
              {
                   printAllData(c); //Print the entire result set
              }
                catch(SQLException e)
                {
                    Toast.makeText(Configuration.this, "No Network Connection Available", Toast.LENGTH_LONG).show();
                }

              c.close();
          }

      }


      /*
       *  Print all data records associated with Cursor c.
       *  Return a string that contains all record data.
       *  For some weird reason, Android SDK Log class cannot print very long string message.
       *  Thus we have to log record-by-record.
       */
      private void printAllData(Cursor c)
      {
          //if(c == null) return null;


          if(c.moveToFirst())
          {
            name_of_GPRS__available = new String[c.getCount()];
            apn_id = new int [c.getCount()];
            int i= 0;

            do{

                    name_of_GPRS__available [i]= c.getString(c.getColumnIndex("name"));
                    apn_id[i]=c.getInt(c.getColumnIndex("_id"));
                    //Log.d("TAG",name[i]);
                    i++;

              }while(c.moveToNext());
              //Log.d("TAG","End Of Records");

            //name_of_GPRS_available [1]=" GPRS";

          }   
      }

请指引我。我怎样才能做到这一点。我会非常感谢你。

Kindly guide me. How can i do it. I'll be very thankful to you

推荐答案

我认为这是一个姜饼设备的设置默认APN辗转于ICS(4.0 - API 14),德precated

I assume that this is for a Gingerbread Device as Setting the Default APN was removed in ICS (4.0 - API 14), deprecated.

您是否尝试过在增加:

wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 
wifiManager.setWifiEnabled(true);

您需要将这些权限添加到您的Andr​​oid清单:

You will need to add these permissions to your Android Manifest:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>

您还可以有额外的微调长到了必须使用扫描结果从可用的WiFi点用户选择:的 http://developer.android.com/reference/android/net/wifi/ScanResult.html

You can also have an additional Spinner come up to have the User select from available Wifi spots by using Scan Result: http://developer.android.com/reference/android/net/wifi/ScanResult.html

然后

WifiManager: http://developer.android.com/reference/机器人/网络/ WIFI / WifiManager.html

WifiManager: http://developer.android.com/reference/android/net/wifi/WifiManager.html

设置所需的网络,如果有不到位的默认连接。

to set the Desired Network if there is not a default connection in place.

Markana对使用WiFi这样一个很好的教程: http://marakana.com /forums/android/examples/40.html

Markana has a nice tutorial on using Wifi this way: http://marakana.com/forums/android/examples/40.html

这篇关于如何添加在GPRS微调无线网络连接选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆