识别应用程序安装

时间:2011-05-12 21:23:33

标签: android

所以有一个很好的博客使用以下代码识别应用程序安装

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的使用权限?

1 个答案:

答案 0 :(得分:0)

而不是“sID”使用Installation.id(this); 这会将id解析为字符串。目前你正在传递“sID”,没有别的。

相关问题