小编Mr_*_*s_D的帖子

当提供者是 gps 时,返回的位置为空?

我正在尝试在以下代码中检索我当前的位置坐标

LocationManager locationManager= (LocationManager) getSystemService(context);

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);

provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
Run Code Online (Sandbox Code Playgroud)

当提供者为“网络”时,我得到位置坐标。

当我更改位置和安全选项中的设置以启用“使用 GPS 卫星”选项时,提供商更改为“ gps ”。在这种情况下,返回的位置为空。

这可能是什么原因,如何纠正?

java android

4
推荐指数
1
解决办法
8156
查看次数

eclipse要求我在finally块中使用try/catch包围 - 可以禁用它吗?

在我的一个Java应用程序代码中,我有一个try-catch-finally块,其中try块创建一些输入和输出流,如果出现问题,我将关闭任何先前打开的流finally.

finally
{
    if(inputStream != null)
        inputStream.close();
    if(outputStream != null)
        outputStream.close();
}
Run Code Online (Sandbox Code Playgroud)

但是<stream>.close()Eclipse中的这行显示了该行代码中的"Unhandled exception IOException"错误,并显示该解决方案是try/catchfinally块中包含另一个,这似乎是编程实践中的坏事,我不想在finally块中.

我的问题是:是否有可能在Eclipse中删除此错误并try/catch仅在我需要它时使用而不是eclipse告诉我进行try/catch添加.(因为我已经开始尝试通过更换以避免异常try/catchif/else越好).

java eclipse

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

使用服务中的AlarmManager更新Android定期GPS位置

我在这里阅读了很多问题,但无法弄清问题是什么.

我正在为Android编写一个现场服务应用程序.在其中一个活动(MyActivity.java)中,我有两个按钮:Start和Stop.

当现场工作人员按下启动时,我需要使用GPS获取当前位置并及时将其发送到服务器(比如默认为5分钟,这里我将其设置为20秒进行测试).客户希望看到工人花多长时间在交通上,我的城市(伊斯坦布尔)的交通是一团糟.

我的活动中有一个AlarmManager,当按下开始按钮时,警报被设置AlarmManager.setRepeating()为启动服务(ServiceClass.java).

Intent intent = new Intent (MyActivity.this, ServiceClass.class);
mPendingIntent = PendingIntent.getService(MyActivity.this, 0, intent,
                                              PendingIntent.FLAG_CANCEL_CURRENT);
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mAlarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 20*1000,
                                                                  mPendingIntent);
Run Code Online (Sandbox Code Playgroud)

我用停止按钮取消闹钟.

它完美地运行到此为止,服务开始了.它onCreate(),onStart()并且onDestroy()方法执行.但我无法得到这个位置.我没有在真正的设备上工作,所以我使用DDMS发送位置.但应用程序跳过该步骤并打印我的位置的经度和纬度为Lon:0 Lat:0.

这是服务中的代码:

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.d("Testing", "Service got started, calling location updates:");
    mLocationManager.requestSingleUpdate(mCriteria, mLocationListener,
                                                                getMainLooper());
    Log.i("TESTING LOCATION UPDATE: LOCATION:", "\nLat:"   + mLatitude +
                                                          "  Lon:" + mLongitude);
    stopSelf(startId);
    Log.d("Testing", "Service Stopped!");
Run Code Online (Sandbox Code Playgroud)

