我尝试在Android中实现VoiceRecognitionService
。在我的情况下,在语音记录结束后,我需要开始Intent
。但是,当我试图这样做时,我得到了,
尝试在空对象引用上调用虚方法'void android.content.Context.startActivity(android.content.Intent)'
我的课看起来像,
public class VoiceRecService extends Application implements RecognitionListener {
/* other methods and contents */
@Override
public void onEndOfSpeech() {
double latitude = 31.249351;
double longitude = 121.45905;
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://maps.google.com/maps?saddr="
+ latitude + ","
+ longitude + "&daddr="
+ 31.186371 + "," + 121.489885));
notificationIntent.setPackage("com.google.android.apps.maps");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(notificationIntent);
}
}
如何使用startActivity(notificationIntent)
启动意图。如果有可能,我该如何解决这个问题?