Android UUID - problem z wyświetleniem

Odpowiedz Nowy wątek
2017-03-08 14:19
0

Hej,
Pobieram UUID Android dla urządzenia, dodałam do manifestu

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

następnie gdy kilkam przycisk aplikacja się zatrzymuje

public class GetNumberActivity extends AppCompatActivity {
    private final static String EXTRA_MESSAGE = "uuidValue";
    private static int REQUEST_CODE = 1;
    private TextView uniqueTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_number);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Typeface custom_fonts = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Light.ttf");

        Typeface custom_fonts2 = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Bold.ttf");

        TextView toolbarText = (TextView) findViewById(R.id.title_GetNumber);
        toolbar.setNavigationIcon(R.drawable.ic_restart);

        toolbarText.setTypeface(custom_fonts);

        TextView stageOneText = (TextView) findViewById(R.id.stageOneText);
        stageOneText.setTypeface(custom_fonts);

        TextView stageTwoText = (TextView) findViewById(R.id.stageTwoText);
        stageTwoText.setTypeface(custom_fonts);

        TextView generateCard = (TextView) findViewById(R.id.textViewGenerationCard);
        generateCard.setTypeface(custom_fonts);

        uniqueTextView = (TextView) findViewById(R.id.uniqueNumberTextView);
        uniqueTextView.setTypeface(custom_fonts2);

        TextView nextButton = (TextView) findViewById(R.id.nextButton);
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                uniqueTextView.setText(deviceUDID(GetNumberActivity.this));

//                Intent intent = new Intent(GetNumberActivity.this, ScanQrCodeActivity.class);
//
//                // intent.putExtra(EXTRA_MESSAGE,)
//                startActivity(intent);
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    public String deviceUDID(Context ctx) {
        final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

        final String tmDevice, tmSerial, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        String deviceId = deviceUuid.toString();
        Log.d("Device Id", deviceId);
        return deviceId;
    }
}

Pojawiające się error

logi

       03-08 14:22:39.496 20825-20825/com.novum.smrtkarta E/AndroidRuntime: FATAL EXCEPTION: main
       Process: com.xxxx.smrtkarta, PID: 20825
       java.lang.SecurityException: getDeviceId: Neither user 10155 nor current process has android.permission.READ_PHONE_STATE.
       at android.os.Parcel.readException(Parcel.java:1620)
                                                                         at android.os.Parcel.readException(Parcel.java:1573)
                                                                         at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4207)
                                                                         at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
                                                                         at com.novum.smrtkarta.activity.GetNumberActivity.deviceUDID(GetNumberActivity.java:81)
                                                                         at com.novum.smrtkarta.activity.GetNumberActivity$1.onClick(GetNumberActivity.java:62)
                                                                         at android.view.View.performClick(View.java:5204)
                                                                         at android.view.View$PerformClick.run(View.java:21153)
                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
edytowany 4x, ostatnio: magdalena123, 2017-03-08 14:27

Pozostało 580 znaków

2017-03-09 13:04
0

https://www.google.pl/search?[...]d.permission.READ_PHONE_STATE


Chcesz pomocy - pokaż kod - abrakadabra źle działa z techniką.

Pozostało 580 znaków

2017-03-09 13:25
0

btw, radziłbym uważać bo nie każdy devica ma UUID

Pozostało 580 znaków

Odpowiedz
Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0