I have created a browser application with below code,
AndroidManifest.xml
<activity
android:name=".CustomBrowserActivity">
<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.VIEW" />
<data android:scheme="http" android:host="www.google.com" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Now I have another application which tries to open google home page http://www.google.com
Intent intentToOpen = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Intent chooserIntent = Intent.createChooser(intentToOpen, "Load http://www.google.com with: ");
Now, whenever above code is executed, default browser is opened, rather than my custom browser.
Any help would be appreciated.
Related
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.
I know this question is not new, but its a bit different from already asked questions. I have a website that provides links to my app. The links direct users to specific data on my app. This is the layout of my app: I have 4 activities as Activity1.class, Activity2.class, Activity3.class, and of course the MainActivity.class which is the launcher activity.
My worry is this: On my website, I have 3 buttons: button 1 goes to open directly Activity1 on my app (assuming the app is already installed on the device), Button 2 on website opens Activity2 in my app.
Note: the app and the website are not by any means linked.
My question is: how to get a URL link to specific activity on my app. I need 3 URLs that open different 3 activities. I need these links for external use, such that they open a specified activity whey clicked.
Something like: http://myapppackage/ACTIVITY1.
This is just an example.
In you AndroidManifest.xml add intent-filters to the activities like this
<activity android:name=".ACTIVITY1">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="myapppackage"
android:pathPattern="/ACTIVITY1" />
</intent-filter>
</activity>
<activity android:name=".ACTIVITY2">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="myapppackage"
android:pathPattern="/ACTIVITY2" />
</intent-filter>
</activity>
<activity android:name=".ACTIVITY3">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="myapppackage"
android:pathPattern="/ACTIVITY3" />
</intent-filter>
</activity>
For more info check this out
Deep Linking In Android
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
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.
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.