2011-05-12 133 views
0

所以有一個不錯的博客使用下面的代碼識別應用安裝

public class Installation { 
    private static String sID = null; 
    private static final String INSTALLATION = "INSTALLATION"; 

    public synchronized static String id(Context context) { 
     if (sID == null) { 
      File installation = new File(context.getFilesDir(), INSTALLATION); 
      try { 
       if (!installation.exists()) 
        writeInstallationFile(installation); 
       sID = readInstallationFile(installation); 
      } catch (Exception e) { 
       throw new RuntimeException(e); 
      } 
     } 
     return sID; 
    } 

    private static String readInstallationFile(File installation) throws IOException { 
     RandomAccessFile f = new RandomAccessFile(installation, "r"); 
     byte[] bytes = new byte[(int) f.length()]; 
     f.readFully(bytes); 
     f.close(); 
     return new String(bytes); 
    } 

    private static void writeInstallationFile(File installation) throws IOException { 
     FileOutputStream out = new FileOutputStream(installation); 
     String id = UUID.randomUUID().toString(); 
     out.write(id.getBytes()); 
     out.close(); 
    } 
} 

在不同的Java類,我有一個的WebView去一個URL識別應用安裝,如圖

public class Notes extends Activity { 

    WebView mWebView; 

    /** Called when the activity is first created. */ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.timsnotes); 

     mWebView = (WebView) findViewById(R.id.webview3); 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.loadUrl("http://www.somedomain.com/notes.php?phoneid=" + "sID" + ""); 
     mWebView.setWebViewClient(new HelloWebViewClient()); 
    } 

但所有它傳遞的是文本sID。有沒有一個使用權限我缺少訪問sID?

回答

0

而不是「sID」use Installation.id(this); 這將解析id到一個字符串。目前你傳遞的是「sID」,沒有別的。