Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:从应用程序类开始新活动_Android_Android Intent_Event Handling_Listener_Android Mediaplayer - Fatal编程技术网

Android:从应用程序类开始新活动

Android:从应用程序类开始新活动,android,android-intent,event-handling,listener,android-mediaplayer,Android,Android Intent,Event Handling,Listener,Android Mediaplayer,我有一个android应用程序,可以播放应用程序类的音频。我的应用程序类中有一个PhoneStateListener,它在有电话呼叫时暂停音频 我想在通话结束时启动一个特定的活动,但我无法启动。这是我的密码: public void getPhoneState(){ TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); PhoneStateListener phoneStateListene

我有一个android应用程序,可以播放应用程序类的音频。我的应用程序类中有一个PhoneStateListener,它在有电话呼叫时暂停音频

我想在通话结束时启动一个特定的活动,但我无法启动。这是我的密码:

public void getPhoneState(){

TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
PhoneStateListener phoneStateListener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (state == TelephonyManager.CALL_STATE_RINGING) {
            if(audio.isPlaying())
               audioPlayer.pause();

        } 
            else if(state == TelephonyManager.CALL_STATE_IDLE) {

                audio.start();
                Intent missintent= new Intent(context,AudioActivity.class);
                missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(missintent);


        } 
            else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {

            if(audio.isPlaying())
            audioPlayer.pause();

        }
        super.onCallStateChanged(state, incomingNumber);


    }
};

if(mgr != null) {
    mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}

public boolean handleAudio(String source, int id) {

phoneState();
//Code for Playing Audio
.....
.....
}
如果有人能告诉我如何以正确的方式开始活动,我将不胜感激


谢谢

好吧,我知道你已经找到了另一个解决方案,但我一直在努力,找到了一些适合我的方法。我没有调用一个intent,而是使用pendingent、intent过滤器和pending post。这里是一个代码剪贴贴画,供有此问题的其他人使用

Context context = MyApplication.this.getApplicationContext();
Intent errorActivity = new Intent("com.error.activity");//this has to match your intent filter
errorActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 22, errorActivity, 0);
try {
    pendingIntent.send();
    } 
catch (CanceledException e) {
        // TODO Auto-generated catch block
    e.printStackTrace();
    }
然后在清单中,确保为捕获活动设置了意图过滤器

<activity
    android:name="UncaughtErrorDialogActivity"
    android:theme="@android:style/Theme.Dialog" >
    <intent-filter>
        <action android:name="com.error.activity" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>


我不确定这件事的正确方法,因为我从来没有这样做过,也不知道是否应该从应用程序类启动活动,因为您总是在清单上设置entry类,但考虑到您可以这样做。。。您是否已将您的活动添加到清单?我的活动已添加到清单。不可能从应用程序类启动活动吗?我没说不可能。我说我不知道,因为我从来没有这样做过,因为你已经在清单上有了开始类,由意图定义:@RaghavShankar我有一个非常类似的问题,你找到任何解决方案了吗?“但我不能。”:你需要告诉我们发生了什么。描述+日志