我的Android应用程序存在一个非常奇怪的问题。 简而言之,我的应用程序使用一个侦听来自某个号码的短信的接收器,如果手机收到来自该号码的短信,它应该播放一些不同的音调并以特定模式振动,它也应该开始另一个活动。
这是在avd模拟器上按预期工作,但它不适用于所有真正的Android设备。例如。它不起作用,它应该启动活动它只是显示黑屏,应用程序不会崩溃,只显示一个完全黑屏。另一方面,在我的朋友手机上,相同的应用程序可以正常工作,除了我们在设备上有不同的供应商,我们也没有相同的Android版本,我有2.3.3而我的朋友有2.3。 5。我不认为这是问题,但是我们。
我已将设备连接到eclipse并进行了一些调试,但我找不到问题。我不知道它是否有帮助,但在下面我已经从Logcat写了一些文本,它是无法启动的活动ax.ha.it.smsalarm_jfbk / .AcknowledgeHandler。 我还记下了我是如何开始这项活动的。
开始活动:
if(enableAlarmAck == true && type.equals("primary")) {
Intent ackIntent = new Intent(ctx,AcknowledgeHandler.class);
ackIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(ackIntent);
}
和Logcat(对不起大日志):
09-02 18:59:58.183: D/SMSDispatcher(224): New SMS Message Received
09-02 18:59:58.210: D/Gsm/SmsMessage(1151): SMS SC address: +358xxxxxxxxxx
09-02 18:59:58.210: D/Gsm/SmsMessage(1151): originatingAddress.address : +358xxxxxxxxxx
09-02 18:59:58.214: D/Gsm/SmsMessage(1151): SMS SC timestamp: 1346601684000
09-02 18:59:58.214: E/Gsm/SmsMessage(1151): hasUserDataHeader : false
09-02 18:59:58.222: D/Gsm/SmsMessage(1151): messageBody : Test
09-02 18:59:58.242: V/MmsSmsProvider(224): uri=content://mms-sms/threadID?recipient=xxxxxxxxxx
09-02 18:59:58.246: V/Telephony(224): getOrCreateThreadId cursor cnt: 1
09-02 18:59:58.394: D/SmsProvider(224): insert content://sms/1467 succeeded
09-02 18:59:58.406: V/AudioPolicyManager(84): setStreamVolumeIndex() stream 3, index 15
09-02 18:59:58.406: V/AudioPolicyManager(84): setStreamVolume() for output 1 stream 3, volume 0.668344, delay 0
09-02 18:59:58.406: I/FmReceiverService(231): BrdcstReceiver onReceive ACTION: android.media.VOLUME_CHANGED_ACTION
09-02 18:59:58.406: I/FMRadioService(129): mReceiver: VOLUME_CHANGED_ACTION
09-02 18:59:58.406: I/FMRadioService(129): stream: 3
09-02 18:59:58.406: I/FMRadioService(129): volume: 15
09-02 18:59:58.406: V/AudioPolicyManager(84): setStreamVolumeIndex() stream 10, index 15
09-02 18:59:58.406: V/AudioPolicyManager(84): setStreamVolume() for output 1 stream 10, volume 0.007499, delay 0
09-02 18:59:58.410: V/AudioHardwareALSA(84): setParameters(FMRadioVol=0.0074989409)
09-02 18:59:58.410: V/AudioHardwareALSA(84): FMRadioVol = 0.007499
09-02 18:59:58.410: I/AudioHardwareALSA(84): virtual android::status_t android::AudioHardwareALSA::setFmRadioVolume(float) : Volume = [0.007499]
09-02 18:59:58.410: V/AudioPolicyManager(84): setStreamVolumeIndex() stream 9, index 15
09-02 18:59:58.410: V/AudioPolicyManager(84): setStreamVolume() for output 1 stream 9, volume 1.000000, delay 0
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): Client(27) constructor
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): Create new client(27) from pid 1151, fd=39, offset=69, length=86475, audioSessionId=31
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): setDataSource fd=39, offset=69, length=86475
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): st_dev = 45826
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): st_mode = 33188
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): st_uid = 1000
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): st_gid = 1000
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): st_size = 2418792
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): player type = 1
09-02 18:59:58.414: V/ANDROID_DRM_TEST(84): create PVPlayer
09-02 18:59:58.414: V/PlayerDriver(84): PVSuspensionState struct constructor
09-02 18:59:58.414: V/PVPlayer(84): PVPlayer constructor
09-02 18:59:58.414: V/PVPlayer(84): construct PlayerDriver
09-02 18:59:58.414: V/PlayerDriver(84): constructor
09-02 18:59:58.414: V/PlayerDriver(84): OpenCore hardware module not found
09-02 18:59:58.414: V/PlayerDriver(84): start player thread
09-02 18:59:58.414: V/PlayerDriver(84): startPlayerThread
09-02 18:59:58.414: V/PlayerDriver(84): InitializeForThread
09-02 18:59:58.414: V/PlayerDriver(84): OMX_MasterInit
09-02 18:59:58.417: V/PlayerDriver(84): OsclScheduler::Init
09-02 18:59:58.417: V/PlayerDriver(84): CreatePlayer
09-02 18:59:58.437: V/PlayerDriver(84): AddToScheduler
09-02 18:59:58.437: V/PlayerDriver(84): PendForExec
09-02 18:59:58.437: V/PlayerDriver(84): OsclActiveScheduler::Current
09-02 18:59:58.437: V/PlayerDriver(84): StartScheduler
09-02 18:59:58.437: V/PVPlayer(84): send PLAYER_SETUP
09-02 18:59:58.437: V/PlayerDriver(84): Send player code: 2
09-02 18:59:58.437: V/PlayerDriver(84): CommandCompleted
09-02 18:59:58.437: V/PlayerDriver(84): Completed command PLAYER_SETUP status=1
09-02 18:59:58.441: V/AudioSink(84): AudioOutput(31)
09-02 18:59:58.441: V/PVPlayer(84): setDataSource(39, 69, 86475)
09-02 18:59:58.441: V/ANDROID_DRM_TEST(84): [27] setAudioStreamType(3)
09-02 18:59:58.441: V/ANDROID_DRM_TEST(84): [27] prepareAsync
09-02 18:59:58.441: V/PVPlayer(84): prepareAsync
09-02 18:59:58.441: V/PVPlayer(84): data source = sharedfd://40:69:86475
09-02 18:59:58.441: V/PlayerDriver(84): Send player code: 3
09-02 18:59:58.441: V/PlayerDriver(84): handleSetDataSource
09-02 18:59:58.441: V/PlayerDriver(84): handleSetDataSource- scanning for extension
09-02 18:59:58.441: D/(84): PVFile::GetFileName
09-02 18:59:58.445: V/PlayerDriver(84): CommandCompleted
09-02 18:59:58.445: V/PlayerDriver(84): Completed command PLAYER_SET_DATA_SOURCE status=1
09-02 18:59:58.445: V/PVPlayer(84): run_init s=0, cancelled=0
09-02 18:59:58.445: V/PlayerDriver(84): Send player code: 6
09-02 18:59:58.445: V/PlayerDriver(84): release string is 2.3.3 len 5
09-02 18:59:58.449: V/PlayerDriver(84): CommandCompleted
09-02 18:59:58.449: V/PlayerDriver(84): Completed command PLAYER_INIT status=1
09-02 18:59:58.449: V/PVPlayer(84): run_set_video_surface s=0, cancelled=0
09-02 18:59:58.449: V/PVPlayer(84): run_set_audio_output s=0, cancelled=0
09-02 18:59:58.449: V/PlayerDriver(84): Send player code: 5
09-02 18:59:58.449: V/PlayerDriver(84): Create realtime output
09-02 18:59:58.449: V/PlayerDriver(84): CommandCompleted
09-02 18:59:58.449: V/PlayerDriver(84): Completed command PLAYER_SET_AUDIO_SINK status=1
09-02 18:59:58.449: V/PVPlayer(84): run_prepare s=0, cancelled=0
09-02 18:59:58.449: V/PlayerDriver(84): Send player code: 7
09-02 18:59:58.449: V/PlayerDriver(84): disable natpkt - 0
09-02 18:59:58.460: V/PlayerDriver(84): HandleInformationalEvent: 44
09-02 18:59:58.460: V/PlayerDriver(84): HandleInformationalEvent: type=44 UNHANDLED
09-02 18:59:58.460: V/ANDROID_DRM_TEST(84): [27] notify (0x3f680, 200, 1, 44)
09-02 18:59:58.460: W/MediaPlayer(1151): info/warning (1, 44)
09-02 18:59:58.460: V/PlayerDriver(84): CommandCompleted
09-02 18:59:58.460: V/PlayerDriver(84): Completed command PLAYER_PREPARE status=1
09-02 18:59:58.460: V/PlayerDriver(84): PLAYER_PREPARE complete mDownloadContextData=0x0, mDataReadyReceived=0
09-02 18:59:58.460: V/ANDROID_DRM_TEST(84): [27] notify (0x3f680, 1, 0, 0)
09-02 18:59:58.460: V/ANDROID_DRM_TEST(84): [27] setVolume(0.000000, 0.000000)
09-02 18:59:58.460: V/AudioSink(84): setVolume(0.000000, 0.000000)
09-02 18:59:58.464: V/PVPlayer(84): check_for_live_streaming s=0, cancelled=0
09-02 18:59:58.472: V/AudioSink(84): open(44100, 2, 1, 4, 31)
09-02 18:59:58.472: V/AudioPolicyManager(84): getDeviceForStrategy() from cache strategy 0, device 2
09-02 18:59:58.472: V/AudioPolicyManager(84): getOutput() stream 3, samplingRate 0, format 0, channels c, flags 0
09-02 18:59:58.472: V/AudioSink(84): setVolume
09-02 18:59:58.472: V/PlayerDriver(84): HandleInformationalEvent: 41
09-02 18:59:58.472: V/PlayerDriver(84): .... with duration = 5146 ms
09-02 18:59:58.484: I/ActivityManager(129): Starting: Intent { flg=0x10000000 cmp=ax.ha.it.smsalarm_jfbk/.AcknowledgeHandler } from pid 1151 //<--------The activity that fails to start
09-02 18:59:58.484: W/ActivityManager(129): Trying to launch ax.ha.it.smsalarm_jfbk/.AcknowledgeHandler
09-02 18:59:58.496: D/SMSDispatcher(224): BroadcastReceiver - mResultReceiver
09-02 18:59:58.496: D/SMSDispatcher(224): GcfMode :
09-02 18:59:58.496: E/SMSDispatcher(224): intent.getAction() : android.provider.Telephony.SMS_RECEIVED
09-02 18:59:58.496: D/SMSDispatcher(224): mResultReceiver : success = true
09-02 18:59:58.500: I/MediaPlayer(1151): Info (1,44)
09-02 18:59:58.562: I/Launcher(234): onResume(). mIsNewIntent : false
09-02 18:59:58.566: E/(234): onResume() check 0
09-02 18:59:58.566: V/ProgramMonitor(234): Binding::bindTaskManagerService() com.sec.android.widgetapp.programmonitorwidget.ProgramMonitorWidgetActivity$1@4056e350 com.sec.android.app.controlpanel.service.ITaskManagerService$Stub$Proxy@4063cef0
09-02 18:59:58.566: E/(234): onResume() check 1
09-02 18:59:58.566: E/Launcher(234): setWindowOpaque()
09-02 18:59:58.589: E/(234): onResume() check 2, mRestoring : false
09-02 18:59:58.589: E/(234): onResume() check 3
09-02 18:59:58.589: E/(234): onResume() check 4
09-02 18:59:58.589: E/(234): onResume() check 5
09-02 18:59:58.593: I/Launcher(234): onResume() ended
09-02 18:59:58.593: I/Launcher(234): onPause()
09-02 18:59:59.148: E/DataRouter(82): [*] Received suspend/ resume event but DUN is not up so neglect
AcknowledgeHandler.onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ack);
//Shared preferences
final SharedPreferences sharedPref = this.getSharedPreferences(SmsAlarm.SHARED_PREF, Context.MODE_PRIVATE);
//Get full message as string
String fullMessage = sharedPref.getString(SmsAlarm.FULL_MESSAGE_KEY, "");
//Get acknowledge number
final String ackNumber = sharedPref.getString(SmsAlarm.ACK_NUMBER, "");
TextView messageTextView = (TextView)findViewById(R.id.fullAlarmMessage);
//Set larm text message to ui
messageTextView.setText(fullMessage);
//Find buttons and set the to button variables
Button abortButton = (Button)findViewById(R.id.abortAlarm);
Button ackButton = (Button)findViewById(R.id.acknowledgeAlarm);
//Create objects that acts as listeners to the buttons
abortButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
//Create objects that acts as listeners to the buttons
ackButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Check if user has given any number to call, else show toast
if(!ackNumber.equals("")) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ackNumber));
startActivity(callIntent);
} else {
Toast.makeText(AcknowledgeHandler.this, R.string.cannotAck, Toast.LENGTH_LONG).show();
}
}
});
}
答案 0 :(得分:0)
您可以执行以下操作来打开屏幕并显示您的活动:
private android.view.Window window;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/**** Turn the screen on and show your activity ****/
window = getWindow();
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.setContentView(R.layout.ack);
/***************************************************/
// setContentView(R.layout.ack); // This is no longer needed
/**** Rest of your code as it is ****/
/* ---------------------------- ****/
/************************************/
}
但请记住,您只是“唤醒设备并打开屏幕”。您没有“解锁”设备。按后退键时,您将看到锁定屏幕。基本上,您的活动将打开屏幕并显示在锁定屏幕上。
希望这有帮助:)