02.03.2020 - 06.03.2020 arası işler

c# parallel.ForEach() Link
c# webrequest Link
c# parallel Programing action Link
c# Console.App dotnetcore için servis konfigürasyon ekleme Link
c# Console.App dotnetcore için konfigürasyon ekleme Link

- Macbook için yüklemenizi önerdiğimiz programlar Link

- LG Mobile Driver Windows 8.1 Link

Android Push Notification



Android üzerinde google cloud messaging ile push notification almak için bu video işimi gördü ama güncel versiyona şu tarihte en yakın arayüz çalışması olmasına rağmen eksikleri var. Aşağıdaki hataları aldım. Çözüm linkleri aşağıda.


Log fonksiyonu kullanırken TAG nedir Link

Android app üzerinde Firebase GCM ile Push Notification göndermek için Link
Makalenin tarihini kontrol etmenizde fayda var. Bazen yeni versiyonla bazı metodlar depreşe olabiliyor. Mesela FirebaseInstanceIdService sınıfıda depreşe olmuş ve bu sayfada ve bu sayfada depreşe olduğunu anlatıyorlar

no target device found android studio
Bu hata uygulamayı denemek için bir cihaz veya virtual emulatör seçili olmadığı için veriyor. Bu sayfada ki öneriler ile düzeliyor

Error type 3 Error: Activity class {} does not exist,

Bu hatayı test cihazında app'ı kaldırıp yeni app'ı install ederken aldım. Bu sayfada seçili önerileri yaptım ama fayda vermedi. Ancak aynı sayfanın altında ikinci sıradaki öneri işime yaradı. Hatanın bendeki nedeni app'ı cep telefonundan silerken tam silmemiş olması. App arafta kalınca yeni app yüklemesi hata verip bir türlü gerçekleşmiyordu.

uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library
Bu hatada enteresan ayarlar ile ilgili Link

Burada temel kodları paylaşıyorum. İlk olarak AndroidManifest.xml
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"

        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
             See README(https://goo.gl/l4GJaQ) for more. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@android:drawable/ic_notification_clear_all" />
        <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
             notification message. See README(https://goo.gl/6BKBk7) for more. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="CodeAndroid" />

    </application>

</manifest>

İkinci sırada mainactivity.kt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.messaging.FirebaseMessaging


class MainActivity : AppCompatActivity() {
    companion object {

        private const val TAG = "MainActivity"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        FirebaseMessaging.getInstance().isAutoInitEnabled = true
        FirebaseInstanceId.getInstance().instanceId
            .addOnCompleteListener(OnCompleteListener { task ->
                if (!task.isSuccessful) {
                    Log.w(TAG, "getInstanceId failed", task.exception)
                    return@OnCompleteListener
                }

                // Get new Instance ID token
                val token = task.result?.token
               
                Log.d(TAG, "RefreshToken: " + token)
                // Log and toast

                Log.d(TAG, token)
                Toast.makeText(baseContext, token, Toast.LENGTH_SHORT).show()
            })
    }


}

MyFireBaseMessagingService.kt burada gelen mesajın çeşitli şekillerde kullanılmasını sağlamak için bu servisi yazıyoruz.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.example.myapplication

import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

private const val TAG = "MyActivity"
class MyFirebaseMessagingService : FirebaseMessagingService(){
    override fun onMessageReceived(p0: RemoteMessage) {
        //super.onMessageReceived(p0)
        if(p0?.data != null){
            Log.d(TAG, "Data: " + p0.data.toString())
        }

        if(p0?.notification != null){
            Log.d(TAG, "Notification: " + p0.notification!!.toString())
        }
    }

    override fun onNewToken(token: String) {
        Log.d(TAG, "Refreshed token: $token")
        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        sendRegistrationToServer(token)
    }

    private fun sendRegistrationToServer(token: String?) {
        // TODO: Implement this method to send token to your app server.
        Log.d(TAG, "sendRegistrationTokenToServer($token)")
    }
}

Build Gradle (module)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.noterkeeper"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
    //implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Build.Gradle (App)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        //classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.gms:google-services:4.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

GCM firebase Java implementasyonu Link
Android stüdyo içinde kodları kopyala yapıştır yaparken Cannot resolve

'R.string.gcm_send_message' şeklinde bir hata alıyorsanuz resource dosyasına gcm_send_message stringi eklemeniz gerekmektedir. Link

Websocket ile bytearray tipinde data alıyorsanız byte içindeki sıfır verileri kaldırmak için bu metodu kullanabilirsiniz Link
 public byte[] Decode(byte[] packet)  
 {  
   var i = packet.Length - 1;  
   while(packet[i] == 0)  
   {  
     --i;  
   }  
   var temp = new byte[i + 1];  
   Array.Copy(packet, temp, i + 1);  
   MessageBox.Show(temp.Length.ToString());  
   return temp;  
 }  

Yorumlar

Bu blogdaki popüler yayınlar

22.06.2020 - 26.06.2020 arası işler

Asp.net RestSharp ile data post etmek

List Box Item içindeki elemanları aşağı veya yukarı taşımak