我无法通过 OnNotificationPosted 中的其他活动调用方法。我也试图制作活动实例但失败了。我搜索了很多但没有成功。请帮忙
的NotificationListener
public class NotificationListener extends NotificationListenerService {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
otherActivity oth = new otherActivity();
oth.loc();
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg", "Notification Removed");
}
}
otherActivity
public class OtherActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
}
public void loc() {
//code body
}
}
答案 0 :(得分:0)
com.apple.coreaudio.ASClientManager
0 libsystem_kernel.dylib 0x185693568 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1856933e0 mach_msg + 72
2 AudioToolbox 0x18982847c ASClient_AudioSessionCreateForPID + 168
3 AudioToolbox 0x189670fdc AudioSessionClient::AudioSessionClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*, AudioSessionType, unsigned int) + 456
4 AudioToolbox 0x1897c36f4 AudioSessionClientManager::CreatePrimaryClient_Priv(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*) + 568
5 AudioToolbox 0x1896721e8 invocation function for block in AudioSessionClientManager::CreatePrimaryClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*) + 40
6 libdispatch.dylib 0x18551ea14 _dispatch_client_callout + 16
7 libdispatch.dylib 0x185527618 _dispatch_queue_barrier_sync_invoke_and_complete + 56
8 AudioToolbox 0x189671ef8 AudioSessionClientManager::CreatePrimaryClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*) + 164
9 AudioToolbox 0x189671c50 AudioSessionClient::InitializeAudioSessionClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*, AudioSessionType, unsigned int) + 92
10 AudioToolbox 0x189804c58 AudioSessionCreateSession_Priv + 600
11 AVFAudio 0x18b3d024c -[AVAudioSession initWithSessionType:] + 472
12 AVFAudio 0x18b3d1848 __32+[AVAudioSession sharedInstance]_block_invoke + 72
13 libdispatch.dylib 0x18551ea14 _dispatch_client_callout + 16
14 libdispatch.dylib 0x185522240 dispatch_once_f$VARIANT$mp + 60
15 AVFAudio 0x18b3d17fc +[AVAudioSession sharedInstance] + 112
16 AXSpeechImplementation 0x1a4c1f748 -[AVSpeechSynthesizer(Implementation) init]
17 Visuals2Go 0x1007ea430 -[SpeakManager init] (SpeakManager.m:47)
如何使用:otherActivity.loc();
public class OtherActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
}
public static void loc(){
//code body
}
}