Android - Customised New Incoming Call Screen

后端 未结 3 1959
既然无缘
既然无缘 2020-12-17 01:02

I\'m trying to make an new incoming call screen in android,

when i get an incoming call my app starts - but crashes immediately, and the default incoming call scree

相关标签:
3条回答
  • 2020-12-17 01:20

    Add this to your manifest:

    <activity> 
        <intent-filter>
            <action android:name="android.intent.action.ANSWER" />
            <action android:name="android.intent.action.PHONE_STATE" />
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>  
    </activity>
    
    0 讨论(0)
  • 2020-12-17 01:27

    You are getting a ClassCastException because your manifest defines MyPhoneBroadcastReceiver as a receiver, not an activity. You don't need an activity to create the intent, since it takes a Context, and one is provided with onReceive(). Have it extend BroadcastReceiver and alter the intent slightly like this:

    public class MyPhoneBroadcastReceiver extends BroadcastReceiver{
    
        public void onReceive(final Context context, Intent intent) {
                Intent main_intent = new Intent(context, CallActivity.class);
                context.startActivity(main_intent);
        }
    }
    
    0 讨论(0)
  • 2020-12-17 01:37

    Ok, in order to make my new page in the front i need to make it sleep for a while... so the new code will be:

    public class MyPhoneBroadcastReceiver extends BroadcastReceiver{
    
        public void onReceive(final Context context, Intent intent) {
    
    
            Thread pageTimer = new Thread(){
                public void run(){
                    try{
                        sleep(1000);
                    } catch (InterruptedException e){
                        e.printStackTrace();
                    } finally {
                        Intent i = new Intent();
                        i.setClass(context, Call.class);
                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(i);
                    }
                }
            };
            pageTimer.start();
        }
    }
    

    But - the original incoming call program is still running in the background...

    Is there any way to replace it instead opening new app ontop of it?

    Thanks!

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