Hello friends there's a option in whatsapp through which we can change the background wallpaper of whatsapp chat. I am making a project in which i am giving so many wallpapers and i want to set the wallpaper from my wallpaper list
I used this code but the code is not working
Intent shareIntent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.mypackagename/"+R.drawable.image);
shareI
ntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));Intent = new
There are two thing you have to define for allow other application to call your application or request..
Define <intent-filter> in Mainfest.xml
Check for Intent at onCreate method..
Intent to host activity with Activity RESULT
If you want to share your image/text to other application on other call there are two way..
Share image your with host application on call
For this you have to use android.intent.action.SEND filter
Answer to host application for image request
For this you have to use android.intent.action.PICK filter
Manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/image1"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- share your image with host application -->
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<!-- answer to host application for image request -->
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
</application>
OnCreate in MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get intent from host activity
Intent intent = getIntent();
if(!intent.getAction().equals("android.intent.action.MAIN")){
// check about request
if (intent.getAction().equals("android.intent.action.PICK")) {
// return to activity with result OK and image selected image
Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri"));
setResult(Activity.RESULT_OK, result);
finish();
}
}
}
Related
I am developing app which have a downloading link which opens in mobile browser by clicking upon it but I want it to open in my webView in my app. My app is not web app I just want to open apps links in webview. I have hundreds of apps on my website. I am getting apps from wp api and like playstore the user can download apps from my application. I tried different solution but not succeeded. SS is attached to clerify my question. Need Help!!
Here is the screenShot attached.
First of all specify intent-filters to open link in app
<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="https"/>
<data android:scheme="http"/>
<data android:host="pollux.androidapksfree.com"/>
<data android:pathPrefix="/hdata"/>
</intent-filter>
Then handle it and pass to WebView in your launcher Activity.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//check that link is not null
//or that you opened app from deep link
if (getIntent() != null) {
Uri intentUri = getIntent().getData(); //get link
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(intentUri.toString()); //open it in webView
}
}
On clicking the link, Android OS will create an Intent with that link as URL and search for apps that can handle that intent.Since mobile browser can handle those "http://" intents , the intent is thrown to mobile browser and the link is opened there.
If you want to open it in your webView than you have to declare that your activity can handle these intents and have to make your activity default to handle these intents.
It can be done by following this link
https://developer.android.com/training/app-indexing/deep-linking.html
please note that if you have done this then any link with these domain clicked from anywhere will be opened only with your app as it is made default
For someone who is still struggling with this here is what worked for me
String defaultUrl = "myapp.com/home"
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.web);
webView.getSettings().setJavaScriptEnabled(true);
// Handle if the url from external app was clicked
Intent appLinkIntent = getIntent();
manageIntent(appLinkIntent, defaultUrl);
}
// override to get the new intent when this activity has an instance already running
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// again call the same method here with the new intent received
Log.e(TAG, "onNewIntent: URL called on new intent");
manageIntent(intent, defaultUrl);
}
public void manageIntent(Intent intent, String defaultUrl) {
String appLinkAction = intent.getAction();
Uri appLinkData = intent.getData();
if (appLinkData != null) {
webView.loadUrl(String.valueOf(appLinkData));
} else{
webView.loadUrl(defaultUrl);
}
}
and my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyTheme"
android:usesCleartextTraffic="true">
<!-- Splash Activity -->
<activity
android:name=".Splash"
android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity -->
<activity
android:name=".MainActivity"
android:launchMode="singleInstance"
android:exported="true" >
<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" />
<data android:scheme="https" />
<data android:host="example.myapp" />
<data android:host="www.example.myapp" />
</intent-filter>
</activity>
</application>
Because I was facing an issue app was opening under the title bar of other apps like browsers I needed to set android:launchMode="singleInstance" and then needed to override another method onNewIntent to handle singleInstance Launch mode
I want to open a specific file from another app with my app to handle it. For example, open a attached file in a mail from Gmail app.
With the following intent-filter setting, it works fine. When I open a file, MainActivity shows up and handles it irrespective of whether it is opened through another app or directly from my app. But I want the flow starting from SplashScreen Activity, in the event that the file is opened from another app. On the other hand, if app has been activated, activate directly MainActivity.
Does anyone know how to fix it??
AndroidManifest.xml
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<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:mimeType="*/*"
android:scheme="content" />
</intent-filter>
</activity>
You have to replace your activity from
to
<activity android:name=".SplashActivity">
And in SplashActivity get Action from Intent and then check if the Action is android.intent.action.VIEW Then Open your MainActivity and send your file from SplashActivity to MainActivity.
That's it
You can't change launcher activity from manifest file. You can set more than one <category android:name="android.intent.category.LAUNCHER"/> in intent-filter but You have to set a default activity.
But there is a way you can solve your problem...
Make a launcher activity with No UI and open the activity with condition in onCreate method.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent;
if (condition) {
intent = new Intent(this, ClassA.class);
} else {
intent = new Intent(this, ClassB.class);
}
startActivity(intent);
finish();
}
OR
In your splash activity write condition before setContentView method.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent;
if (condition) {
setContentView();
} else {
intent = new Intent(this, ClassB.class);
startActivity(intent);
finish();
}
}
Hope this will help you.
I have two apps. From the first, I want to launch the second one by deep linking. It works but the problem is that the second one starts inside the first one. I would like to start the second one in a new instance.
The code of the first app to open the second app:
String uri = "deeplinkTestTom://token/123456";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
The manifest of the second app:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:scheme="deeplinkTestTom" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
When I try to launch Facebook app from my first app (String uri = "facebook://facebook.com/inbox";), it launch facebook in a new app and not inside my first app. So I suppose that something is missig in the manifest of my second app, but I can't find what.
What should I do ?
I believe you're talking about new Task instead of "new app".
Read Tasks and Back Stack
You need to use Intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) to start an Activity in a new Task.
For your case, use
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I would like to start MyBrowser, an application that show web pages like the built-in Browser app, from another application, IntentsLab.
I followed Launch custom android application from android browser to setup the intent, and also the official Intent and Intent-filters guide which does says "You need to include CATEGORY_DEFAULT to receive implicit intents".
So my intent-filter is so written:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.categroy.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
The code of the parent activity in IntentsLab to start the new activity is:
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
String title = "Use Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
if(chooserIntent != null) startActivity(chooserIntent);
The MyBrowser application does not show up on the chooser dialog. However, when I created an Activity inside the IntentsLab and added to it a same intent-filter, this activity shows up in the chooser dialog. Is there anything wrong with the code? Or is there any difference between implicit intent towards Activities in a same Application with those in a different one?
Provided my AndroidManifest.xml for the MyBrowserActivity. It works perfectly for me. Even I am doing the coursera Android programming class :)
<activity android:name=".MyBrowserActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
</activity>
I have created an Intent filter to open my application when clicking on an specified link such as "http://www.myapp.com/1234". When I click on the link I am asked to open the app, and OK, everything works well. Then, I quit from the app by clicking repeatedly in the back button until all activities are closed. But:
After launching the app again from the launcher, it receives the same Intent data than
before when I clicked the link. How do avoid it?
When I open my app from a link, ie. from WhatsApp, as I can see in the app manager, WhatsApp is the application which is opened! why?
Here is my current manifest code:
<activity
android:name="com.x.y.SplashActivity"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<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" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="#string/app_host"
android:pathPrefix="/events/"
android:scheme="http" />
</intent-filter>
</activity>
and in my onCreate():
// Retrieve the Intent
Intent intentUri = getIntent();
// Check URI
Uri uri = intentUri.getData();
if (uri != null) {
// Try to extract the data
// For now, data could be a public event id, so parse it
List<String> pathSegments = uri.getPathSegments();
// Check validity
if (pathSegments.size() > 2) {
// Finally, get the public event id
String publicEventId = pathSegments.get(2);
// Set poll as responded
user.setPollEventId(publicEventId);
}
// Remove the intent to prevent further calls
setIntent(null);
}
// Open the main activity normally
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);