I'm using intent filter for catching a custom scheme for my app:
<activity
android:name=".activities.MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/title_my_activity"
android:launchMode="singleTop"
android:noHistory="true"
android:screenOrientation="portrait">
<!-- myapp://app.open -->
<intent-filter android:label="#string/my_intent">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
<data android:host="app" />
<data android:host="app.open" />
</intent-filter>
</activity>
In my activity I override:
#Override
protected void onNewIntent(Intent intent) {
Log.d("DEBUG", "New intent!");
super.onNewIntent(intent);
}
but this is never called...where am I wrong?
Is noHistory flag necessary? If I remove that, I've two copies of the same activity on the stack.
Below code is working fine for me
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
<data android:host="app" />
<data android:host="app.open" />
</intent-filter>
</activity>
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("DEBUG", "New intent!");
}}
Related
I have 2 activities - MainActivity and DeepLinkActivity. MainActivity generates a link. When I click on the DeepLink from an sms, I expect the DeepLinkActivity to open however the MainActivity always opens.
Manifest file is as follows:
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DeepLinkActivity"
android:label="#string/app_name"
android:theme="#style/ThemeOverlay.MyDialogActivity">
<!-- [START deep_link_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="blessd.mobi" android:scheme="http"/>
<data android:host="blessd.mobi" android:scheme="https"/>
</intent-filter>
<!-- [END deep_link_filter] -->
</activity>
Snippet of both activities
MainActivity
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_referral);
//long
String link = "http://www.blessd.mobi";
DynamicLink m = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))....
DeepLinkActivity
public class DeepLinkActivity extends AppCompatActivity implements
View.OnClickListener {
private static final String TAG = DeepLinkActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.deep_link_activity);
Log.d(TAG,"Deep Activity" );
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}...
Thanks
In your manifest activity, you must have 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="yourlinkhost.com"
android:scheme="http" />
<data
android:host="yourlinkhost.com"
android:scheme="https" />
</intent-filter>
And it should handle your links. Maby your links have wrong host scheme - I had such problem when my link had wrong host. But the solution you have - seems good and the same I had worked well for me.
You must add the additional data on your intent filters.
<data
android:host=""
android:path=""
android:scheme="" />
And you must have set that data while you were creating share intent.
builder.scheme(getString(R.string.config_scheme)) // "http"
.authority("your url") // your host
.appendPath(getString(R.string.path)) // "your path"
.appendQueryParameter(QUERY_PARAM, data)
<activity android:name=".XActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:noHistory="true"
android:launchMode="singleTask" >
<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="x.lv" />
<data android:scheme="http" android:host="www.x.lv" />
<data android:scheme="https" android:host="m.x.lv" />
</intent-filter>
</activity>
AND
public class XActivity extends Activity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent(); [Debugger break-point]
if (intent == null || intent.getData() == null) {
finish();
}
}
}
Well, I do get till the part when my application is start from deep-link if app is running in the background. If I close my app and then click on deep-link, then app opens but I dont hit onCreate method with debugger. Why is so? I thought it should work the same even if app is offline/turned off.
I am facing problem to work with VoiceInteractor. Here it my Manifest part:
<activity android:name=".ProductSearchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
And in the Activity,
#Override
public void onResume() {
super.onResume();
if (isVoiceInteraction()) {
getVoiceInteractor().submitRequest(new VoiceInteractor.PickOptionRequest(prompt, optionArr, null) {
#Override
public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
if (finished && selections.length == 1) {
showResult(selections[0].getIndex());
}
}
#Override
public void onCancel() {
getActivity().finish();
}
});
}
}
Whenever I am starting my app using "OK Google, search Jackets on MYCART", it starts the application, but isVoiceInteraction() is always returning false and getVoiceInteractor() is always returning null even if I am starting the app by google search. Can anyone help me on that?
I am using android studio and playing around with CsipSimple. I am trying to figure out the flow for an outgoing call.
There is a method called Place call, which triggers the intent that handles the action ACTION_CALL for the scheme csip
#Override
public void placeCall(String number, Long accId) {
if(!TextUtils.isEmpty(number)) {
Intent it = new Intent(Intent.ACTION_CALL);
it.setData(SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, SipUri.getCanonicalSipContact(number, false)));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if(accId != null) {
it.putExtra(SipProfile.FIELD_ACC_ID, accId);
}
getActivity().startActivity(it);
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
resetInternals();
}
Here is the declaration of activity in the manifest, that handles the action
<activity
android:name="com.freemobile.ui.outgoingcall.OutgoingCallChooser"
android:allowTaskReparenting="false"
android:configChanges="orientation"
android:excludeFromRecents="true"
android:label="#string/call"
android:launchMode="singleTask"
android:permission="android.permission.USE_FREEMOBILE_SIP"
android:process=":sipStack"
android:taskAffinity=""
android:theme="#style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="android.phone.extra.NEW_CALL_INTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
</activity>
I have put a debug point in the onCreate method of the activity OutgoingCallChooser. But it never comes there. Please help me. am i missing something obvious?
You should override onNewIntent in your activity:
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
//Do something
}
More information here:
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
I am struggling with the following strange behavior of SingleTop activities.
I have defined some intent filters in that activity:
<activity android:name="com.example.DashboardActivity"
android:screenOrientation="landscape"
android:launchMode="singleTop"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="video" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.EDIT" />
<data android:scheme="survey" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<data android:scheme="call" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This code should start the activity:
webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
} catch(ActivityNotFoundException e) {
Log.e(TAG,"Could not load url"+url);
}
return super.shouldOverrideUrlLoading(view, url);
}
});
in the onResume of the DashboardActivity I check for the according action:
public void onResume(){
super.onResume();
Fragment fragment = null;
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
extras.putParcelable("uri", getIntent().getData());
fragment = new VideoplayerFragment();
} else {
fragment = new DashboardFragment();
}
addOrReplaceFragment(fragment, extras);
}
But when I run this code, I always get the android.intent.action.MAIN action. If I remove the singleTop launch mode, it launches a new activity, but passes the correct intent. I have to use the same instance of the activity, so singleTop, singleTask or singleInstance must do the job. But I don't know what's going wrong here. HELP!
Intent.ACTION_VIEW.equals(intent.getAction())
Where is this intent coming from? In order to catch the new Intent you must use
onNewIntent().