Adding 3rd party application into Settings.apk - java

Recently I'm building a AOSP ROM from source. What I wanted to do is, add a 3rd party application into Settings app and It should be launched only from Settings and it should be invisible from Launcher.
Here's what I did, It fails everytime.
Removed these lines from apps AndroidManifest.xml
android:name="android.intent.category.LAUNCHER" />
and added below lines in SettingsActivity.java from Settings app.
if (KA_FRAGMENT.equals(fragmentName)) {
Intent kaIntent = new Intent();
kaIntent.setClassName("com.cyborg.manager", "com.cyborg.manager.activities.MainActivity");
startActivity(kaIntent);
finish();
return null;
}
Also added below lines in AndroidManifest.xml of Settings
<activity android:name="Settings$KActivity"
android:label="#string/hit_perform"
android:icon="#drawable/hit_performance_icon"
android:taskAffinity="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.urom" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.ka" />
</activity>
Although, it works fine when 3rd party app is visible in launcher

If you want to play with custom ROM I'd recommend getting familiar with Android fundamentals first.
What makes you activity shown by launcher is this <intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
especially these two lines:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
so remove them and you are done.

Related

How to add a Login Page/Activity to a Pre-Existing Main Activity? [duplicate]

I have created the meat and guts of my application but I want to add a different activity that will be the starting point (sort of a log-in screen).
Couple questions:
1 I have a fairly decent handle on how to switch between activities (based on this article: http://www.linux-mag.com/id/7498) but I'm not sure how to go about creating a new one (with eclipse).
2 Once I have a new activity created, how can I set it as the default activity of my application? I presume I could just change the name of the classes...but is there a more elegant way to handle that (maybe within the AndroidManifest.xml)?
Yes, you use the AndroidManifest.xml file. You can actually even have more than one launcher activity specified in your application manifest. To make an activity seen on the launcher you add these attributes to your activity in the manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Go to AndroidManifest.xml in the root folder of your project and change the Activity name which you want to execute first.
Example:
<activity android:name=".put your started activity name here"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
If you are using Android Studio and you might have previously selected another Activity to launch.
Click on Run > Edit configuration and then make sure that Launch default Activity is selected.
<application
android:icon="#drawable/YOUR_ICON" <!-- THIS ICON(IMAGE) WILL BE SHOWN IN YOUR APPS -->
android:label="MY APP NAME " > <!-- HERE LABEL(APP NAME) -->
<activity
android:name=".application's starting activity" <!-- (.)dot means current dir, if your activity is in another package then give full package name ex: com.xxx.Activity -->
android:label="LABEL FOR ACTIVITY "
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Follow to below instructions:
1:) Open your AndroidManifest.xml file.
2:) Go to the activity code which you want to make your main activity like below.
such as i want to make SplashScreen as main activity
<activity
android:name=".SplashScreen"
android:screenOrientation="sensorPortrait"
android:label="City Retails">
</activity>
3:) Now copy the below code in between activity tags same as:
<activity
android:name=".SplashScreen"
android:screenOrientation="sensorPortrait"
android:label="City Retails">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and also check that newly added lines are not attached with other activity tags.
This is easy to fix.
Changes to the Launcher activity are also stored in the Debug configuration.
Go to Run > Debug Configurations and edit the setting.
There is also a similar setting in Intellij under Run > Edit Configurations select Run default Activity and it will no longer save the setting in this fashion.
It's simple. Do this, in your Manifest file.
<activity
android:name="Your app name"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Just go to your AndroidManifest.xml file and add like below
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
then save and run your android project.
You add this you want to launch activity
android:exported="true" in manifest file like
<activity
android:name=".activities.activity.MainActivity"
android:windowSoftInputMode="adjustPan"
android:exported="true"/>
<activity
Open java file of this activity and right click then click on Run 'main Activity'
OR
Open java file of this activity and press Ctrl+Shift+F10.
In a recent project I changed the default activity in AndroidManifest.xml with:
<activity android:name=".MyAppRuntimePermissions">
</activity>
<activity android:name=".MyAppDisplay">
<intent-filter>
<action android:name="android.intent.activity.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In Android Studio 3.6; this seems to broken. I've used this technique in example applications, but when I use it in this real-world application it falls flat. The IDE once again reports:
Error running app: Default activity not found.
The IDE still showed a configuration error in the "run app" space in the toolbar (yellow arrow in this screenshot)
To correct this error I've tried several rebuilds of the project, and finally File >> "Invalidate Cache/Restart". This did not help. To run the application I had to "Edit Configurations" and point at the specific activity instead of the default activity:
In AndroidManifest.xml
I changed here the first activity to be MainActivity4 instead of MainActivity:
Before:
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2" />
<activity android:name=".MainActivity3" />
<activity android:name=".MainActivity4" />
<activity android:name=".MainActivity5" />
<activity android:name=".MainActivity6"/>
After:
<activity android:name=".MainActivity" />
<activity android:name=".MainActivity2" />
<activity android:name=".MainActivity3" />
<activity android:name=".MainActivity4" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity5" />
<activity android:name=".MainActivity6"/>
For anyone getting errors in their debug\AndroidManifest.xml file make sure that you include the tag!
"<activity android:name=".MainActivity>"
For example:
<activity android:name=".MainActivity"><intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter></activity>

