0

我想修改一个 callerid 应用程序,以便它打开一个浏览器窗口并调用一个特定的 URL。当调用进入下面的代码时,会转到一个 URL 并返回调用者信息。这很好用。我遇到的问题是我还想用预先格式化的 url 打开手机默认浏览器。类似http://www.myurl.com/index.php?action=getCallerInformation&number=phoneNumber.toString () 我拥有的代码是

package com.integralblue.callerid;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import roboguice.inject.InjectResource;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.google.inject.Inject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;



public class HttpCallerIDLookup implements CallerIDLookup {
    @Inject SharedPreferences sharedPreferences;
    @InjectResource(R.string.default_lookup_url) String defaultLookupUrl;
    @Inject RestTemplate restTemplate;

    @Inject TelephonyManager telephonyManager;

    public CallerIDResult lookup(final CharSequence phoneNumber) throws NoResultException {
        //use the network's country if it's available (as I figure that's probably the best? I'm just guessing)
        //if the network's country isn't available, using the SIM's
        //I have no idea how or if this works on CDMA networks
        //(Android documentation warns that these function may not work as expected with CDMA)
        final String agentCountry = TextUtils.isEmpty(telephonyManager.getNetworkCountryIso())?telephonyManager.getNetworkCountryIso():telephonyManager.getSimCountryIso();

        final String beforeSubstitutionLookupUrl = sharedPreferences.getString("lookup_url", defaultLookupUrl);
        final String url;


            final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.myurl.com/index.php?action=getCallerInformation&number=phoneNumber.toString()"));
            startActivity(intent);


        if(beforeSubstitutionLookupUrl.contains("{0}")){
            // ensure backwards compatibility. The URL used to use {0} and {1}
            url = MessageFormat.format(beforeSubstitutionLookupUrl, "{number}", "{agentCountry}");
        }else{
            url = beforeSubstitutionLookupUrl;
        }
        final Map<String, String> urlVariables = new HashMap<String, String>();
        urlVariables.put("number", phoneNumber.toString());
        urlVariables.put("agentCountry", agentCountry);
        try{
            return restTemplate.getForObject(url, CallerIDResult.class, urlVariables);
        }catch(HttpClientErrorException e){
            if(HttpStatus.NOT_FOUND.equals(e.getStatusCode())){
                throw new NoResultException();
            }else{
                throw new RuntimeException(e);
            }
        }catch(Exception e){
            throw new RuntimeException(e);
        }
    }

}

当我编译它抱怨 startActivity(intent); 找不到标志

4

1 回答 1

0

我现在已经阅读了有关roboguice的信息,因此您似乎需要:

@Inject Activity thisActivity;

将上述内容添加到您的声明中,然后使用以下命令调用意图:

thisActivity.startActivity(intent);
于 2012-06-06T03:41:33.267 回答