I am trying to capture audio/* mimetype action.View intents and forward them to another application (chosen by the user). The problem is that, while I am able, from a file manager, to select my Activity on file opening (through the app chosen dialog), I am not able to forward the intent to another activity (not the same one).
This is the manifest part about the activity:
<activity
android:label="#string/app_name"
android:name=".TestMimeActivity" >
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="audio/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is the onStart code in the activity:
#Override
protected void onStart() {
super.onStart();
setContentView(R.layout.main);
Intent intent = getIntent();
startActivity(intent);
}
I obtain only an infinite loop. I would like to open on the activity che app chosen dialog (preferably without my app listed but I can also tolerate the whole list). Is it possible? How can I achieve this?
Thanks
Tobia Loschiavo
From your comments above I think you are looking for createChooser. You should modify your code to look like this:
Intent intent = getIntent();
startActivity(Intent.createChooser(intent, "Select application"));
Related
I have two Android applications.
The first application is the "browser". It gets an URL and displays it in a WebView. The corresponding activity is declared as:
<activity android:name=".MainActivity">
<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.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
The second application has a few buttons. Tapping each button opens the first application and sends the URL to it using Intent.ACTION_VIEW:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(urlString);
intent.setData(uri);
intent.setComponent(new ComponentName("com.custom.browser", "com.custom.browser.MainActivity"));
startActivity(intent);
I expect this code to start a new activity as per https://developer.android.com/reference/android/app/Activity. So the browser application retrieves the URL in onCreate() by using the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
...
Intent intent = getIntent();
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
displayUrl(intent.getDataString());
}
...
}
However I found that sometimes onCreate() is not called. After calling startActivity(intent), the browser application is just brought to the front, therefore displaying a previous URL.
I can override this behavior by moving the intent retrieval code in the onResume().
However I'd like to understand what am I doing wrong? Shouldn't the method startActivity(Intent) always start a new activity and always call onCreate(), as suggested by the Android documentation?
I expect this code to start a new activity
That is not necessarily what will happen.
However I found that sometimes onCreate() is not called. After calling startActivity(intent), the browser application is just brought to the front,
Yes, that will happen if the activity you are starting is already running at the front of a task. See the documentation for tasks.
I can override this behavior by moving the intent retrieval code in the onResume().
That will not work. Override onNewIntent() and get the new Intent there. Or, adjust the flags in your Intent, or adjust the manifest settings for the activity that you are starting, as is discussed in the documentation for tasks.
I want to achieve "launch App from web" and I have 2 ready-to-use links in my webpage. Opening either of the links did call the activity SchemeRedirectActivity and get the correct intent. The problem is when I store(don't close) the links in phone browser separately and:
open one link from browser > press Recent Apps key(e.g.the right hardware key on device) > open another link,
getIntent() always gives me the old intent except the first time opening each link.
Manifest:
<activity
android:name=".SchemeRedirectActivity"
android:screenOrientation="sensorPortrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
SchemeRedirectActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = getIntent(); //always got the old intent here
Uri data = intent.getData();
}
The solutions from internet don't work for my case, even if I add android:launchMode="singleTask" / "singleTop" to manifest file, my onNewIntent() is never launched:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("intent", "onNewIntent "); //never launched
Uri data = intent.getData();
}
What is wrong with the process and how can I fix it please?
*Sorry if my question is not clear, thanks.
I am developing two android applications:
the first is a normal application with a launcher and so on
the other is a application only with a viewer activity (see the manifest):
<activity
android:name=".MyActivity"
android:icon="#drawable/icon"
android:label="#string/dropbox" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask" >
<intent-filter>
<data android:scheme="db-XXXXX" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The plan is, that the first application does not need internet permissions and the second is some kind of add-on to the first.
The second application should sync a file with Dropbox (with the Core API, not with the Sync API).
From my first app, I start 'MyActivity' from the second app like this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("my.package","my.package.MyActivity"));
intent.putExtra("filePath", "/myFile.txt");
startActivityForResult(intent, SYNC_REQUEST);
That works. The Activity comes up and there, if not authorized yet, the user must press a button. Then the following code will be executed
AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);
mApi.getSession().startAuthentication(MyActivity.this);
If the user does not have dropbox installed, the browser will pop up.
Now my troubles begin:
As soon as the user presses 'Accept' or 'Decline', the browser does not disappear. It stays open and MyActivity does not get resumed (onResume is not called!).
I found out, that adding
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
before starting MyActivity from my first application will solve the problem, but then I can not listen/wait for the result of MyActivity.
I am frustrated. Can anyone help me or give me some advise?
Thanks!
When you are using startAuthentication method. It will automatically start the AuthActivity. you do not need to call startActivity() explicitly. Then in onResume method of your activity write this code :
#Override
protected void onResume()
{
super.onResume();
if (if dropBoxAPI!= null && dropboxAPI.getSession().authenticationSuccessful())
{
try {
dropboxAPI.getSession().finishAuthentication();
oAuth2Token = dropboxAPI.getSession().getOAuth2AccessToken();
}
catch (IllegalStateException ie)
{
ie.printStackTrace();
}
}
}
I have an intent filter that looks like so:
<activity
android:name="com.test.Call"
android:label="#string/makeCall" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
</activity>
This works fine and when you try to make a call my text appears as one of the options. What I want to do is process the number being called and ask the user some questions and then continue on with the call. I do this by running the following code after I do whatever processing I have do do:
Uri phoneCall = Uri.parse("tel:" + numToCall);
Intent caller = new Intent(Intent.ACTION_DIAL, phoneCall);
startActivity(caller);
The issue is, it is displaying the same options from the beginning again (the native caller and my intent filter). This is not what I want, I want to bypass my intent filter and go directly to the native caller. Is there a way to do this? How can I force the intent to go directly to the native caller? I am looking at moving this to a broadcast receiver but would rather go this route.
Thanks
You could try disabling your component via PackageManager.setComponentEnabledSetting() [use the DONT_KILL_APP flags!], but you'll need to re-enable the component again before the next call.
Or you could take Huang's comment above but find out components that catch the ACTION_CALL intent and build your own chooser if there's more than one other than you - use PackageManager.queryIntentActivities() to get a list of Activities.
Using the broadcast is really the right way to go.
i'm trying to do something that is described briefly on the next link:
link
meaning, i have an activity that can be even on another application (but for now let's focus on an activity that my app has) , which i want to be able to create a shortcut to it.
for terminology , let's say that the activity that creates the shortcut is named "ShortcutCreatorActivity" ,and the activity that gets started is "MyActivity" .
what i got from what is written is that the ShortcutCreatorActivity should be defined in the manifest as:
<activity android:icon="#drawable/ic_launcher"
android:label="ShortcutActivity" android:name="com.my_app.ShortcutCreatorActivity">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and what i got in its java code is:
public class ShortcutCreatorActivity extends Activity
{
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final Intent shortcutIntent=new Intent("com.my_app.MyActivity");
final ShortcutIconResource iconResource=Intent.ShortcutIconResource.fromContext(this,R.drawable.ic_launcher);
final Intent intent=new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"Shortcut Test");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
setResult(RESULT_OK,intent);
Toast.makeText(this,"shortcut created",Toast.LENGTH_SHORT).show();
finish();
}
}
yet i keep getting the same message of "application not found" when clicking on the shortcut , and the log :
ActivityManager(232): Starting: Intent { act=com.my_app.MyActivity flg=0x10200000 bnds=[80,150][160,250] } from pid 3956
can anyone please help me? what is missing?
i've also tried some intent filters for the MyActivity activity inside the manifest. nothing helped...
#liro
i don't think it matters , since i've specified the exact full path to the class , including the package name.
everyone, please, if you have a working project, that would be perfect .
Not sure here, but I think you need to remove the "com" from "com.MyActivity."
<activity android:icon="#drawable/ic_launcher"
android:label="ShortcutActivity" android:name=".ShortcutCreatorActivity">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Instead of
final Intent shortcutIntent=new Intent("com.my_app.MyActivity");
try
final Intent shortcutIntent=new Intent(this, com.my_app.MyActivity.class);
or define your action in intent-filter of that activity, which I believe you may did not.
Those two links may be helpful:
http://developer.android.com/reference/android/content/Intent.html#Intent(java.lang.String)
http://developer.android.com/guide/topics/manifest/action-element.html