2

この質問は割り当てられているように感じますが、それらのどれも私のニーズに合わず、解決策もうまくいきません。

次の状態をリッスンするために PhoneStateListener に拡張するクラスを持つアプリケーションがあります。

  • CALL_STATE_RINGING (ここでは、着信電話番号でグローバル文字列変数を設定します)
  • CALL_STATE_OFFHOOK (ここでは、タスク/プロセスを前面に移動して、ユーザーが通話中画面ではなく発信者の詳細を含むアプリケーションを画面に表示できるようにします)

通話中画面を (通知領域に) 最小化する方法が必要です。できることは知っていますが (プルーフがあります)、方法がわかりません。最小化したら、自分のタスクを以前に背面に移動された前面。

私のアプリケーションが起動し、ユーザーがログインし、戻るボタンを押し続けると、ユーザーはログインしたままになりますが、アプリケーションはバックグラウンドに移動します。着信が発生した場合、発信者の電話番号がアプリケーションに存在するかどうかを確認し (アプリケーションはいくつかのユーザー情報を保持します)、通話中画面が最小化された後にユーザー情報に移動します。

このコードを CALL_STATE_OFFHOOK 状態で実行すると、呼び出しが最小化され、マップがフルスクリーンで読み込まれます (証明)

public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING: {
                IncomingTelephoneNumber = incomingNumber;
                break;
            }
            case TelephonyManager.CALL_STATE_OFFHOOK: {
                Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
                intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
                activity.startActivity(intent);
                break;
            }
        }
    }
}

マップのソース コードを入手することはできません。これをやりたいのと同じ方法ですが、自分のアプリケーションでこれを試してみましたが、機能しません。通話中画面がまだアプリケーションの前にあります(またはアプリケーションがまったく呼び出されません)。コードが壊れたりすることはありません。アプリが前に出ないだけです。

public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING: {
                IncomingTelephoneNumber = incomingNumber;
                break;
            }
            case TelephonyManager.CALL_STATE_OFFHOOK: {
                try {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setFlags(270532608);//This is the flag which is used from the Launcher, LogCat helped here //flg=0x10200000
                    intent.setClassName(activity.getPackageName(), Splash.class.getCanonicalName());
                    activity.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}

アプリケーションを前面に戻す他の方法を試しましたが、うまくいきません。

この投稿を見ましたが、これまでに解決策はありません。

使用しているデバイスに必要な Android バージョン 10 を使用します (Samsung P-1000 タブレット、Android 2.3.3 が最新の公式バージョンです)。

どんな助けでも大歓迎です。それは、電車のスマッシュか、呼び出す必要がある非常に単純なものである可能性があります。しかし、マップと同じように、これを実行したいと思います。

編集: 通話中画面を最小化する解決策を見つけました (最善の解決策ではありませんが、機能します)

public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING: {
                IncomingTelephoneNumber = incomingNumber;
                break;
            }
            case TelephonyManager.CALL_STATE_OFFHOOK: {
                try {
                    //This will simulate pressing the Home button
                    //Thus Minimizing the In Call Screen
                    Intent startMain = new Intent(Intent.ACTION_MAIN);
                    startMain.addCategory(Intent.CATEGORY_HOME);
                    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    activity.startActivity(startMain);

                    //This is the part still not working Correctly
                    //Moving my Task/Process to the Front for the user to see
                    //This is Android 10, I still can not find a solution to move task to front
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setClassName(activity, Splash.class.getCanonicalName());
                    activity.startActivity(intent);
                } catch (Exception e) {
                    Log.v("", "e: " + e.getMessage());
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}
4

1 に答える 1

1

特定の問題の解決策を見つけました。さまざまな設定を試してフォーラムを読んだ後、これが思いつき、Android GingerBread 2.3.3(バージョン10)で動作します

通話を最小化してホーム画面に移動するには、これを行いました

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(startMain);

上記を使用しないことに決めました。基本的に必要なことを正確に行う次のもののみを使用します(ソリューションは、インテントコードとAndroidマニフェストファイルのコードの2つの部分で機能します)

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

//Here the activity class in Question "JobDetail"
intent.setClassName(activity.getPackageName(), JobDetail.class.getCanonicalName());

//These extras I add and then use them in my
//JobDetail class to show the specific details for the caller
intent.putExtra("JobId", JobId);
intent.putExtra("FromCall", "true");
activity.startActivity(intent);

マニフェスト部

<activity android:name="JobDetail" android:configChanges="orientation|keyboardHidden"
    android:taskAffinity="" android:launchMode="singleInstance"
    android:alwaysRetainTaskState="true" />

マニフェスト ファイル内の特定のアクティビティ クラスの下に、前面に表示する必要があります。私の場合は の上に表示しInCallScreen、次の 3 つのプロパティ/タグを追加します。

  • android:taskAffinity="" (これで何かができるかどうかはわかりませんが、そのままにしておきます)
  • android:launchMode="singleInstance" (これによりアクティビティの新しいインスタンスが起動されると思いますが、このオプションと上記のインテントのみを使用すると、アプリケーション全体が再起動され、最後のプロパティ/タグが追加されることがわかりました)
  • android:alwaysRetainTaskState="true" (これにより、Activity クラスが直接開かれ、アプリケーション全体がリセットされないようになります)

この後、起動しているアクティビティ クラスが別の親アクティビティ内のアプリケーションの奥深くにある場合などに、バック キーを処理します。

また、 を使用しmoveTaskToBack(true);てアプリケーションを最小化すると、Gingerbread ではうまく機能しないことがわかりました。この背後にある技術的な詳細をすべて知っているわけではありませんが、問題のアプリケーションがスタックのすぐ後ろに移動されているため、タスクを前に出すのは簡単な冒険ではないことがわかります. 代わりに、次のインテント コールを使用します (ホーム ボタンを押すことをシミュレートlight-hideし、ユーザーからのアプリケーション)。

@Override
public void onBackPressed() {
    //moveTaskToBack(true);
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);
    //Show toast to notify the user that your application is still running in the background
    return;
}

これが、古いハードウェアと古いソフトウェアで私と同じ問題に悩まされている人に役立つことを願っています.

于 2014-01-10T19:57:34.897 に答える