定制新的来电屏幕

定制新的来电屏幕

本文介绍了Android的 - 定制新的来电屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Android的一个新的来电屏幕,

当我收到来电我的应用程序启动 - 但立即崩溃,并默认来电屏幕快到了

我在做什么错了?

我的code:

的Andr​​oidManifest.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
      包=com.example.myfirstapp
      安卓版code =7
      机器人:VERSIONNAME =7>
    <使用-SDK安卓的minSdkVersion =7安卓targetSdkVersion =10>< /使用的SDK>
    <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.MODIFY_PHONE_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.CALL_PHONE/>

    <应用机器人:标签=@字符串/ APP_NAME机器人:图标=@可绘制/ ic_launcher>
        <接收机器人:MyPhoneBroadcastReceiver名称=机器人:启用=真正的>
            <意图过滤器的Andr​​oid版本:优先=99999>
                <作用机器人:名称=android.intent.action.PHONE_STATE/>
            &所述; /意图滤光器>
        < /接收器>
        <活动
            机器人:名称=>中打电话。
        < /活性GT;
    < /用途>
< /舱单>
 

MyPhoneBroadcastReceiver.java:

 包com.example.myfirstapp;

进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;

公共类MyPhoneBroadcastReceiver延伸活动{

    公共无效的onReceive(最终上下文的背景下,意图意图){
            意图main_intent =新的意图(这一点,Call.class);
            context.startActivity(main_intent);
    }


}
 

Call.java:

 包com.example.myfirstapp;

进口android.app.Activity;
进口android.os.Bundle;

公共类呼叫延伸活动{

保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    }

}
 

日志是:

  10-14 20:59:51.056:E / AndroidRuntime(1826):致命异常:主要
 10-14 20:59:51.056:E / AndroidRuntime(1826):
 java.lang.RuntimeException的:无法实例接收器
 com.example.myfirstapp.MyPhoneBroadcastReceiver:
 java.lang.ClassCastException:
 com.example.myfirstapp.MyPhoneBroadcastReceiver不能转换到
 android.content.BroadcastReceiver 10月14日20:59:51.056:
 E / AndroidRuntime(1826):在
 android.app.ActivityThread.handleReceiver(ActivityThread.java:2210)
 10-14 20:59:51.056:E / AndroidRuntime(1826):在
 android.app.ActivityThread.access $ 1500(ActivityThread.java:130)10-14
 20:59:51.056:E / AndroidRuntime(1826):在
 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1271)
 10-14 20:59:51.056:E / AndroidRuntime(1826):在
 android.os.Handler.dispatchMessage(Handler.java:99)10-14
 20:59:51.056:E / AndroidRuntime(1826):在
 android.os.Looper.loop(Looper.java:137)10月14日20:59:51.056:
 E / AndroidRuntime(1826):在
 android.app.ActivityThread.main(ActivityThread.java:4745)10-14
 20:59:51.056:E / AndroidRuntime(1826):在
 java.lang.reflect.Method.invokeNative(本机方法)10-14
 20:59:51.056:E / AndroidRuntime(1826):在
 java.lang.reflect.Method.invoke(Method.java:511)10月14日20:59:51.056:
 E / AndroidRuntime(1826):在
 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
 10-14 20:59:51.056:E / AndroidRuntime(1826):在
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)10-14
 20:59:51.056:E / AndroidRuntime(1826):在
 dalvik.system.NativeStart.main(本机方法)10-14 20:59:51.056:
 E / AndroidRuntime(1826):java.lang.ClassCastException:产生的原因:
 com.example.myfirstapp.MyPhoneBroadcastReceiver不能转换到
 android.content.BroadcastReceiver 10月14日20:59:51.056:
 E / AndroidRuntime(1826):在
 android.app.ActivityThread.handleReceiver(ActivityThread.java:2205)
 10-14 20:59:51.056:E / AndroidRuntime(1826):10 ...更多
 

解决方案

