Ok so first off, the issue is when i install my app and open it, it is starting a activity without being declared in my manifest as here below.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
I know that this above declare the a activity to be the activity ran when the app is launched, therefore should be the only one. Well i have some source code that i didn't originally write, Its for a launcher replacement app, therefore inside the source code i cant figure out how it is being launcher when its not declared in the manifest for this activity to be ran from the intial start, Its declare, but there isnt even a intent filter for it.
Is there some sort of java code you can declare a activity to be ran when the app is launched for the first time??? thats mainly my question.
Here The source im working with
classic.java
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnKeyListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.widget.Toast;
public class classic extends Activity {
/** Called when the activity is first created. */
private static String mPackageName = Constants.PACKAGE_LAUNCHER;
private ComponentName mCn = null;
private Activity currentActivity = null;
private boolean mApplyTheme = false;
private AlertDialog mConfirmDialog = null;
private ProgressDialog mProgressDialog = null;
private final String GOLAUNCHER_PKG_NAME = "com.gau.go.launcherex";
AttachInfo mAi = null;
class CustomAlertDialog extends AlertDialog {
public CustomAlertDialog(Context context) {
super(context);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean ret = super.onKeyDown(keyCode, event);
finish();
return ret;
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
private Handler mHandler = new Handler()
{
public void handleMessage(Message msg)
{
super.handleMessage(msg);
AlertDialog.Builder localBuilder2 = new AlertDialog.Builder(
classic.this);
localBuilder2.setTitle("Go Launcher EX not Found");
localBuilder2
.setMessage("Do you want to vist the Go Launcher EX on Google Play?");
localBuilder2.setIcon(R.drawable.golauncherex);
localBuilder2.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface paramDialogInterface,
int paramInt) {
Intent localIntent = new Intent(
"android.intent.action.VIEW").setData(Uri
.parse("market://details?id=com.gau.go.launcherex"));
classic.this.startActivity(localIntent);
}
});
localBuilder2.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface paramDialogInterface,
int paramInt) {
}
});
localBuilder2.show();
}
};
@Override
protected void onResume() {
super.onResume();
currentActivity = this;
ThemeUtils.sendInactiveApplyThemeFlagBroadcast(this);
if (isExistGO(GOLAUNCHER_PKG_NAME))
{
final Result result = new Result();
displayStartGoLauncherDialog(result);
setVisible(false);
return;
}
setVisible(false);
mAi = MergeUtil.getAttachInfo(this);
// 判æ–é™„åŠ çš„æ˜¯åœ°å�€è¿˜æ˜¯apk
if(mAi != null && mAi.IsAttachApk())
{
// �动�并
MergeUtil.DoMergeFileTask(mHandler, this);
setVisible(false);
return;
}
AlertDialog.Builder localBuilder2 = new AlertDialog.Builder(
classic.this);
localBuilder2.setTitle("Go Launcher EX not Found");
localBuilder2
.setMessage("Do you want to vist the Go Launcher EX on Google Play?");
localBuilder2.setIcon(R.drawable.golauncherex);
localBuilder2.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface paramDialogInterface,
int paramInt) {
Intent localIntent = new Intent(
"android.intent.action.VIEW").setData(Uri
.parse("market://details?id=com.gau.go.launcherex"));
classic.this.startActivity(localIntent);
}
});
localBuilder2.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface paramDialogInterface,
int paramInt) {
}
});
localBuilder2.show();
}
private boolean isExistGO(String packageName) {
Result result = GoLauncherUtils.isGoLauncherExist(this);
mPackageName = result.packageName == null ? Constants.PACKAGE_LAUNCHER
: result.packageName;
mCn = result.componentName;
return result.isExist;
}
private void startGOLauncher(String packageName) throws Throwable {
GoLauncherUtils.startGoLauncher(this, packageName, mCn);
}
private void displayStartGoLauncherDialog(final Result result) {
String dialogtitle = null;
String dialogmsg = null;
String dialogok = null;
String dialogcancel = null;
String language = Locale.getDefault().getLanguage(); // zh
if(language.equals("zh"))
{
dialogtitle = "信�";
dialogmsg = "点击确定立刻�用桌�支�软件";
dialogok = "确定";
dialogcancel = "�消";
}
else
{
dialogtitle = "Go Launcher EX";
dialogmsg = "Press OK button to launch GO Launcher EX";
dialogok = "OK";
dialogcancel = "Cancel";
}
mConfirmDialog = new AlertDialog.Builder(this)
.setTitle(dialogtitle)
.setMessage(dialogmsg)
.setPositiveButton(dialogok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// NotificationActivity.this.finish();
startGoLauncher(
result.packageName == null ? Constants.PACKAGE_LAUNCHER
: result.packageName,
result.componentName);
}
})
.setNegativeButton(dialogcancel,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
classic.this.finish();
}
}).setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
classic.this.finish();
}
return false;
}
}).show();
}
private void startGoLauncher(final String packageName,
final ComponentName componentName) {
mApplyTheme = true;
new AsyncTask<Void, Void, Boolean>() {
@Override
protected void onPreExecute() {
String msg = null;
String language = Locale.getDefault().getLanguage(); // zh
if(language.equals("zh"))
{
msg = "GOæ¡Œé�¢EXå�¯ç”¨ä¸ï¼Œè¯·ç¨�å�Ž";
}
else
{
msg = "Applying The Galaxy S3 Theme, Please Wait";
}
mProgressDialog = ProgressDialog.show(
classic.this,
null,
msg,
true);
}
@Override
protected Boolean doInBackground(Void... v) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
classic.this.finish();
try {
GoLauncherUtils.startGoLauncher(classic.this,
packageName, componentName);
} catch (Throwable e) {
return false;
}
return true;
}
protected void onPostExecute(Boolean success) {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
if (!success) {
String msg = null;
String language = Locale.getDefault().getLanguage();
// zh
if(language.equals("zh"))
{
msg = "GO桌��用失败,请�新安装GO桌�";
}
else
{
msg = "Start GO Launcher EX failed, please reinstall GO Launcher EX";
}
Toast.makeText(
classic.this,
msg,
Toast.LENGTH_LONG).show();
}
};
}.execute();
}
@Override
protected void onStop() {
super.onStop();
if (mApplyTheme) {
mApplyTheme = false;
ThemeUtils.sendApplyThemeBroadcast(this);
}
}
@Override
protected void onDestroy() {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
if (mConfirmDialog != null) {
mConfirmDialog.dismiss();
mConfirmDialog = null;
}
super.onDestroy();
}
}
GoLauncherUtils.java
import java.util.List;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
public class GoLauncherUtils {
public static final String NAME_GOLAUNCHER = "go_launcher";
public static final String KEY_UNINSTALLED = "uninstalled";
public static void startGoLauncher(Context context, String packageName,
ComponentName componentName) throws Throwable {
PackageManager packageMgr = context.getPackageManager();
Intent launchIntent = packageMgr.getLaunchIntentForPackage(packageName);
if (launchIntent != null) {
try {
context.startActivity(launchIntent);
} catch (Throwable t1) {
t1.printStackTrace();
if (componentName != null) {
Intent intent = new Intent(Intent.ACTION_MAIN);
//intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(componentName);
try {
context.startActivity(intent);
} catch (Throwable t2) {
t2.printStackTrace();
throw t2;
}
} else {
throw t1;
}
}
} else {
if (componentName != null) {
Intent intent = new Intent(Intent.ACTION_MAIN);
//intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(componentName);
try {
context.startActivity(intent);
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}
}
}
public static void downloadGoLauncher(Context context , final String aUrl) {
Intent intent = new Intent();
intent.setClass(context, GoDownloadService.class);
String fileName = "GO Launcher EX";
intent.putExtra("downloadFileName", fileName);
intent.putExtra(Constants.DOWNLOAD_URL_KEY, aUrl);
context.startService(intent);
}
public static Result isGoLauncherExist(Context context) {
Result result = new Result();
PackageManager pm = context.getPackageManager();
// Launcher
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.addCategory("android.intent.category.DEFAULT");
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
int launcherSz = infos.size();
for (int i = 0; i < launcherSz; i++) {
ResolveInfo info = infos.get(i);
if (null == info || null == info.activityInfo
|| null == info.activityInfo.packageName) {
continue;
}
String packageStr = info.activityInfo.packageName;
if (packageStr.contains(Constants.PACKAGE_LAUNCHER)) {
result.packageName = packageStr;
result.componentName = new ComponentName(packageStr,
info.activityInfo.name);
result.isExist = true;
return result;
}
}
return result;
}
public static boolean isGoLauncherRunning(Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
// for (RunningAppProcessInfo info : infos) {
// System.out.println("---------------running process: "
// + info.processName);
//
// if
// ("com.gau.go.launcherex".equals(info.importanceReasonComponent.getPackageName()))
// {
// goLauncherRunning = true;
// break;
// }
// }
List<RunningServiceInfo> infos = am.getRunningServices(500);
for (RunningServiceInfo info : infos) {
if (Constants.PACKAGE_LAUNCHER
.equals(info.service.getPackageName())) {
return true;
}
}
return false;
}
public static boolean isGoLauncherUninstalled(Context context) {
SharedPreferences sp = context.getSharedPreferences(NAME_GOLAUNCHER,
Context.MODE_PRIVATE);
return sp.getBoolean(KEY_UNINSTALLED, false);
}
public static void setGoLauncherUninstalled(Context context,
boolean uninstalled) {
SharedPreferences sp = context.getSharedPreferences(NAME_GOLAUNCHER,
Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putBoolean(KEY_UNINSTALLED, uninstalled);
editor.commit();
}
}
All i need help with is just disabling anything starting onstartup of the application, i only need this to be used when i send a intent over to it from a button click from another activity. please any help with find where i can disable this from the intial startup would be awesome.