-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallActivity.java
More file actions
120 lines (97 loc) · 3.64 KB
/
CallActivity.java
File metadata and controls
120 lines (97 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package io.CareAR.connect;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.google.firebase.MessagingUnityPlayerActivity;
import com.unity3d.player.UnityPlayer;
public class CallActivity extends Activity {
private MediaPlayer mMediaPlayer;
private CallInfoModel model;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = new CallInfoModel(getIntent().getExtras());
Log.e("CallActivity: ", "onCreate!");
DisplayCallerInfo();
WakeUpPhone();
setContentView(R.layout.activity_call);
}
@Override
protected void onDestroy() {
super.onDestroy();
stopDefaultNotificationRingtone();
}
@Override
protected void onPause() {
super.onPause();
// If the screen is off then the device has been locked
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
if (!powerManager.isInteractive()) {
mMediaPlayer.pause();
}
}
public void AcceptCall(View view) {
Log.i("CallActivity", "AcceptCall");
Intent mainUnityActivity = new Intent(this,MessagingUnityPlayerActivity.class);
mainUnityActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (model.IsHasCallInfo())
{
mainUnityActivity.putExtras(model.GetInfoAsBundle());
startActivity(mainUnityActivity);
// TODO: gives "Native libraries not loaded - dropping message for" when there is no activity to use
UnityPlayer.UnitySendMessage("NativeBridge", "ProcessNativeCallWith", model.BuildInfoString());
}
else
Log.e("AcceptCall: ", "No call info from VOIP class!");
model.Reset();
finish();
}
public void DeclineCall(View view) {
Log.i("CallActivity", "DeclineCall");
finish();
}
private void DisplayCallerInfo() {
// TODO
}
private void WakeUpPhone() {
playDefaultNotificationRingtone();
final Window win = getWindow();
win.addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );
}
private void playDefaultNotificationRingtone() {
try {
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(this, alert);
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_RING) != 0) {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void stopDefaultNotificationRingtone() {
mMediaPlayer.stop();
mMediaPlayer.release();
}
}