Ich versuche, eine Anwendung zu machen. Ich habe ein paar Probleme. Ich möchte Geräteinformationen in der Datei "DeviceActivity.java" erstellen und auf jeder Seite verwenden.Android Erstellen und Verwenden von Methoden
Der Codeblock I auf MainActivity.java erstellt:
public class MainActivity extends AppCompatActivity {
String email;
int MY_PERMISSIONS_EMAIL = 8889;
String imei;
int MY_PERMISSIONS_IMEI = 8889;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
////////////////////// E-Posta Sorgulama //////////////////////
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.GET_ACCOUNTS},
MY_PERMISSIONS_EMAIL);
} else {
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(MainActivity.this).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
email = account.name;
}
}
}
TextView epota = (TextView) findViewById(R.id.email);
epota.setText("E-posta: " + email);
////////////////////// E-Posta Sorgulama Son //////////////////////
////////////////////// Cihaz Modeli Sorgulama //////////////////////
String CihazModel = Build.MODEL;
TextView cihazmodel = (TextView) findViewById(R.id.cihaz_model);
cihazmodel.setText("Cihaz Modeli: " + CihazModel);
////////////////////// Cihaz Modeli Sorgulama Son //////////////////////
////////////////////// Cihaz İsmi Sorgulama //////////////////////
String CihazIsim = Build.MANUFACTURER;
TextView cihazisim = (TextView) findViewById(R.id.cihaz_isim);
cihazisim.setText("Cihaz İsmi: " + CihazIsim.toUpperCase()+ " " + CihazModel);
////////////////////// Cihaz İsmi Sorgulama Son //////////////////////
////////////////////// Bellek Sorgulama //////////////////////
RandomAccessFile reader = null;
String load = null;
DecimalFormat twoDecimalForm = new DecimalFormat("#.##");
double totRam = 0;
String lastValue = "";
try {
reader = new RandomAccessFile("/proc/meminfo", "r");
load = reader.readLine();
// Get the Number value from the string
Pattern p = Pattern.compile("(\\d+)");
Matcher m = p.matcher(load);
String value = "";
while (m.find()) {
value = m.group(1);
// System.out.println("Ram : " + value);
}
reader.close();
totRam = Double.parseDouble(value);
// totRam = totRam/1024;
double mb = totRam/1024.0;
double gb = totRam/1048576.0;
double tb = totRam/1073741824.0;
if (tb > 1) {
lastValue = twoDecimalForm.format(tb).concat(" TB");
} else if (gb > 1) {
lastValue = twoDecimalForm.format(gb).concat(" GB");
} else if (mb > 1) {
lastValue = twoDecimalForm.format(mb).concat(" MB");
} else {
lastValue = twoDecimalForm.format(totRam).concat(" KB");
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
// Streams.close(reader);
}
String CihazBellek = lastValue;
TextView cihazbellek = (TextView) findViewById(R.id.cihaz_bellek);
cihazbellek.setText("Cihaz Bellek: " + CihazBellek);
////////////////////// Bellek Sorgulama Son //////////////////////
////////////////////// İşletim Sistemi //////////////////////
String CihazOs = "Android";
TextView cihazos = (TextView) findViewById(R.id.cihaz_os);
cihazos.setText("Cihaz OS: " + CihazOs);
////////////////////// İşletim Sistemi Son //////////////////////
////////////////////// Cihaz ID Sorgulama //////////////////////
String CihazId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
TextView cihazid = (TextView) findViewById(R.id.cihaz_id);
cihazid.setText("Cihaz ID: " + CihazId);
////////////////////// Cihaz ID Sorgulama Son //////////////////////
////////////////////// Cihaz OS Versiyonu Sorgulama //////////////////////
Integer CihazApi = Build.VERSION.SDK_INT;
TextView cihazapi = (TextView) findViewById(R.id.cihaz_api);
cihazapi.setText("Cihaz Api: " + CihazApi.toString());
////////////////////// Cihaz OS Versiyonu Sorgulama Son //////////////////////
////////////////////// Cihaz Zaman Dilimi Sorgulama //////////////////////
String TimeZone = java.util.TimeZone.getDefault().getID();
TextView timezone = (TextView) findViewById(R.id.timezone);
timezone.setText("Timezone: " + TimeZone);
////////////////////// Cihaz Zaman Dilimi Sorgulama Son //////////////////////
////////////////////// Cihaz IMEI Sorgulama //////////////////////
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_PHONE_STATE},
MY_PERMISSIONS_IMEI);
} else {
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
imei = tManager.getDeviceId();
}
TextView cihazimei = (TextView) findViewById(R.id.imei);
cihazimei.setText("Cihaz Imei: " + imei);
////////////////////// Cihaz IMEI Sorgulama Son //////////////////////
}
}
Ich möchte die Codes auf dieser Seite passen auf anderen Seiten zu „DeviceActivity.java“ Seite und verwenden.
und was ist ein Problem? Warum kannst du es nicht anpassen? Oder willst du einfach, dass jemand es an deiner Stelle tut? –
Es funktioniert, wenn ich es der Homepage hinzufüge, aber ich kann es nicht auf einer anderen Seite ausführen. Ich wollte nicht, dass jemand anderes es macht, ich bat um Hilfe. @VladMatvienko –
Warum können Sie es nicht von einer anderen Seite ausführen? Was ist ein Problem dort? Welche Art von Hilfe willst du? –