Android Read Phone State?
I'm trying to make app to READ PHONE STATE and when the phone state is changed to display Toast with the current state. But when I start it, the app stops unexpectedly. my class :
Solution 1:
I did not see <uses-permission android:name="android.permission.READ_PHONE_STATE" />
in your Manifest file.
It is required for your application to be able to read that state.
Solution 2:
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.marakana"android:versionCode="1"android:versionName="1.0" >
/* permission should be added like below*/
<uses-permissionandroid:name="android.permission.READ_PHONE_STATE"/><applicationandroid:icon="@drawable/icon"android:label="@string/app_name"android:theme="@android:style/Theme.Light" ><activityandroid:name=".TelephonyDemo"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application><uses-sdkandroid:minSdkVersion="7" /></manifest>
Solution 3:
Your application knows PHONE STATE thanks an Intent that is Broadcasted by the Telephony Service notifying to application about PHONE STATE changes. You may need Guide line to create your application
- Intent : see http://developer.android.com/reference/android/content/Intent.html for details and see http://developer.android.com/guide/topics/intents/intents-filters.html for concept and TelephonyManager.ACTION_PHONE_STATE_CHANGED is the name of the intent you need to receives thanks your BoradCastReceiver
- BroadcastReceiver http://developer.android.com/reference/android/content/BroadcastReceiver.html and see http://developer.android.com/guide/topics/fundamentals.html at "Application Component" Section
android.permission.READ_PHONE_STATE permission have to be added in your AndroidManifest.xml file (here an example extract..)
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="xyz...."android:versionCode="1"android:versionName="0.1"><uses-sdkandroid:minSdkVersion="7" /><uses-permissionandroid:name="android.permission.READ_PHONE_STATE"></uses-permission> ... </manifest>
Post a Comment for "Android Read Phone State?"