1. joonood's Avatar
    I want to create a SDK in android studio and useit in my other mobile applications.

    I'm some what new to android studio. In the SDK I want to manage notifications, such as getting notification from server, create channels and show notification. When my code is in the application, it works, but when I moved it to the android library, it doesn't work and in running mode application closed. what should I do? What steps do I need to correctly create SDK for my applications?

    code to create channels

    private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = getString(R.string.channel_name);
    String description = getString(R.string.channel_description);
    int importance = NotificationManager.IMPORTANCE_DEFAULT;
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
    channel.setDescription(description);
    // Register the channel with the system; you can't change the importance
    // or other notification behaviors after this
    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    notificationManager.createNotificationChannel(channel);
    }
    }

    code to show notifications

    btnShow.setOnClickListener(new View.OnClickListener(){
    @override
    public void onClick(View view) {
    try {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle("Notification")
    .setContentText("test")
    .setChannelId(CHANNEL_ID)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    ;
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, mBuilder.build());
    }
    catch (Exception ex)
    {
    Log.i("Log Error",ex.getMessage());
    }
    }
    });

    These codes work on application itself but not in the library.
    08-01-2019 02:50 AM
  2. Rukbat's Avatar
    You're looking to build a library, not an SDK. An SDK is a whole system, including an editor, a compiler, a method of building the code into an apk, etc. A whole kit.
    08-01-2019 12:07 PM

Similar Threads

  1. Verizon moto z2 force Android 9.0 Pie update is live
    By jimcapraro in forum Moto Z2 Force
    Replies: 4
    Last Post: 08-10-2019, 11:37 PM
  2. Why is it that whenever im done making a call, I no longer have video audio?
    By Android Central Question in forum Ask a Question
    Replies: 9
    Last Post: 08-01-2019, 10:52 PM
  3. Replies: 3
    Last Post: 08-01-2019, 03:56 PM
LINK TO POST COPIED TO CLIPBOARD