在android中假电话

时间:2010-09-15 09:15:08

标签: android

全部,

我想在android中开发一个假的调用应用程序。点击按钮后,我必须在给定的时间段内收到一个假电话。有没有办法做到这一点.. 任何线索或示例代码......?请让我知道..谢谢。

2 个答案:

答案 0 :(得分:8)

Android是开源的。使用它!

Phone app on the git repository中,您可以找到call_card.xmlCallCard.java,用于显示来电屏幕。特别是java文件非常复杂,但是布局(当然,它与引用的资源相结合)应该可以为您提供相当准确的默认Android调用屏幕副本。

答案 1 :(得分:1)

按钮点击事件类:

将警报管理器设置为意图

Intent intent = new Intent(this, FakeCallReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 1222222, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

if (mTimer.getText().toString().trim().equalsIgnoreCase("5 sec")) {
    int i = 5;
    alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (i * 1000), pendingIntent);
    Toast.makeText(this, "Fake call scheduled after " + i + " sec",Toast.LENGTH_LONG).show();
}
else if (mTimer.getText().toString().trim().equalsIgnoreCase("10 sec")) {
    int i = 10;
    alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (i * 1000), pendingIntent);
    Toast.makeText(this, "Fake call scheduled after " + i + " sec",Toast.LENGTH_LONG).show();
}

FakeCallReciever.class:

public class FakeCallReciever extends BroadcastReceiver {

private PowerManager.WakeLock mWakelock;
@SuppressWarnings("deprecation")
private KeyguardManager.KeyguardLock mLock;
private static ContentResolver sResolver;

/**
 * onReceive for Reciever
 */

@SuppressWarnings("deprecation")
@Override
public void onReceive(Context paramContext, Intent intent) {

    this.mWakelock = ((PowerManager) paramContext.getSystemService("power"))
            .newWakeLock(805306394/* | PowerManager.ON_AFTER_RELEASE */,
                    "wakelock");
    this.mWakelock.acquire();
    this.mLock = ((KeyguardManager) paramContext
            .getSystemService("keyguard")).newKeyguardLock("");
    this.mLock.disableKeyguard();



    if (Constants.LOG)
        Log.d("FAkceREciever Call", "================>");

    setLockPatternEnabled(true);

    sResolver = paramContext.getContentResolver();

    Intent startMain = new Intent();
    startMain = new Intent(paramContext, InComingCall.class);
    startMain.setAction("com.example.fakecall.MyService");
    startMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    paramContext.startActivity(startMain);
}

/**
 * used for to enable lock in all patterns
 * 
 * @param enabled
 */
@SuppressWarnings("deprecation")
public static void setLockPatternEnabled(boolean enabled) {
    setBoolean(android.provider.Settings.System.LOCK_PATTERN_ENABLED,
            enabled);
}

private static void setBoolean(String systemSettingKey, boolean enabled) {
    android.provider.Settings.System.putInt(sResolver, systemSettingKey,
            enabled ? 1 : 0);
}

}

================== InComingCall.class:

接听来电活动以显示虚拟假电话屏幕。

它对我有用。