我從一個類使用此Android如何從包中獲取/檢索數據?
intent.putExtra("alarmMgr_id", alarm_id);
我得到的數據中的其他類在包發送數據,但我不知道如何從包安裝IM的截圖檢索:
請指導我如何得到這個數據在其結束紅星; 我想存儲這兩個變量wakelockid = 3,alarmMgr_id = 9作爲整數。
我已經嘗試過,但它沒有爲我工作,所以請看看調試模式的截圖; alarmManager_id每次都返回null。
Bundle extras = intent.getExtras();
int alarmManager_id = extras.getInt("alarmMgr_id");
認爲這是對數據進行發送
public class AlarmBroadcastReciever extends WakefulBroadcastReceiver {
// The app's AlarmManager, which provides access to the system alarm
// services.
private AlarmManager alarmMgr;
// The pending intent that is triggered when the alarm fires.
private PendingIntent alarmIntent;
@Override
public void onReceive(Context context, Intent intent) {
String alarm_id = intent.getAction();
Intent service = new Intent(context, AlarmSchedulingService.class);
service.putExtra("alarmMgr_id", alarm_id);
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, service);
}
@SuppressLint("NewApi")
public void setAlarm_RepeatOnce(Context context, int year, int month,
int date, int hours, int minutes, TaskModel currentTask) {
try {
alarmMgr = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
int alarm_id = currentTask._id;
Intent intent = new Intent(context, AlarmBroadcastReciever.class);
intent.setAction(String.valueOf(alarm_id));
alarmIntent = PendingIntent.getBroadcast(context, alarm_id , intent,
PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DATE, date);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
alarmIntent);
// Enable {@code AlarmBootBroadCastReceiver} to automatically
// restart the alarm
// when the
// device is rebooted.
ComponentName receiver = new ComponentName(context,
AlarmBootBroadcastReceiverRepeatOnce.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
} catch (Exception ex) {
String e = ex.getLocalizedMessage();
}
}
}
,並以此爲B類,如果你去,你可以看到即時得到的數據的包,但截圖現在臨危數據A級我不知道如何提取它,你也可以在代碼中看到我嘗試提取值的方法,但都返回null。
public class AlarmSchedulingService extends IntentService {
DatabaseHelper db;
Context mContext;
public AlarmSchedulingService() {
super("SchedulingService");
}
// An ID used to post the notification.
public int NOTIFICATION_ID;//= 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
//Bundle extras;
@SuppressLint("NewApi") @Override
protected void onHandleIntent(Intent intent) {
try{
// Get passed values
Bundle extras = intent.getExtras();
int uniqueID = extras.getInt("alarm_id");
int alarmMgr_id = extras.getInt("alarmMgr_id");
int alarmMgr_idd = extras.getParcelable("alarmMgr_id");
// NOTIFICATION_ID = alarmMgr_id;//uniqueID;
// sendNotification(alarmMgr_id);
// Release the wake lock provided by the BroadcastReceiver.
AlarmBroadcastReciever.completeWakefulIntent(intent);
}
catch(Exception e)
{
String ex = e.getLocalizedMessage();
}
}
// Post a notification
private void sendNotification( int alarm_id) {
//code for notificaiton generation
}
}
您是否嘗試過搜索如何從包中檢索數據,有大量的示例 – 2014-11-06 08:27:04
是的,我確實搜索過,但對我沒有幫助,因爲非解決方案爲我工作。 – mushahid 2014-11-06 08:47:42