我想在我的 Android 应用程序中包含 2 个东西。
获取设备id,然后用这个id打开一个网页。例如 myserver.com/deviceId
我的主要 java 类如下所示:
package es.unican.CityInfo;
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.provider.Settings.Secure;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webview);
mywebview.loadUrl("http://www.google.com");
//enabling Javascript
WebSettings webSettings = mywebview.getSettings();
webSettings.setJavaScriptEnabled(true);
//opening links in my webview. if you delete this line , any link pressed will cause the browser to start
mywebview.setWebViewClient(new WebViewClient());
}
}
为了获得我读到的设备 ID,我应该这样做:
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
但是我不明白我应该把 android_id 代码放在哪里,因为我总是得到一个错误。
错误是:
Multiple markers at this line:
- The method getcontext() is undefined for the type MainActivity
- Illegal modifier for parameter android_id; only final is permitted
最佳答案
用这个替换你的错误行:
String android_id = Secure.getString(this.getContentResolver(),Secure.ANDROID_ID);
关于android - 我如何在 Android 中获取设备 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15807090/