Recently Added

6/recent/ticker-posts

Music Player App Part 1 in Android Studio | How to Make Music Player App

In this Music Player App Part 1 I am going to show you how to ask permission for Storage 

So let's start 

Download ICONS Folder.

1. Colors


<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="dark_blue">#191b20</color>
<color name="blue">#4a80f0</color>
<color name="light_black">#101116</color>
<color name="dark_grey">#41454a</color>
<color name="heart_fill">#4a80f0</color>
<color name="ripple_color">#737988</color>

2.create splash_screen.xml file in drawable and add this code

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


<item android:drawable="@color/dark_blue" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo" />
</item>

</layer-list>

3.Update your theme.xml

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Music" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">@color/dark_blue</item>
<!-- navigation bar color. -->
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/light_black</item>
<item name="android:colorEdgeEffect">@android:color/transparent</item>
<item name="colorControlHighlight">@color/ripple_color</item>
<item name="android:background">?attr/selectableItemBackground</item>
<item name="android:windowBackground">@color/dark_blue</item>
<item name="android:windowContentTransitions">true</item>

</style>

<style name="SplashScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:statusBarColor" tools:targetApi="l">@color/dark_blue</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/light_black</item>
</style>

</resources>

4.update your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.music">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Music">
<activity android:name=".MainActivity"></activity>
<activity android:name=".SplashScreen"
android:theme="@style/SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

5.Create a SplashScreen.java File in Your Project and add this code 


public class SplashScreen extends AppCompatActivity {


public static final int REQUEST_CODE_FOR_PERMISSION = 1;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkStoragePermission();
}

private void checkStoragePermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
//asking permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_FOR_PERMISSION);
}else {
nextActivity();
}
}


@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_CODE_FOR_PERMISSION){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
nextActivity();
}else {
//asking permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_FOR_PERMISSION);
}
}
}

private void nextActivity(){
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
finish();
}
}

Watch Tutorials

Post a Comment

1 Comments