How to grant MODIFY_PHONE_STATE permission for apps ran on Gingerbread

后端 未结 5 1385
粉色の甜心
粉色の甜心 2020-11-22 15:40

I write an application that attempts to modify phone call state. It works well on Android 2.2 or less, but throw an exception on Android 2.3 because of the lack of permissio

5条回答
  •  攒了一身酷
    2020-11-22 15:46

    I got the solution.

    Rather to override incoming call screen, do below two things. which will allow you to access accept and decline button and also allow you to show screen above your incoming call screen.

    (1) Make one receiver class:

    public class MyPhoneReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) 
        {
            String state = extras.getString(TelephonyManager.EXTRA_STATE);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) 
                String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
    
            Intent i = new Intent(context, IncomingCallActivity.class);
            i.putExtras(intent);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
        }
    }
    

    (2) your activity xml look like:

    RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="top"
    android:gravity="top"
    android:orientation="vertical"
    android:windowAnimationStyle="@android:style/Animation.Translucent"
    android:windowBackground="@android:color/transparent"
    android:windowIsTranslucent="true"
    

    (3)Make your activity's layout transparent(which will come above calling screen),write below code in menifest

    
    
    

    (4)In menifest add your broad cast receiver

    
            
                
                
            
    
    

    (5) add below code in oncreate() of IncomingCallActivity

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    Cheers!

    Let me know if you face any problem!

提交回复
热议问题