Reputation: 130
I know that we can open a browser activity with implicit intent:
<activity ...>
<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" />
</intent-filter>
</activity>
But now I want to open a browser service to load webpages in background when we click links, so I just do like this:
<service ...>
<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" />
</intent-filter>
</service>
But it is not work, the app chooser do not appear and the browser service not running.
From the Intent | Android Developers it saids "android.intent.action.VIEW" is a Activity Action, that's mains I can't use it with Service?
Or is there any idea to start a browser service with implicit intent?
Upvotes: 1
Views: 746
Reputation: 130
After days of thinking I found a "hack way" to implement this solution.
Just set activity's theme to android:theme="@android:style/Theme.NoDisplay"
, when an implicit intent arrive the activity start, we just do somethings in it's onCreate()
such as startService()
and then just finish()
this activity.
The whole process run very fast and has good experience, looks awesome :)
Upvotes: 1
Reputation: 47
Intent imintent=new Intent(Intent.ACTION_VIEW,Uri.parse("http:\www.google.com"));
try
{
startActivity(imintent);
} catch(ActivityNotFoundException a)
{ }
You can use this code for start browser activity implicitly . not any changes required in Androidmanifeast file.
Upvotes: 0
Reputation: 93561
Yes, an activity action must be an activity. Also, you should not use intent filters with services. Its possible but its highly, highly discouraged. From the docs
"Caution: To ensure your app is secure, always use an explicit intent when starting a Service and do not declare intent filters for your services. Using an implicit intent to start a service is a security hazard because you cannot be certain what service will respond to the intent, and the user cannot see which service starts. Beginning with Android 5.0 (API level 21), the system throws an exception if you call bindService() with an implicit intent."
Upvotes: 0