最后,这是我的LocationListener:

 mLocationListener = new LocationListener() {
        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

service gps android alarmmanager

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

如何在android中的内部/外部存储中保存已解析的文本文件

目前我在项目中工作,我需要解析远程文本文件并将其存储在本地存储(内部/外部).我能够解析文本文件但无法将其存储在SDCARD中.这是我的代码:

package com.exercise.AndroidInternetTxt;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidInternetTxt extends Activity {

    TextView textMsg, textPrompt;
    final String textSource = "http://sites.google.com/site/androidersite"
                                                              + "/text.txt";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textPrompt = (TextView) findViewById(R.id.textprompt);
        textMsg = (TextView) findViewById(R.id.textmsg);
        textPrompt.setText("Wait...");
        URL textUrl;
        try {
            textUrl = new URL(textSource);
            BufferedReader bufferReader = new BufferedReader(
                    new InputStreamReader(textUrl.openStream()));
            String StringBuffer;
            String stringText = …
Run Code Online (Sandbox Code Playgroud)

storage android text external internal

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

与Github for Mac app同步时出错

我在同步时尝试登录后收到此错误.我不知道是什么导致它,并且在搜索时似乎无法找到任何关于它的信息.我知道我正在输入正确的用户名和密码.有人有主意吗?

2012-11-12 09:49:20.122 GitHub for Mac Login[64648:707] Error reading generic password: The user name or passphrase you entered is not correct. 2012-11-12 09:49:20.123 GitHub for Mac Login[64648:707] Error reading internet password: The specified attribute does not exist. error: unable to read askpass response from '/Applications/GitHub.app/Contents/MacOS/GitHub for Mac Login' fatal: could not read Username for 'https://github.com': Device not configured (256)

git github github-for-mac

4
推荐指数
1
解决办法
8611
查看次数

twitter4j - 通过ID获取推文

当我有推文ID和用户ID时,如何获取推文?我有一个包含以下行的文件:

userID  tweetID
Run Code Online (Sandbox Code Playgroud)

我想我应该过去:

Query query = new Query("huh ?");
QueryResult result = twitter.search(query);
List<Status> tweets = result.getTweets();
Run Code Online (Sandbox Code Playgroud)

但我不知道如何拼写 query

谢谢

twitter4j

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

调用需要API级别14(当前最小值为10):

我该如何解决这个错误?我不明白这个错误背后的原因?

devicePolicyManager.setCameraDisabled(demoDeviceAdmin, false);
Run Code Online (Sandbox Code Playgroud)

错误:

调用需要API级别14(当前最小值为10):android.app.admin.DevicePolicyManager#setCameraDisabled DevicePolicyDemoActivity.java/DevicePolicyDemoActivity/src/com/marakana/android/devicepolicydemo line 62 Android Lint问题

android

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

NotificationCompat.Builder不起作用,Android 2.2.1

我有下一个代码:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        this).setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
Run Code Online (Sandbox Code Playgroud)

为什么它不起作用?它没有任何表现.在Android 2.2.1上测试.

更新.活动代码:

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
import android.view.View;

public class LoginActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    public void start(View view) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("My notification")
                .setContentText("Hello World!");
    }
}
Run Code Online (Sandbox Code Playgroud)

布局按钮:

<Button
    android:id="@+id/startButton"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/aboutButton"
    android:layout_alignLeft="@+id/aboutButton"
    android:layout_marginBottom="20dp"
    android:onClick="start"
    android:text="Start" />
Run Code Online (Sandbox Code Playgroud)

UPDATE2.错误日志:

02-04 11:40:40.752: D/dalvikvm(23054): GC_EXTERNAL_ALLOC freed 859 objects / 59168 bytes …
Run Code Online (Sandbox Code Playgroud)

android

4
推荐指数
1
解决办法
7142
查看次数

Android GoogleMaps V2 MarkerDemo IllegalStateException没有包括点

我正在为GoogleMaps V2创建MarkerDemo的自定义实现.我有一个奇怪的错误,我将LatLng值提供给LatLngBounds.Builder实例,然后将其作为变量传递给.build.当我通过Eclipse在调试模式下运行应用程序时,Map会加载.当我通过Eclipse正常运行时,会抛出一个带有"no included points"的IllegalStateException作为消息.有人可以帮忙吗?

这是一些协助的代码.

public class MyActivity extends android.support.v4.app.FragmentActivity
        implements OnMarkerClickListener, OnInfoWindowClickListener,
        OnMarkerDragListener {

    private HashMap<DataItem, ArrayList<DataItem>> mUserLocations = new
             HashMap<DataItem, ArrayList<DataItem>>();
    private ArrayList<DataItem> mFeedData;
    private NetworkingHandler mHandler = new NetworkingHandler("tag");
    private GoogleMap mMap;
    private final String DOWNLOAD_USER_LOCATIONS_URL =
               "http://www.myfeedurllocation.com/page.php";

    @Override
    public void onCreate(Bundle savedBundleInstance) {
        super.onCreate(savedBundleInstance);
        setContentView(R.layout.activity_myactivitylayout);
        downloadUserLocations();
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the
        // map. …
Run Code Online (Sandbox Code Playgroud)

java android android-sdk-2.3 illegalstateexception google-maps-android-api-2

4
推荐指数
1
解决办法
6034
查看次数

使用JGit获取存储库的所有标记

我想获得一个存储库的所有标签列表以及tagger和带有JGit的commit-IDs.

首先,我尝试了Git.tagList().call()命令并解析标签:

objectIdOfTag = oneResultOfTheTagList.getObjectId(); 
// or should I call getPeeledObjectId() here?

RevWalk walk = new RevWalk(repository);
RevTag tag = walk.parseTag(objectIdOfTag);
Run Code Online (Sandbox Code Playgroud)

这适用于我的存储库,但我不确定这是否正确:呼叫是正确Ref.getObjectId()还是应该呼叫Ref.getPeeledObjectId()?(什么是" 去皮的 ObjectId"?)

使用JGit检索标记列表时,轻量级和带注释的标记之间是否存在差异?

java tags jgit

4
推荐指数
1
解决办法
2578
查看次数