相关疑难解决方法(0)

在不使用gps或互联网的情况下获取用户的当前位置名称,但在android中使用Network_Provider

这个问题与" Android:获取用户的当前位置而不使用gps或互联网 " 相同的主流stackoverflow问题直接相关,其中接受的答案实际上没有回答问题.

我应该能够通过网络提供商而不是GPS或互联网获取设备的当前位置名称(例如:城市名称,村庄名称).以下是该问题的公认答案.(以下代码部分应包含在onCreate()方法中)

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener …
Run Code Online (Sandbox Code Playgroud)

java android location locationmanager

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

VFY:无法解析静态方法10876:Android

我在我的程序中使用了SmsCbMessage.java类.它取自http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage 以下是我的程序.

package com.android.internal.telephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.telephony.SmsCbMessage;
import android.widget.Toast;

public class MainActivity extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //---get the CB message passed in---
        Bundle bundle = intent.getExtras();
        SmsCbMessage[] msgs = null;
        String str = "";
        if (bundle != null)  {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsCbMessage[pdus.length];
            for (int i=0; i<msgs.length; i++) {
                msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);
                str += "CB …
Run Code Online (Sandbox Code Playgroud)

java android

8
推荐指数
1
解决办法
1556
查看次数

标签 统计

android ×2

java ×2

location ×1

locationmanager ×1