Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kt.myapplication" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/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:name=".ViewerActivity"
android:label="#string/title_activity_viewer" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.main_txt).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("myapp://"));
startActivity(intent);
}
});
}
}
ViewerActivity.java
public class ViewerActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewer);
}
}
Error log...
03-02 09:37:59.753 21103-21103/com.example.kt.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.kt.myapplication, PID: 21103
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp:// }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
at android.app.Activity.startActivityForResult(Activity.java:3511)
at android.app.Activity.startActivityForResult(Activity.java:3472)
at android.app.Activity.startActivity(Activity.java:3714)
at android.app.Activity.startActivity(Activity.java:3682)
at com.example.kt.myapplication.MainActivity$1.onClick(MainActivity.java:26)
at android.view.View.performClick(View.java:4630)
at android.view.View$PerformClick.run(View.java:19331)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
I don't know why don't run...
please help me...
For some reason it seems like Android do not allow you to have only Browsable category in the intent filter declaration, try this instead:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="somettt"/>
</intent-filter>
And launch it as expected:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("somettt://"));
startActivity(intent);
It should work now...
EDIT: This is why it works with DEFAULT as per Google's:
CATEGORY_DEFAULT
Set if the activity should be an option for the default action (center
press) to perform on a piece of data. Setting this will hide from the
user any activities without it set when performing an action on some
data. Note that this is normally -not- set in the Intent when
initiating an action -- it is for use in intent filters specified in
packages.
Regards!
Related
I want to create an application which will have two entry points.
The first will be a regular entry when the user clicks the app icon.
The second one will be through a deeplink which will be sent through push notifications.
I used this tutorial to build the deeplink.
I tried to use the deeplink to open the second entry point using adb, however I keep getting
Activity not started, unable to resolve Intent.
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.edwardkeselman.siemens">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_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/AppTheme">
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ReportActivity" />
<activity android:name=".DetailsActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my DetailsActivity:
public class DetailsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
}
This is the adb command that I use to try to open the DetailsActivity:
adb shell am start -W -a android.intent.action.BROWSE -d "example://gizmoz" com.example.myname
Help will be much appreciated.
manifest.xml
<activity android:name=".DeepLinking">
<intent-filter android:label="#string/filter_deeplinking">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data
android:host="domain.in"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix -->
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
</activity>
DeepLinking.java
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.net.URLDecoder;
public class DeepLinking extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deep_linking);
Intent intent = getIntent();
String action = intent.getAction();
Uri uri_data = intent.getData();
String data=uri_data.toString();
Log.d("DATA : ",""+uri_data.toString());
if(data.equals("domain.in") || data.equals("http://domain.in") )
{
Intent i = new Intent(getApplicationContext(), Splash.class);
startActivity(i);
finish();
}
else if (!data.equals(null))
{
Intent i = new Intent(getApplicationContext(), DetailActivity.class);
startActivity(i);
finish();
}
else
{
Intent i = new Intent(getApplicationContext(), Splash.class);
startActivity(i);
finish();
}
}
}
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.ui05.ACTION_START");
intent.addCategory("com.example.ui05.MY_CATEGORY");
startActivity(intent);
}
the relevant Manifest is:
<activity android:name=".SecondActivity" >
<intent-filter>
<action android:name="com.example.ui05.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.CATEGORY" />
</intent-filter>
</activity>
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.ui05.ACTION_START");
startActivity(intent);
}
the relevent manifest is:
<activity android:name=".SecondActivity" >
<intent-filter>
<action android:name="com.example.ui05.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
why the first situation would give an Exception :
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=com.example.ui05.ACTION_START cat=[com.example.ui05.MY_CATEGORY] }
The second situation is OK.
Your intent filter doesn't include the category for the category you're specifying in the intent. Change your intent filter category specifying android.intent.category.CATEGORY to com.example.ui05.MY_CATEGORY and it should work.
Within my application I am getting the following error from logcat, What is the error with my code? I have searched for over an hour online and cannot solve the issue.
It is relating to the intent that I am trying to use in order to open up a new activity but I am not sure how to solve it.
07-20 20:02:18.976: E/AndroidRuntime(7381): FATAL EXCEPTION: Thread-9022
07-20 20:02:18.976: E/AndroidRuntime(7381): Process: com.example.brianapp, PID: 7381
07-20 20:02:18.976: E/AndroidRuntime(7381): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.brianapp.MeditationResults }
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3511)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3472)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3714)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3682)
07-20 20:02:18.976: E/AndroidRuntime(7381): at com.example.brianapp.Meditation$2.run(Meditation.java:115)
It is relating from this code section as this error only occured once I changed this code section:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.meditation);
//new thread
Thread timer = new Thread() {
/**
* Method that firstly starts the thread and makes it sleep,
* then using intents opens the main activity using
* a reference to its name
*/
public void run() {
try {
//sleep for 3.5 seconds
sleep(15000);
} catch (InterruptedException e) {
// exceptions caught here
e.printStackTrace();
} finally {
Intent openActivity = new Intent("com.example.brianapp.MeditationResults");
// //Start activity
startActivity(openActivity);
}
}
};
//Start timer
timer.start();
The following is my manifest, note that I have included an intent filter for this class (meditation), the class I am trying to open with the intent is called MeditationResults:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brianapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.brianapp.Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.brianapp.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.Meditation"
android:label="Meditation" >
<intent-filter>
<action android:name="com.example.brianapp.meditation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
</activity>
<activity
android:name="com.example.brianapp.UserName"
android:label="#string/title_activity_user_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.ServerInterface"
android:label="#string/title_activity_server_interface" >
</activity>
</application>
</manifest>
Change this in your manifest to
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
</activity>
to
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
<intent-filter>
<action android:name="com.example.brianapp.MeditationResults" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I am creating a Jigsaw Puzzle application in android. I have created two activites, activity_jigsaw.xml and activity_level.xml. One activity is created by default (Displaying Hello World!) which I modified and created a new activity by following these steps:
File -> New -> Other -> Android Activity
But when I install the application these two files (and all other activities of the application) are installed as a separate project. But at the same time they are also interlinked. The Java code of the files as follows:
Jisaw.java file contains:
public class Jigsaw extends Activity {
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jigsaw);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_jigsaw, menu);
return true;
}
public void play(View v)
{
try
{
intent = new Intent(this, Level.class);
startActivity(intent);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Here Play is a function which is called when an image is clicked.
Level.java file contains:
public class Level extends Activity {
Intent intent;
String level = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_level, menu);
return true;
}
public void easy(View v)
{
level = "easy";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void medium(View v)
{
level = "medium";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void hard(View v)
{
level = "hard";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
}
Functions easy, medium and hard are called when a corresponding image is clicked.
Can somebody please tell me that what I am doing wrong?
Thanks in advance..
Here is the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maju.jigsawpuzzle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Jigsaw"
android:label="#string/title_activity_jigsaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Level"
android:label="#string/title_activity_level" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:label="#string/title_activity_play" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayBoard"
android:label="#string/title_activity_play_board" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You probably are defining android.intent.category.LAUNCHER intent category to all the activities in your AndroidManifest.xml, it creates an icon in the app launcher. Activities other than main should not have this intent filter.
Do something like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".JigSaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Level" />
<activity android:name=".Play" />
<activity android:name=".Playboard" />
</application>
EDIT:
As you just posted, you are indeed doing that, just remove the intent filter from other activities.
07-18 04:48:22.465: E/AndroidRuntime(19105): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.liamwli.fa.yearbook/com.liamwli.fa.yearbook.Home}: java.lang.NullPointerException
That is the error I get.
I have defined the Home class in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liamwli.fa.yearbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And it only started doing this when I added the putExtras line in my main activity:
enter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
myname = name.getText().toString();
Intent i = new Intent("com.liamwli.fa.yearbook.HOME");
i.putExtra("myname", myname);
startActivity(i);
}
});
So, can anyone please explain what is happening?
use this:
Intent i = new Intent(context,otherActivity.class);
context of that activity from where you want to start activity.otherActivity is the name of activity which you want to start
Try this once
Intent i = new Intent(MainActivity.this,Home.class);
i.putExtra("myname", myname);
startActivity(i);
And I don't think this is required in Manifest
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
change like this
Intent i = new Intent(MainActivity.this, Home.class);
i.putExtra("myname", myname);
startActivity(i);
Try this...
Intent i = new Intent( YourActivityName.this , otherActivity.class);
Ok, I looked and it looked like I was setting a variable contents outside of the onCreate method. So that is why it wasn't working.