2012-06-06 94 views
0

我想修改一個callerid應用程序,以便它打開瀏覽器窗口並調用特定的URL。 當呼叫進入時,下面的代碼發送到URL並返回呼叫者信息。這很好。我遇到的問題是我也想用預格式化的URL打開手機的默認瀏覽器。像http://www.myurl.com/index.php?action=getCallerInformation&number=phoneNumber.toString() 我的代碼是找不到符號java/android

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(意向); 找不到符號

回答

0

現在我已經讀了有關roboguice,所以會出現你需要:

@Inject Activity thisActivity; 

上述添加到您的聲明,然後使用調用的意圖:

thisActivity.startActivity(intent);