Android READ PHONE STATE?

后端 未结 3 1984
暗喜
暗喜 2020-12-01 16:49

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 a

相关标签:
3条回答
  • 2020-12-01 17:03
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns: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-permission android:name="android.permission.READ_PHONE_STATE"/>
    
        <application
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Light" >
            <activity
                android:name=".TelephonyDemo"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
        <uses-sdk android:minSdkVersion="7" />
    
    </manifest>
    
    0 讨论(0)
  • 2020-12-01 17:08

    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..)

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      
           package="xyz...."
           android:versionCode="1" android:versionName="0.1">
           <uses-sdk android:minSdkVersion="7" />
           <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
      
       ...
      </manifest>
      
    0 讨论(0)
  • 2020-12-01 17:10

    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.

    0 讨论(0)
提交回复
热议问题