michelelacorte / FlickLauncher

Pixel Launcher for everyone!
Apache License 2.0
290 stars 78 forks source link

[Request] Apply icon pack from other app #42

Closed danimahardhika closed 6 years ago

danimahardhika commented 7 years ago

I'm the creator of CandyBar dashboard for icon pack. It will be very helpful if user able to apply icon pack directly from the dashboard without opening Flick Launcher settings.

Something like Aviate launcher has (Scroll to bottom)

Or like Nova launcher has

final Intent intent = new Intent("com.teslacoilsw.launcher.APPLY_ICON_THEME");
intent.setPackage("com.teslacoilsw.launcher");
intent.putExtra("com.teslacoilsw.launcher.extra.ICON_THEME_PACKAGE", context.getPackageName());
context.startActivity(intent);

Which will open a dialog ask if user want to apply the icon pack or directly apply the icon pack.

michelelacorte commented 7 years ago

Sure, you can do this:

final Intent intent = new Intent("com.android.launcher3.FLICK_ICON_PACK_APPLIER");
intent.setPackage("com.android.launcher3");
intent.putExtra("com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
context.startActivity(intent);

If you send me an APK I can test this!

danimahardhika commented 7 years ago

It doesn't work

android.content.ActivityNotFoundException: No Activity found to handle Intent { 
    act=com.android.launcher3.FLICK_ICON_PACK_APPLIER flg=0x10000000 pkg=com.android.launcher3 (has extras)
    ...

If it's a receiver, I think you should register it first inside manifest

michelelacorte commented 7 years ago

Yes, I mean this is not implemented yes, but you can do that on your app, than pass me APK and I test it with my code (which is not released)

danimahardhika commented 7 years ago

Check here. I only added 1 icon for Chrome.

michelelacorte commented 7 years ago

Candy app tell me Launcher is not installed (in installed section WTF?)...and open Google Play..

danimahardhika commented 7 years ago

I told you before, it doesn't works. You need to register the receiver inside flick launcher manifest.

michelelacorte commented 7 years ago

I've do that!..see screenshot

alt tag

alt tag

danimahardhika commented 7 years ago

This is the packagename I used to check if Flick launcher installed

com.universallauncher.universallauncher

I used this code to apply from the dashboard

final Intent flick = new Intent("com.android.launcher3.FLICK_ICON_PACK_APPLIER");
flick.setPackage("com.android.launcher3");
flick.putExtra("com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(flick);
((Activity) context).finish();

Then this exception shown right after context.startActivity(flick) called

android.content.ActivityNotFoundException: No Activity found to handle Intent { 
    act=com.android.launcher3.FLICK_ICON_PACK_APPLIER flg=0x10000000 pkg=com.android.launcher3 (has extras)
michelelacorte commented 7 years ago

Seems correct, but I don't understand wht it tell me "Flick Launcher is not installed" I've also tried with signed apk..

michelelacorte commented 7 years ago

So?? @danimahardhika

danimahardhika commented 7 years ago

Already follow your guide above, but not working.

  1. If the project you are using same with the one here, make sure to register the receiver in manifest. Because I don't see it here.
  2. Make sure to register the receiver inside activity too.
michelelacorte commented 7 years ago

Bro, you don't understand...Your apk doesn't work with my code (not updated in github, it's my private code!)

danimahardhika commented 7 years ago

I'm just following your guide. Nova launcher has similar code to apply icon pack and it works.

danimahardhika commented 7 years ago

What's the package name of flick launcher? Is it this one

com.universallauncher.universallauncher
michelelacorte commented 7 years ago

Yes but problem is that your apk doesn't give me access to Flick Launcher, it is showed in installed apps but when I click it tell me "Flick Launcher is not installed" so it redirect me in Play store and..Flick launcher is installed..WTF?

Yes it is correct package!

danimahardhika commented 7 years ago

Should I explain to you one more time?!

This is the packagename I used to check if Flick launcher installed

com.universallauncher.universallauncher

I used this code to apply from the dashboard

final Intent flick = new Intent("com.android.launcher3.FLICK_ICON_PACK_APPLIER");
flick.setPackage("com.android.launcher3");
flick.putExtra("com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(flick);
((Activity) context).finish();

Then this exception shown right after context.startActivity(flick) called

android.content.ActivityNotFoundException: No Activity found to handle Intent { 
    act=com.android.launcher3.FLICK_ICON_PACK_APPLIER flg=0x10000000 pkg=com.android.launcher3 (has extras)
try {
    final Intent flick = new Intent("com.android.launcher3.FLICK_ICON_PACK_APPLIER");
    flick.setPackage("com.android.launcher3");
    flick.putExtra("com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
    flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(flick);
    ((AppCompatActivity) context).finish();
} catch (ActivityNotFoundException e) {
    //When the exception called, that means the launcher not installed, there will be a popup dialog to ask if user want to install the launcher from play store
    openGooglePlay(context, launcherPackage, launcherName);
}

The problem comes from your side, not mine

I tried to change the code like this, since I can't test it by myself, I don't know if it's working or not. Check here

final Intent flick = new Intent("com.android.launcher3.FLICK_ICON_PACK_APPLIER");
//before com.android.launcher3
flick.setPackage("com.universallauncher.universallauncher");
flick.putExtra("com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(flick);
((AppCompatActivity) context).finish();
viztushar commented 7 years ago

he use two different package names this package name in build.gradle as applicationId

com.universallauncher.universallauncher

this package name use in all java code

com.android.launcher3

so maybe you need to do like this

final Intent flick = new Intent("com.universallauncher.universallauncher/com.android.launcher3.FLICK_ICON_PACK_APPLIER");
//before com.android.launcher3
flick.setPackage("com.universallauncher.universallauncher/com.android.launcher3");
flick.putExtra("com.universallauncher.universallauncher/com.android.launcher3.extra.ICON_THEME_PACKAGE", context.getPackageName());
flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(flick);
((AppCompatActivity) context).finish();

maybe i'm wrong but try it

michelelacorte commented 7 years ago

What I've do:

Class ApplyIconPack.java

public class ApplyIconPack extends BroadcastReceiver{
    public static final String ICON_PACK_APPLIER_ACTION = "com.android.launcher3.FLICK_ICON_PACK_APPLIER";

    public ApplyIconPack(){

    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("ApplyIconPack", "new Intent Received ");
        //Apply icon pack method here
    }
}

Then in onCreate()

        ApplyIconPack receiver = new ApplyIconPack();
        IntentFilter intentFilter = new IntentFilter(ApplyIconPack.ICON_PACK_APPLIER_ACTION);
        registerReceiver(receiver, intentFilter);

in Manifest.xml

        <receiver android:name=".util.ApplyIconPack">
            <intent-filter>
                <action android:name="com.android.launcher3.FLICK_ICON_PACK_APPLIER" />
            </intent-filter>
        </receiver>

Package name: com.android.launcher3 App id: com.universallauncher.universallauncher

danimahardhika commented 7 years ago

This one should works CandyBar.apk

michelelacorte commented 7 years ago

No, it always tell me to install Flick Launcher...

viztushar commented 7 years ago

this code open the FlickLauncher Choose Icon

val flick = Intent()
flick.`package` = "com.universallauncher.universallauncher"
flick.putExtra("com.universallauncher.universallauncher/com.teslacoilsw.launcher.APPLY_ICON_THEME",packageName)
flick.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(flick)

but after i click on the Choose icon Flick Launcher close

screenshot_20170526-213141 1

michelelacorte commented 6 years ago

So my code in onCreate() is

        if(getIntent()!=null && getIntent().getAction()!=null && getIntent().getAction().equals("com.android.launcher3.FLICK_ICON_PACK_APPLIER")){
            String iconPackPackage = getIntent().getStringExtra("icon_pack_package");
            if(iconPackPackage!=null && !iconPackPackage.isEmpty()) {
                //update icon
            }
        }

other things to do?

You should do:

        final Intent flick = new Intent("com.universallauncher.universallauncher/com.android.launcher3.FLICK_ICON_PACK_APPLIER");
        flick.setPackage("com.universallauncher.universallauncher/com.android.launcher3");
        flick.putExtra("com.universallauncher.universallauncher/com.android.launcher3.FLICK_ICON_PACK_APPLIER", context.getPackageName());
//or this flick.putExtra("icon_pack_package", context.getPackageName());
        flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(flick);
        ((AppCompatActivity) context).finish();
danimahardhika commented 6 years ago

That's not working, the log:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.universallauncher.universallauncher/com.android.launcher3.FLICK_ICON_PACK_APPLIER flg=0x10000000 pkg=com.universallauncher.universallauncher/com.android.launcher3 (has extras) }
michelelacorte commented 6 years ago

Anyway my launcher/dafault activity is com.universallauncher.universallauncher.Launcher if you call this with string extra "icon_pack_package" to identify icon pack string and with this action: "com.universallauncher.universallauncher.FLICK_ICON_PACK_APPLIER", and send me apk

michelelacorte commented 6 years ago

add this to fix, but YOU CANNO'T TEST because you don't have new update, so pass me apk with this


                 //Todo: fix direct apply for flick launcher
                 try {
                     final Intent flick = context.getPackageManager().getLaunchIntentForPackage(
                             "com.universallauncher.universallauncher");
                     final Intent flickAction = new Intent("com.universallauncher.universallauncher.FLICK_ICON_PACK_APPLIER");
                     flickAction.putExtra("com.universallauncher.universallauncher.ICON_THEME_PACKAGE", context.getPackageName());
                     flick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                     context.sendBroadcast(flickAction);
                     context.startActivity(flick);
                     ((AppCompatActivity) context).finish();
                  } catch (ActivityNotFoundException | NullPointerException e) {
                      openGooglePlay(context, launcherPackage, launcherName);
                  }
                 break;
michelelacorte commented 6 years ago

Fixed!

Phonlab-Android commented 5 years ago

I am trying to get this same problem figure out do you have a true fix for this i read this thread 5 times and nothing in it is letting me apple my icon pack to flick launcher