How to show App icon in ACTION_SEND intent - android

I want the app icon to be shown when sharing my app inside my app. When clicking the Share the App button in my App. It works but instead of my icon, it shows some other icon.
It shows like Below
Here's the code I used:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, " Knowledge");
String shareMessage= "\n Download now for free !\n\n";
shareMessage = shareMessage + "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID +"\n\n";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
context.startActivity(Intent.createChooser(shareIntent, "choose one"));
How can I set my icon in here? Please help me with some solution
Congratulations guys, you waited for this :)
In some cases you need to add several Intent filters:
<activity
android:name=".activity.FeedActivity"
android:exported="true"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
And be sure you add the android:exported="true" tag otherwise you app won't appear in other share intents.

Open Application in App Link outside of receiver

When using App Links, the receiver app (EX. Whatsapp) is paused, and your application's activity is opened on top of the receiver app.
For example, if you open your link from a WhatsApp's chat page, the new activity isn't opened from your app (The WhatsApp's task in recent apps includes your app), while your app isn't in the recent task.
But what if I want to open my application in a new task? Separate from the receiver app?
This is my Manifest file of the activity opened from the App Link:
<activity
android:name=".Activitys.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter
android:autoVerify="true"
android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="eventtk.uae-dc.com"
android:pathPrefix="/product/"
android:scheme="https" />
</intent-filter>
</activity>
Is there a thing I should add to the IntentFilter?
Not sure if I understood correctly what you would like to achieve, but you can try
to add
android:launchMode="singleTask"
to your activity definition.
More information here:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en

Figuring out the launcher on this Android Studio Github project

Still a little bit new to Android studio and app development. On this project: https://github.com/watabou/pixel-dungeon, which file is acting as the MainActivity.java file? As in, which file is the main launcher of the application, how do you tell?
The activity with the intent filters android.intent.action.MAIN and android.intent.category.LAUNCHER is the launcher for any app,
Just check which activity it has bellow intent filter that is launcher,
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In that project PixelDungeon is the launcher activity.
Your launcher activity is defined in your android manifest (AndroidManifest.xml), it should look like this:
<activity
android:name=".activity.Login_screen"
android:label="Activity Validation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For your case, if you want to edit your launcher activity just change ".activity.Login_screen" for the activity you want to display on launch. However, make sure that there are no duplicate definitions.
As you can see in your code:
<activity
android:label="#string/app_name"
android:name=".PixelDungeon"
android:screenOrientation="portrait">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android add my app to "Share" button in gallery

I succeed to add my app in the "share" button in the Android gallery, so if I click on it, my app will start. Can I choose which activity of my app to start?
Now it starts the "main" one. Here's my code in the main class:
.....
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
// Get resource path
}
}
And the manifest:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
In reality I succeed in opening a new activity immediately after the "main" starts but I'll prefer to directly open the right one.
Thanks
Put your intent filter under activity you want to start into your manifest
<activity android:name=".Theme"
android:label="MAIN">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Theme"
android:label="ActiVITY2">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
If you had two activities in your manifest file, say Main and MediaShare then it would look something like this:
<activity android:name="Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="MediaShare" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
The android.intent.action.SEND action and android:mimeType="image/*" data should go with the activity you want to start when you share an image.
See the page on Receiving Content from Other Apps for more details.

Categories

Resources