내가 OnResume 내 reciver입니다을 등록하고 있고 OnPause에 뭔가를한다 등록 취소는 매니페스트 파일수없는 동적으로
package com.bd2;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
public class BroadcastReceiver2Activity extends Activity {
/** Called when the activity is first created. */
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
IntentFilter intentfilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
intentfilter = new IntentFilter();
intentfilter.addAction("android.intent.action.AIRPLANE_MODE");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
/*intfilter = new IntentFilter();
intfilter.addAction("android.intent.action.AIRPLANE_MODE");*/
registerReceiver(receiver, intentfilter);
// sendBroadcast();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
unregisterReceiver(receiver);
}
private BroadcastReceiver receiver=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notifyDetails = new Notification(R.drawable.icon,"Time Reset!",System.currentTimeMillis());
PendingIntent myIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, People.CONTENT_URI), 0);
notifyDetails.setLatestEventInfo(context, "Time has been Reset", "Click on me to view Contacts", myIntent);
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
Log.i(getClass().getSimpleName(),"Sucessfully Changed Time");
}
};
}
//////// 내 코드에 문제가 있습니다
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bd2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BroadcastReceiver2Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
내 알림을 받고 있지 않다. 내가 정적이 일을하고있어 경우 그것은 작동
이것은 다른 사용자들과 마찬가지로 매우 좋은 질문입니다. 나중에이 시나리오를 실행할 것입니다. 동적으로 방송 수신기를 등록 :) .. : D – t0mm13b
t0mm13b @ 동적으로 방송 수신기를 등록하는 것은 쉽고, 비키 바로 그것을하고있다. 당신이 활동을 일시 중지해야 (수신기를 등록 취소)/오프에 비행기 모드를 설정하기 위해 : 문제는 어제 내 대답에서 지적한 것입니다. 따라서 방송을 놓친다. 이것은 동적으로 등록해서는 안되는 수신기의 예입니다. –