Android Studio learning record - sixth week

7.4.2 cross-program data sharing

In ProviderTest the click of a button can not be achieved printing function log, it is still unresolved.

 

Basic Usage 8.2.1 notice

According to the book code error;

      The reason is that Android 8.0 introduces notification channels, upgrade targeSdk after 26 to achieve all notifications are required to provide notification channels, without providing notification channels, then all notifications in 8.0 above system can not display properly.

MainActivity.java code is as follows

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    String id="channel_1";
    int importance = NotificationManager.IMPORTANCE_HIGH;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button sendNotice = (Button)findViewById(R.id.send_notice);
        sendNotice.setOnClickListener(this);
    }
    @Override
    public void onClick(View v){
        switch (v.getId()) {
            case R.id.send_notice:
                NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                NotificationChannel mchannel = new NotificationChannel(id,"test",importance);
                manager.createNotificationChannel(mchannel);
                Notification notification;
                notification = new NotificationCompat.Builder(this,id)
                        .setContentTitle("This is content title")
                    .setContentText("This is content text")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .build();
                manager.notify(1, notification);
                break;
            default:
                break;
        }
    }
}

Also need to minSdkVersion gradle file is set to 26;

 

Advanced features 8.2.3 notice

NotificationCompat.Builder of setSmallIcon no effect when calling ic_launcher,

16 * 16 pixels eventually replaced can show in FIG.

8.3.1 call camera to take pictures

android.support.v4.content.FileProvider deprecated

It should be amended to

 

androidx.core.content.FileProvider

 

8.4.1 Play Audio

No music sounded, to be resolved after clicking play.

 

Guess you like

Origin www.cnblogs.com/yangyangyang-xiannv/p/12236014.html