1 /* Copyright 2020 Braden Farmer
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 package com.farmerbb.taskbar.activity;
18 import android.app.Activity;
19 import android.content.ActivityNotFoundException;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Bundle;
24 import com.farmerbb.taskbar.R;
25 import com.farmerbb.taskbar.util.AppEntry;
26 import com.farmerbb.taskbar.util.ApplicationType;
27 import com.farmerbb.taskbar.util.U;
29 public class PersistentShortcutLaunchActivity extends Activity {
32 protected void onCreate(Bundle savedInstanceState) {
33 super.onCreate(savedInstanceState);
35 String packageName = getIntent().getStringExtra("package_name");
36 String componentName = getIntent().getStringExtra("component_name");
37 String windowSize = getIntent().getStringExtra("window_size");
39 if(!U.canDrawOverlays(this) && windowSize != null) {
40 Intent intent = new Intent(this, DummyActivity.class);
41 intent.putExtra("show_permission_dialog", true);
42 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
44 startActivity(intent);
45 } else if(packageName != null && componentName != null) {
46 final AppEntry entry = new AppEntry(packageName, componentName, null, null, false);
48 U.launchApp(this, entry, windowSize, () -> {
49 Intent intent = new Intent(Intent.ACTION_VIEW);
50 intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
53 startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, null));
54 } catch (ActivityNotFoundException | IllegalArgumentException e1) { /* Gracefully fail */ }
57 U.showToast(this, R.string.tb_invalid_shortcut);