好了,为了让我的新的一页,前面我需要让睡一会...因此,新的code将是:

 公共类MyPhoneBroadcastReceiver扩展的BroadcastReceiver {

    公共无效的onReceive(最终上下文的背景下,意图意图){


        螺纹pageTimer =新的Thread(){
            公共无效的run(){
                尝试{
                    睡眠(1000);
                }赶上(InterruptedException异常E){
                    e.printStackTrace();
                } 最后 {
                    意图I =新意图();
                    i.setClass(背景下,Call.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(ⅰ);
                }
            }
        };
        pageTimer.start();
    }
}
 

但是 - 原来来电程序正在后台仍在运行...

有什么办法来替代它,而不是打开新的应用程序ontop呢?

谢谢!

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 screen is coming up.

what am i doing wrong?

my code:

AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myfirstapp"
      android:versionCode="7"
      android:versionName="7">
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"></uses-sdk>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
    <uses-permission android:name="android.permission.CALL_PHONE" />

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <receiver android:name=".MyPhoneBroadcastReceiver" android:enabled="true">
            <intent-filter android:priority="99999">
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
        <activity
            android:name=".Call" >
        </activity>
    </application>
</manifest>

MyPhoneBroadcastReceiver.java:

package com.example.myfirstapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

public class MyPhoneBroadcastReceiver extends Activity{

    public void onReceive(final Context context, Intent intent) {
            Intent main_intent = new Intent(this, Call.class);
            context.startActivity(main_intent);
    }


}

Call.java:

package com.example.myfirstapp;

import android.app.Activity;
import android.os.Bundle;

public class Call extends Activity{

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

}

the log is:

 10-14 20:59:51.056: E/AndroidRuntime(1826): FATAL EXCEPTION: main
 10-14 20:59:51.056: E/AndroidRuntime(1826):
 java.lang.RuntimeException: Unable to instantiate receiver
 com.example.myfirstapp.MyPhoneBroadcastReceiver:
 java.lang.ClassCastException:
 com.example.myfirstapp.MyPhoneBroadcastReceiver cannot be cast to
 android.content.BroadcastReceiver 10-14 20:59:51.056:
 E/AndroidRuntime(1826): at
 android.app.ActivityThread.handleReceiver(ActivityThread.java:2210)
 10-14 20:59:51.056: E/AndroidRuntime(1826): at
 android.app.ActivityThread.access$1500(ActivityThread.java:130) 10-14
 20:59:51.056: E/AndroidRuntime(1826): at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
 10-14 20:59:51.056: E/AndroidRuntime(1826): at
 android.os.Handler.dispatchMessage(Handler.java:99) 10-14
 20:59:51.056: E/AndroidRuntime(1826): at
 android.os.Looper.loop(Looper.java:137) 10-14 20:59:51.056:
 E/AndroidRuntime(1826): at
 android.app.ActivityThread.main(ActivityThread.java:4745) 10-14
 20:59:51.056: E/AndroidRuntime(1826): at
 java.lang.reflect.Method.invokeNative(Native Method) 10-14
 20:59:51.056: E/AndroidRuntime(1826): at
 java.lang.reflect.Method.invoke(Method.java:511) 10-14 20:59:51.056:
 E/AndroidRuntime(1826): at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
 10-14 20:59:51.056: E/AndroidRuntime(1826): at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-14
 20:59:51.056: E/AndroidRuntime(1826): at
 dalvik.system.NativeStart.main(Native Method) 10-14 20:59:51.056:
 E/AndroidRuntime(1826): Caused by: java.lang.ClassCastException:
 com.example.myfirstapp.MyPhoneBroadcastReceiver cannot be cast to
 android.content.BroadcastReceiver 10-14 20:59:51.056:
 E/AndroidRuntime(1826): at
 android.app.ActivityThread.handleReceiver(ActivityThread.java:2205)
 10-14 20:59:51.056: E/AndroidRuntime(1826): ... 10 more
解决方案

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!

这篇关于Android的 - 定制新的来电屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:37