小编spa*_*agi的帖子

android挂起意图通知问题

我在我的应用程序中发生了一个警报,它会启动一个通知,然后在按下时启动一个活动.问题是,当我创建多个警报时,从通知启动的活动会获得与第一个相同的额外内容.我认为这个问题要么是我在未决意图中的意图,要么是在未决意图本身.我想我可能需要在其中一个上放一面旗帜,但我不知道哪一个.

Intent showIntent =new Intent(context, notificationreceiver.class);
    showIntent.putExtra("details", alarmname);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
        showIntent, 0); 

    notification.setLatestEventInfo(context, "The event is imminent",
            alarmname, contentIntent);
Run Code Online (Sandbox Code Playgroud)

和通知的接收者

Bundle b = getIntent().getExtras();
    String eventname = b.getString("details");
    details.setText(eventname);
Run Code Online (Sandbox Code Playgroud)

每次下次通知发生时,"详细信息"额外都是相同的,而不是具有不同的值.直到我设置意图,我确信正确的值转到"详细信息",因此每次按任何通知时都会获得第一个意图的问题.如何才能启动正确的意图呢?希望我尽可能清楚,谢谢!

notifications android android-intent

72
推荐指数
2
解决办法
4万
查看次数

来自intent的getExtra从pendingIntent启动

在用户从列表中选择带有时间的内容并在给定时间为其创建通知后,我尝试发出一些警报.我的问题是我的意图上的putExtra无法在广播接收器上收到的"showame".它总是得到空值.这是我对大部分意图的处理方式,但我想这次可能是因为pendingIntent或者broadcastReceiver需要不同的事情.谢谢

通过挂起的意图发送Intent的函数

public void setAlarm(String showname,String time) {

    String[] hourminute=time.split(":");
    String hour = hourminute[0];
    String minute = hourminute[1];
    Calendar rightNow = Calendar.getInstance();
    rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
    rightNow.set(Calendar.MINUTE, Integer.parseInt(minute));
    rightNow.set(Calendar.SECOND, 0);
    long t=rightNow.getTimeInMillis();
    long t1=System.currentTimeMillis();

    try {   

    Intent intent = new Intent(this, alarmreceiver.class);  
    Bundle c = new Bundle();            
    c.putString("showname", showname);//This is the value I want to pass
    intent.putExtras(c);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 12345, intent, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, rightNow.getTimeInMillis(),pendingIntent);
    //Log.e("ALARM", "time of millis: "+System.currentTimeMillis());
    Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();

    } catch …
Run Code Online (Sandbox Code Playgroud)

android bundle alarm android-intent

38
推荐指数
3
解决办法
2万
查看次数

android从最佳提供商处获取位置

我有这个代码来获得最好的提供商

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

locationListener = new MyLocationListener();
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(criteria, true);
Location mostRecentLocation = lm.getLastKnownLocation(provider);
if(mostRecentLocation != null) {
    latid=mostRecentLocation.getLatitude();
    longid=mostRecentLocation.getLongitude();
}
lm.requestLocationUpdates(provider, 1, 0, locationListener);
Run Code Online (Sandbox Code Playgroud)

然后是听众

private class MyLocationListener implements LocationListener {

@Override
public void onLocationChanged(Location loc) {
  if (loc != null) {
    latid = loc.getLatitude();
    longid = loc.getLongitude();
    // if(loc.hasAccuracy()==true){
    accuracyd = loc.getAccuracy();
    String providershown = loc.getProvider();    
    accuracy.setText("Location Acquired. Accuracy:"
      + Double.toString(accuracyd) + "m\nProvider: "+providershown);
    accuracy.setBackgroundColor(Color.GREEN);
    // }
    userinfo=usernamevalue+"&"+Double.toString(latid)+"&"+Double.toString(longid); …
Run Code Online (Sandbox Code Playgroud)

android location location-provider

13
推荐指数
1
解决办法
3万
查看次数

在python中解析大型.csv的最有效方法?

我试着寻找其他答案,但我仍然不确定正确的方法.我有一些非常大的.csv文件(每个可能是一个千兆字节),我想首先得到他们的列标签,因为它们不是全部相同,然后根据用户偏好提取一些这些列的一些标准.在我开始提取部分之前,我做了一个简单的测试,看看解析这些文件的最快方法是什么,这是我的代码:

def mmapUsage():
    start=time.time()
    with open("csvSample.csv", "r+b") as f:
        # memory-mapInput the file, size 0 means whole file
        mapInput = mmap.mmap(f.fileno(), 0)
        # read content via standard file methods
        L=list()
        for s in iter(mapInput.readline, ""):
            L.append(s)
        print "List length: " ,len(L)
        #print "Sample element: ",L[1]
        mapInput.close()
        end=time.time()
        print "Time for completion",end-start

def fileopenUsage():
    start=time.time()
    fileInput=open("csvSample.csv")
    M=list()
    for s in fileInput:
            M.append(s)
    print "List length: ",len(M)
    #print "Sample element: ",M[1]
    fileInput.close()
    end=time.time()
    print "Time for completion",end-start

def readAsCsv():
    X=list()
    start=time.time()
    spamReader …
Run Code Online (Sandbox Code Playgroud)

python csv

12
推荐指数
1
解决办法
3万
查看次数