Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. Example: If I'm using Vodafone Network it will display the service provider name that my mobile is currently using.
  2.  
  3. TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  4. String deviceID =telephonyManager.getDeviceId();
  5. String deviceID1 =telephonyManager.getSimSerialNumber();
  6. String deviceID2 =telephonyManager.getSimOperatorName();
  7.  
  8. Use This code it will give you your service provider name
  9.  
  10. TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
  11. String operatorName = telephonyManager.getNetworkOperatorName();
  12.  
  13. package com.example.serviceprovider;
  14. import android.support.v7.app.ActionBarActivity;
  15. import android.support.v7.app.ActionBar;
  16. import android.support.v4.app.Fragment;
  17. import android.telephony.TelephonyManager;
  18. import android.content.Context;
  19. import android.os.Bundle;
  20. import android.view.LayoutInflater;
  21. import android.view.Menu;
  22. import android.view.MenuItem;
  23. import android.view.View;
  24. import android.view.ViewGroup;
  25. import android.widget.TextView;
  26. import android.os.Build;
  27.  
  28. public class MainActivity extends ActionBarActivity {
  29.  
  30. TextView serviceProviderTextView;
  31.  
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.main);
  36.  
  37. serviceProviderTextView = (TextView) findViewById(R.id.Service);
  38.  
  39. }
  40.  
  41. public void getServiceProvider(View view) {
  42.  
  43. TelephonyManager manager = (TelephonyManager)
  44. getSystemService(Context.TELEPHONY_SERVICE);
  45. String carrierName = manager.getNetworkOperatorName();
  46. serviceProviderTextView.setText(carrierName);
  47.  
  48. }
  49.  
  50. }
  51.  
  52. <?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  54. android:layout_width="match_parent"
  55. android:layout_height="match_parent"
  56. android:orientation="vertical" >
  57.  
  58. <TextView
  59. android:id="@+id/Service"
  60. android:text="hello"
  61. android:layout_width="wrap_content"
  62. android:layout_height="wrap_content"/>
  63.  
  64.  
  65. <Button
  66. android:id="@+id/click"
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:onClick="getServiceProvider"
  70. android:text="Click me"/>
  71.  
  72. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement