Implicit intent doesn't work with my app - java

I have two applications, the first one send an implicit intent to view a link and the second one named "MyBrowser" receives it. But when I install both apps on my phone (API level 23), the app chooser only display the Internet (default application for web viewing). If I use the AVD (API level 25), app chooser includes also "MyBrowser". Here is my first application's function:
private void startImplicitActivation() {
Log.i(TAG, "Entered startImplicitActivation()");
// Create a base intent for viewing a URL
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
// Create a chooser intent, for choosing which Activity
// will carry out the baseIntent
Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);
// Verify the intent will resolve to at least one activity
if (baseIntent.resolveActivity(getPackageManager()) != null) {
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
// Start the chooser Activity, using the chooser intent
startActivity(chooserIntent);
}
And "MyBrowser" Manifest.xml:
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyBrowserActivity"
android:label="#string/app_name" >
<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:scheme="http" />
</intent-filter>
</activity>
</application>
I am newbie in android and can't understand why. Please explain to me. Thank you.

Related

activity is creates twice for no apparent reason

I am writing an application running on my custom device (marshmallow based). the general idea is to prompt a user dialog to enter some information at boot and send it to my server. once the information is successfully sent I update the shared preferences that the information was sent and the dialog will not be prompt anymore.
as always I check to see if the needed permissions are present (read phone state for IMEI and sim info), if not I create an activity that requests permissions and on result starts the user dialog activity. if permissions already exist I create the dialog activity straight from the boot receiver.
however, for some reason, sometimes the permissions activity is created twice (I made sure the boot receiver is only triggered once). this causes as expected the user dialog to be shown twice for no reason. does anyone know how can I solve this? thank you.
here is a code snippet for the boot receiver (the only place where the permissions activity is started).
public class BootReceiver extends BroadcastReceiver {
SharedPreferences mPrefs;
boolean wasUpdated;
#Override
public void onReceive(Context context, Intent intent) {
Log.v("car_num", "got boot receiver");
mPrefs = context.getSharedPreferences("car_num", MODE_PRIVATE);
wasUpdated = mPrefs.getBoolean("is_num_updated", false);
if (!wasUpdated) {
Log.v("car_num", "first time - asking for car num");
if (UtilityFunctions.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
Log.v("car_num", "we have permission lets ask for car num");
Intent i = new Intent();
i.setClassName("com.mgroup.carnumberapp", "com.mgroup.carnumberapp.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Log.v("car_num", "main activity started");
} else {
Log.v("car_num", "no permission - so requesting");
Intent i = new Intent();
i.setClassName("com.mgroup.carnumberapp", "com.mgroup.carnumberapp.PermissionActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("from", "boot receiver");
context.startActivity(i);
}
} else {
Log.v("car_num", "car number already updated - doing nothing");
}
}
}
edit:
I tried adding
android:launchMode = "singleTop"
however, it happened again.
here is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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/MGServiceTheme">
<service
android:name=".SendDetailsService"
android:enabled="true"
android:exported="true"></service>
<activity android:name=".PermissionActivity"
android:launchMode = "singleTop"/>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN"
android:theme="#style/Theme.AppCompat.NoActionBar" />
</intent-filter>
</activity>
</application>
In your manifest do android:launchMode="singleTop" for an activity
like
<activity android:name=".MapActivity"
android:launchMode="singleTop"/>
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android Studio Layout is not Responding

I recently have added a layout and a java file connecting it to my java code file which is taking and giving actual output by implementing an algorithm but the second layout when opened in my phone it does not react to any of the two buttons clicked on it.
Seems like an error in AndroidManifest file.
here is Manifest file code,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationgeneric">
<application
android:allowBackup="true"
android:label="#string/app_name2"
android:icon="#mipmap/jug_black_trasnparent"
android:roundIcon="#mipmap/jug_black_trasnparent"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Next"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".connectorclass">
<intent-filter>
<action android:name="android.intent.action.ANSWER"/>
<category android:name="android.intent.category.Calculator"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
here connectorclass.java is linked to the Layout not Responding named something xyz..
Just remove the intent filter for "connectorclass".
In AndroidManifest.xml file, you provide two intent files. That doesn't need it. Always try to add one intent-filter on your activity and this activity is your lancer activity. So remove the second intent-filter from connectorclass activity.
Then add below code on your button onClickListener
Intent intent = new Intent(MainActivity.class, connectorclass.class);
startActivity(intent);
you can remove
<intent-filter>
<action android:name="android.intent.action.ANSWER"/>
<category android:name="android.intent.category.Calculator"/>
</intent-filter>
in android manifest and can start activity using class name by default
like this
Intent intent = new Intent(this, connectorclass.class);
startActivity(intent);
try this

how can I launch a first time installation project?

I have an android project for first time installation.
It is related with my firm agreement pages. It comes after google agreement pages.
I tried some technics for doing it. For example,I set it as a system application. However, it is cleaned when backup and reset operation.
Does anybody know how to run it?
on AndroidManifest.xml
<application
android:theme="#android:style/Theme.NoTitleBar"
android:allowBackup="true"
android:icon="#drawable/launcher"
android:label="#string/appname" >
<activity
android:name="xxxagreement.MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter android:priority="3">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
on MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onResume() {
Intent i = new Intent();
i.setAction(AGREEGATE_STARTED);
sendBroadcast(i);
TextView t = (TextView)findViewById(R.id.textView1);
t.setSelected(true);
...
super.onResume();
}
Event Log prints:
Session 'app': Error Launching activity
Your application doesn't have any launcher activity. Replace these lines
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
with
<category android:name="android.intent.category.LAUNCHER" />

Linking Activities Using Intents (Android Beginner)

I'm beginning to learn Android and have been reading the "Beginning Android 4 Application Development." (As well as downloading the relevant source code)..
However; I have been trying to create a very simple slideshow with a button labelled "Gallery" which will take me to a new Activity that will show a grid like layout for my photos. However, my application does not do this. When the button is pressed it either crashes the app or refuses to do anything at all.
Manifest
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<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" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Viwer"
android:name=".Viwer" >
<intent-filter >
<action android:name="com.example.viwer.Gallery" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Any help would be greatly appreciated, I assume it's something simple but after looking at it for three hours I can't see what it is.
You need to add the Gallery activity to the Android Manifest
<activity
android:name=".Gallery"
android:label="Gallery"></activity>
In your manifest you register viewer activity in an intent-filter yet is not declare as a broadcast receiver.
Second event if it was a broadcast receiver it will never launch as you do not send any broadcast by calling startActivity
i think that what your trying to achieve is this:
Please try this:
ebutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Viwer.calss )
startActivity(intent);
}
});

android app crashing on startActivity()

I have started an Intent and asked it to go to the main activity, when it attempts it the app crashes.
Here is the code that tries to go to the main activity.
Intent i = new Intent(
".MAIN_ACTIVITY");
startActivity(i);
Here is the XML manifest for Main_Activity.
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I'm still pretty new to this so any help and/or advice is of great value.
Write like this :
Intent i = new Intent(MainActivity.this, NewActivity.class);
startActivity(i);
Also you need to declare both activity class in manifest file like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NewActivity"
android:label="#string/app_name" >
</activity>
For those, who come from Google, I was trying to pass large string in putExtra (over 90K Symbols) and my app was crashing because of that. The correct solution is either save the string to file or implement Singleton.
Here is the relevant link Maximum length of Intent putExtra method? (Force close)
as per your code: if i have create newActiviy in my project then:
i have to add that activity in android manifest file.
like:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<activity android:name=".newActivity"></activity>
</activity>
for calling that activity just do:
Intent intent = new Intent(MainActivity.this, newActivity.class);
startActivity(intent);
befre ask question here try some googling. and you must have to check this: Building Your First Android App and Starting Another Activity
Start new Activity like this:
Intent intent = new Intent(YourCurrentActivity.this, TargetActivity.class);
startActivity(intent);

Categories

Resources