Unable to start activity by using the package name - android

I am trying to use a library where I have to pass the action and the URI and to open the activity I have to use the package name but the thing is even I change the package name it is not working at all
this is the code that I am trying
Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse(filename));
intent.putExtra("was_get_content_intent", mWasGetContentIntent);
intent.setClassName("neelay.mediaplayer.beatbox.ringdroid", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
startActivityForResult(intent, REQUEST_CODE_EDIT);
and this is my manifest code for setting the activity
<activity
android:name=".ringdroid.RingdroidSelectActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
<activity
android:name=".ringdroid.RingdroidEditActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/edit_intent">
<action android:name="android.intent.action.EDIT" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
The package name is package="neelay.mediaplayer.beatbox"
I know it is easy to open the activity by just calling the names of the activity but in this case i have to pass the action with a uri and this is the only possible way i can see and guide will be helpful .

You said your package name (in the manifest) is "neelay.mediaplayer.beatbox". In that case you need to change this:
intent.setClassName("neelay.mediaplayer.beatbox.ringdroid", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
to this:
intent.setClassName("neelay.mediaplayer.beatbox", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
Since there are a number of ways to set the Component, you can also use any of the following methods:
intent.setClassName(this, "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
or like this:
intent.setClassName(getApplicationContext(), "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
or like this:
intent.setComponent(new ComponentName("neelay.mediaplayer.beatbox", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));
or like this:
intent.setComponent(new ComponentName(this, "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));
or like this:
intent.setComponent(new ComponentName(getApplicationContext(), "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));

Related

What type of Intent object required Query tag for package visibility in API 30 in Android?

I have a question regarding package visibility in Android 11. I read the oficial docs and also checked stack overflow question-answer. But I've few doubts. Please check the code below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.test">
<application
.....>
<activity
android:name=".TestActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<data
android:host="open"
android:scheme=“xxx” />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.xxx.com"
android:pathPrefix="/"
android:scheme="https" />
</intent-filter>
</activity>
<activity
android:name=".ABCActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
</application>
</manifest>
Doubt:
I tried and understood that <query> tag suggestion is coming only outside of <application> tag. Am I right?
If you see my code like this android.intent.category.BROWSABLE written inside particular TestActivity. Now If I'll move intent filter code outside of application tag, then how Android will understand that for which activity browsable is required?
There are multiple intent filter with BROWSABLE, so I need to declare query tag multiple times?
I saw that people uses intent tag inside query tag, and no one is using intent-filter. So is that fine?
Can I do one last request? Can someone please correct my code and post it in answer? I already reduced and added only required code according to my questions. Thanks in advance!
EDIT:
Usage 1:
upiIntent = Intent(Intent.ACTION_VIEW)
val pm: PackageManager = packageManager
val app: MutableList<ResolveInfo>? = pm.queryIntentActivities(upiIntent!!, 0)
Usage 2:
Intent intent = new Intent(Intent.ACTION_SEND, null);
intent.setType("text/plain");
private List<ResolveInfo> sharingAppList = new ArrayList<>();
PackageManager pManager = context.getPackageManager();
sharingAppList = pManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Usage 3:
mVersionName.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
The latest code in your question seems wrong, insofar as upiIntent needs more than an action string.
But, ignoring that, you would need a <queries> element like:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent>
</queries>
The first <intent> matches an ACTION_VIEW with no content; the second matches an ACTION_SEND with a MIME type of text/plain.

Adding multiple intent filters to MainActivity doesn't work?

I have MainAcitivty on which I am adding multiple intent-filters, with a purpose to open the MainActivity.
But the problem is that onNewIntent() is called but intent.action is always main, even when it should be VIEW_RICH_PUSH_MESSAGE. If I remove the second intent filter and add that to another new Activity, it will work for that Activity.
What I want is to define multiple intent filters for one Activity but I couldn't figure out the problem.
My manifest is defined as follows:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.urbanairship.VIEW_RICH_PUSH_MESSAGE" />
<data android:scheme="message"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
Any help is appreciated.

Action Intent causing a ActivityNotFoundException while starting another activity

My TestApp which launches the activity has the following code:
public void startOperaView() {
Intent browserIntent = new Intent("org.droidtv.nettvbrowser.VIEW");
Uri luri = Uri.parse("connectedplanet.tv/olvs/test");
//browserIntent.setClass(getApplicationContext(), Browser.class);
//browserIntent.setAction("org.droidtv.nettvbrowser.VIEW");
browserIntent.setType("application/vnd.droidtv.sta");
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
browserIntent.setData(luri);
startActivity(browserIntent);
}
And the package "org.droidtv.nettvbrowser" has the following AndroidManifest.xml file:
<activity
android:name="org.droidtv.nettvbrowser.Browser"
android:configChanges="locale"
android:label="#string/app_name" >
<intent-filter>
<action android:name="org.droidtv.nettvbrowser.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.droidtv.sta" />
</intent-filter>
</activity>
The weird part is that if I specify the actual package name in the intent it seems to work fine, Only the action intents are throwing these errors.Any help would be appreciated.Thank You.
Refer to http://developer.android.com/guide/topics/manifest/activity-element.html and you can try set android:exported="true"
android:exported
Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.
The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".
This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the permission attribute).
Or you can refer to something like this:
<activity android:name="OutgoingCallBroadcaster"
android:theme="#android:style/Theme.NoDisplay"
android:permission="android.permission.CALL_PHONE"
android:configChanges="orientation|screenSize|keyboardHidden">
<!-- CALL action intent filters, for the various ways
of initiating an outgoing call. -->
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter android:icon="#drawable/ic_launcher_sip_call">
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sip" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="voicemail" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/phone" />
<data android:mimeType="vnd.android.cursor.item/phone_v2" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter>
</activity>

Implicit intent from test application

I am new for implicit intent part of android.
In my application I have registered the intent like below:
<activity
android:name="ihpc.mocha.fakertt.view.MainActivity"
android:label="#string/app_name"
android:screenOrientation="reverseLandscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data
android:host="mocha"
android:path="/RTT/reset"
android:scheme="content" />
</intent-filter>
</activity>
<activity
android:name="ihpc.mocha.fakertt.view.SessionTimeOutActivity"
android:label="#string/app_name"
android:screenOrientation="reverseLandscape" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="mocha"
android:path="/RTT/sessionTimeOut"
android:scheme="content" />
</intent-filter>
</activity>
Now I want to trigger these intent from some test application but I do not know how to achieve that? I tried googling the same but could not find appropriate solution.Please suggest the way to do it.
your intent filter will catch all the intent with the "android.intent.action.VIEW" key. so if any application send an intent with this your application will receive. To test from another test application try this
intent = new Intent("android.intent.action.VIEW");
// if needed put some extra data
startActivity(intent);

Activity not found exception when clicking on the image

i am getting following error:
log is:
android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.VIEW
dat=android.resource://com.isummation.customgallery/2130837504 typ=image/* }
my code is as:
intent.setAction(Intent.ACTION_VIEW);
Uri hacked_uri = Uri.parse("android.resource://com.isummation.customgallery/" + R.drawable.a);
intent.setDataAndType(hacked_uri, "image/*");
startActivity(intent);
manifest.xml is as:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
any suggestion?
thanks
Try putting all actions/categories in the same intent filter, as opposed to the two different ones you currently have:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Also make sure you added the intent filter to the correct activity. For an example, check out the Note Pad example.
i can't see setName() in ur code . usually Activity not found means we set a name to intent but no Activity tag in menifest with this name exist . so please check

Categories

Resources