Are there alternate ways to look up user phone number when TelephonyManager returns null?

by Muthu Ramadoss » Fri, 10 Apr 2009 16:15:15 GMT


Sponsored Links
 Is there a way to look up the user phone number other than TelephonyManager?

In my G1, this returns null:

// get your phone number
        TelephonyManager telephonyManager = (TelephonyManager)
                getSystemService(Context.TELEPHONY_SERVICE);
        String tel = telephonyManager.getLine1Number();

        Log.i("Telephone Number ==> ", tel+" <==");


Is there any other way of getting user's own phone number?

take care,
Muthu Ramadoss.

 http://linkedin.com/in/tellibitz 
 http://androidrocks.googlecode.com  - Android Consulting.

Emo Philips < http://www.brainyquote.com/quotes/authors/e/emo_philips.html> ;
- "A computer once beat me at chess, but it was no match for me at
kick
boxing."

--~--~---------~--~----~------------~-------~--~----~



Are there alternate ways to look up user phone number when TelephonyManager returns null?

by Mark Murphy » Fri, 10 Apr 2009 19:56:17 GMT


 


Not only does this apparently return null in some cases (like you got),
it does not have to necessarily return a valid value.

I tried your code, and I get a phone number that I *think* is what I was
originally assigned when I bought the G1, before my other T-Mobile
number could be ported over.

So I am not certain this method is reliable in any case.


Hopefully yes, though I don't know of one...

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books.html 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Are there alternate ways to look up user phone number when TelephonyManager returns null?

by strazzere » Fri, 10 Apr 2009 23:08:09 GMT


 Does your G1 display the correct line number through settings?
(Settings > About phone > Status > Phone Number)

This method used by the system seems to always be accurate, but I
believe it is a private API;

// Snippit from
 http://android.git.kernel.org/?p=platform/packages/apps/Settings.git ;a=blob_plain;f=src/com/android/settings/deviceinfo/Status.java;hb=HEAD

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;

...

Phone mPhone = PhoneFactory.getDefaultPhone();

...

setSummaryText("number", mPhone.getLine1Number());

// End snippit







--~--~---------~--~----~------------~-------~--~----~



Are there alternate ways to look up user phone number when TelephonyManager returns null?

by Muthu Ramadoss » Fri, 10 Apr 2009 23:22:22 GMT


 My G1 says "Unknown" when (Settings > About phone > Status > Phone
Number)

I haven't tried your new code snippet. I'll report back with the
results. Thanks.





--~--~---------~--~----~------------~-------~--~----~



Are there alternate ways to look up user phone number when TelephonyManager returns null?

by strazzere » Sat, 11 Apr 2009 00:45:43 GMT


 What type of phone are you using? Does it have a simcard and/or work
on your carrier network?

If the About phone/Status is not showing, then I doubt the snippit
would work even if you could compile it (your not going to be able to
using the standard SDK)






--~--~---------~--~----~------------~-------~--~----~



Are there alternate ways to look up user phone number when TelephonyManager returns null?

by Muthu Ramadoss » Sat, 11 Apr 2009 14:24:14 GMT


 I have an ADP1 bought from market that I use with a local GSM carrier
in Chennai. The phone works perfectly, although we use only GPRS and
not 3G.

But the phone number is always displayed as "Unknown".








--~--~---------~--~----~------------~-------~--~----~



Are there alternate ways to look up user phone number when TelephonyManager returns null?

by Edward Falk » Sun, 12 Apr 2009 00:47:16 GMT


 I encountered the same issue with a new Sim card I bought from the T-
Mobile store.  In a couple weeks, it started returning the correct
phone number, but it initially returned null.  I modified my software
to allow the user to enter the phone number if I couldn't find it from
the telephony manager.
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. about setting WindowManager.LayoutParams.screenBrightness

We noticed some devices(not android's) support such feature:black out
screen and turn bright when someone touches it.
Our custom want us to simulate such function with android.
We trid to set WindowManager.LayoutParams.screenBrightness to make
screen dark enough but still knowing touch motion but failed.

 lp.screenBrightness = 0.039f;  //dark enough and looks dead

 lp.screenBrightness = 0.04f;  //not dark enough but knowing touch
motion

It turns out that there is no way to make our customer happy.

I think Android has nothing to do with our problem and it should be
the problem of LED screen maker. If they can make such LED, Android
will support it also. Am I right?

Best Regards.

James

-- 

2. Add Self-Define view into layout

I have a self-define view class, I would like to add this view into
the layout , but there is a problem

02-21 17:23:07.843: ERROR/AndroidRuntime(1253): Uncaught handler:
thread main exiting due to uncaught exception
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.helloandroid/
com.example.helloandroid.HelloAndroid}: java.lang.NullPointerException
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2401)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2417)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.os.Handler.dispatchMessage(Handler.java:99)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.os.Looper.loop(Looper.java:123)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread.main(ActivityThread.java:4203)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
java.lang.reflect.Method.invokeNative(Native Method)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
java.lang.reflect.Method.invoke(Method.java:521)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
dalvik.system.NativeStart.main(Native Method)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253): Caused by:
java.lang.NullPointerException
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
com.example.helloandroid.HelloAndroid.onCreate(HelloAndroid.java:16)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2364)
02-21 17:23:07.853: ERROR/AndroidRuntime(1253):     ... 11 more

Here is my code, I want the SelfView to be under the TextView.

public class HelloAndroid extends Activity {
        private SelfView mSelfView;
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       LinearLayout mlayout =
(LinearLayout)findViewById(R.id.mylayout);
       mSelfView = new SelfView(this);
       mlayout.addView(mSelfView);
       setContentView(R.layout.main);
   }
}

public class SelfView extends View {

        public SelfView(Context context) {
                super(context);
                // TODO Auto-generated constructor stub
        }

        protected void onDraw(Canvas canvas) {
                canvas.drawColor(Color.BLUE);
        }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/mylayout"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>

-- 

3. Live report isat

4. how to set break points when developing Eclipse with an actual device

5. Online order now open for business

6. Is there a way to call Android Scripting Environment from Java Code

7. Ask: Provider GSM utk Android.