then when i press f8 a i get : ZygoteInit$methodandargscaller.run() source not found
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.copyup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.copyup.MainActivity"
android:label="copy up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Game"
android:label="Copy Up">
</activity>
<activity
android:name=".Rules"
android:label="Copy Up!">
</activity>
<activity
android:name=".Scores"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnCircle"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnHoriz"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnVert"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnMenu"
android:label="Copy Up!">
</activity>
</application>
</manifest>
and my code:
package com.example.copyup;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button start, rules, hs, learn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linktoxml();
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Game.class);
MainActivity.this.startActivity(myIntent);
}
});
/*
rules.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Rules.class);
MainActivity.this.startActivity(myIntent);
}
});
hs.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Scores.class);
MainActivity.this.startActivity(myIntent);
}
});
learn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, LearnMenu.class);
MainActivity.this.startActivity(myIntent);
}
});*/
//show shape, take reading after 4 seconds, compare with other, if true next, if false, end game
//dont make it complex with time reduce yet!!
}
private void linktoxml() {
start = (Button) findViewById(R.id.bcstart);
rules = (Button) findViewById(R.id.brules);
hs = (Button) findViewById(R.id.bhs);
learn = (Button) findViewById(R.id.blearn);
}
}
I have tried cleaning the project, re-writing the manifest and everything i can possible think of. It works if i comment out the links to the buttons in the code and leave them in the manifest but the moment i uncommnet them i get these errors, please help!!!
The problem is that the activity throw exception.
eclipse looks for the source code in android SDK and can't find it.
Just debug your code and find out where the code throw exception.
solved it, feeling pretty stupid now, needed bstart not bcstart when the button is defined.
Related
i'm a student and i'm working on a mobile app.
The probleme is that my app was working, but now when i click on the button to open another window it closes.
Here is my code:
`
public class MainActivity extends AppCompatActivity {
Button b_inscrire_etudiant;
Button b_inscrire_enseignant;
Button b_inscrire_admin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b_inscrire_etudiant = findViewById(R.id.b_inscrire_etudiant);
b_inscrire_enseignant = findViewById(R.id.b_inscrire_enseignat);
b_inscrire_admin = findViewById(R.id.b_inscrire_admin);
b_inscrire_etudiant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionEtudiant.class);
startActivity(i);
}
});
b_inscrire_enseignant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionEnseignant.class);
startActivity(i);
}
});
b_inscrire_admin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionAdmin.class);
startActivity(i);
}
});
}
}
`
I worked as usual "using Intent" besides it worked well until now.
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myusto">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyUsto"
tools:targetApi="31">
<activity
android:name=".InscriptionEnseignant"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".InscriptionEtudiant"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".InscriptionAdmin"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".Connexion"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
ps: I solved the problem, by the way two were missing
Thank you for the answers.
It's true, it was missing a part of the code which was not written in the manifest file
I have imported a package which was downloaded from the link "https://github.com/moritz-wundke/android-page-curl", then I created a new project and imported the downloaded package by clicking on "import module". I have added a button inside my new package to open the downloaded package. But its not working. Can someone help. Here is the code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage
("fi.harism.curl");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
});
}
Manifest:
<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"
tools:replace="android:icon">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Layout:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:text="press"/>
enter code here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newuser.applicationtwo">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:screenOrientation="landscape"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
android:label="#string/app_name">
</activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>
<activity android:name=".SecondActivity" />
<activity android:name=".ThirdActivity" />
<activity android:name=".FourthActivity" />
<activity android:name=".FifthActivity" />
<activity android:name=".SixthActivity" />
</manifest>
-----------------------------------------------------------------------
package com.example.newuser.applicationtwo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import static android.content.ContentValues.TAG;
public class MainActivity extends Activity implements View.OnClickListener
{
private ImageButton playBtn, multiplayerBtn, settingsBtn;
public MainActivity(ImageButton playBtn, ImageButton multiplayerBtn) {
this.playBtn = playBtn;
this.multiplayerBtn = multiplayerBtn;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.playBtn:
Intent i = new Intent(getApplicationContext(),
SecondActivity.class);
startActivity(i);
onClick(playBtn);
Log.d(TAG, "Play Button Move");
break;
case R.id.TopicBtn8:
Intent j = new Intent(getApplicationContext(),
ThirdActivity.class);
startActivity(j);
onClick(multiplayerBtn);
Log.d(TAG, "Multiplayer Button Move");
break;
case R.id.settingsBtn:
Intent k = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(k);
onClick(settingsBtn);
Log.d(TAG, "Settings Button Move");
break;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playBtn = (ImageButton) findViewById(R.id.playBtn);
multiplayerBtn = (ImageButton) findViewById(R.id.multiplayerBtn);
settingsBtn = (ImageButton) findViewById(R.id.settingsBtn);
playBtn.setOnClickListener(MainActivity.this);
multiplayerBtn.setOnClickListener(MainActivity.this);
settingsBtn.setOnClickListener(MainActivity.this);
------------------------------------------------------------------------
package com.example.newuser.applicationtwo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import static android.content.ContentValues.TAG;
class SecondActivity extends AppCompatActivity implements
View.OnClickListener {
private Button topic1Btn, topic2Btn, topic3Btn, topic4Btn, topic5Btn,
topic6Btn, topic7Btn, topic8Btn;
public SecondActivity(Button topic1Btn, Button topic2Btn, Button topic3Btn,
Button topic4Btn,
Button topic5Btn, Button topic6Btn, Button topic7Btn,
Button topic8Btn) {
this.topic1Btn = topic1Btn;
this.topic2Btn = topic2Btn;
this.topic3Btn = topic3Btn;
this.topic4Btn = topic4Btn;
this.topic5Btn = topic5Btn;
this.topic6Btn = topic6Btn;
this.topic7Btn = topic7Btn;
this.topic8Btn = topic8Btn;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.topic1Btn:
Intent i = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(i);
onClick(topic1Btn);
Log.d(TAG, "Topic 1 Button Clicked");
break;
case R.id.topic2Btn:
Intent j = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(j);
onClick(topic2Btn);
Log.d(TAG, "Topic 2 Button Clicked");
break;
case R.id.topic3Btn:
Intent k = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(k);
onClick(topic3Btn);
Log.d(TAG, "Topic 3 Button Move");
break;
case R.id.topic4Btn:
Intent l = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(l);
onClick(topic4Btn);
Log.d(TAG, "Topic 4 Button Move");
break;
case R.id.topic5Btn:
Intent m = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(m);
onClick(topic5Btn);
Log.d(TAG, "Topic 5 Button Clicked");
break;
case R.id.topic6Btn:
Intent n = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(n);
onClick(topic6Btn);
Log.d(TAG, "Topic 6 Button Clicked");
break;
case R.id.topic7Btn:
Intent o = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(o);
onClick(topic7Btn);
Log.d(TAG, "Topic 7 Button Move");
break;
case R.id.topic8Btn:
Intent p = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(p);
onClick(topic8Btn);
Log.d(TAG, "Topic 8 Button Move");
break;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
topic1Btn = (Button) findViewById(R.id.topic1Btn);
topic2Btn = (Button) findViewById(R.id.topic2Btn);
topic3Btn = (Button) findViewById(R.id.topic3Btn);
topic4Btn = (Button) findViewById(R.id.topic4Btn);
topic5Btn = (Button) findViewById(R.id.topic5Btn);
topic6Btn = (Button) findViewById(R.id.topic6Btn);
topic7Btn = (Button) findViewById(R.id.topic7Btn);
topic8Btn = (Button) findViewById(R.id.topic8Btn);
topic1Btn.setOnClickListener(SecondActivity.this);
topic2Btn.setOnClickListener(SecondActivity.this);
topic3Btn.setOnClickListener(SecondActivity.this);
topic4Btn.setOnClickListener(SecondActivity.this);
topic5Btn.setOnClickListener(SecondActivity.this);
topic6Btn.setOnClickListener(SecondActivity.this);
topic7Btn.setOnClickListener(SecondActivity.this);
topic8Btn.setOnClickListener(SecondActivity.this);
Intent intent = new Intent(getApplicationContext(),
SixthActivity.class);
startActivity(intent);
}
}
----------------------------------------------------
I wonder if anyone can help? I am trying to build an quiz application and I
am having a problem with the main activity in the manifest file. It seems
to be asking for a constructor and when I run the code it is telling me the
following:Error running SecondActivity: The activity 'SecondActivity' is
not declared in AndroidManifest.xml . Not sure how I would change this as
MainActivity or what else to add for the SecondActivity, unfortunately
reading through similar questions on MainActivity I cannot resolve it.
I attach the Manifest file and both the MainActivity and the SecondActivity
Move
</application>*
right before
</manifest>
because now only first activity is in < application > scope
First remove all constructor which is not needed here and you are not adding all activity under application tag in manifest also you defining the launcher filter out of activity tag add it under activity tag, change manifest as below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newuser.applicationtwo">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:screenOrientation="landscape"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
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=".SecondActivity" />
<activity android:name=".ThirdActivity" />
<activity android:name=".FourthActivity" />
<activity android:name=".FifthActivity" />
<activity android:name=".SixthActivity" />
</application>
</manifest>
I also recommend you to go through basic android development tutorial
https://developer.android.com/training/index.html
activity tags belong inside the application tag.
This should work:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newuser.applicationtwo">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:screenOrientation="landscape"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
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=".SecondActivity" />
<activity android:name=".ThirdActivity" />
<activity android:name=".FourthActivity" />
<activity android:name=".FifthActivity" />
<activity android:name=".SixthActivity" />
</application>
</manifest>
Appart the fakt that all the activities you declare in your androidmanifest file, should be included in the <application> </application> tag, also if you want to start one exact activity first (meaning that when the app launches that exact activity will start first, for example if you want a logo image, create an activity for that) , you can change the category name to LAUNCHER, and if you want it not to be the first activity starting when the application launches, put it to DEFAULT like this:
<category android:name="android.intent.category.DEFAULT" />
My app crashes when I try to navigate to another activity. Why does that happen?
I'm able to start the other activity when I launch it at first so there's no problem in the CheckUsernameActivity.
public class CheckNumberActivity extends AppCompatActivity {
EditText phoneNumberEditText;
Button countryCodeButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_number);
Button button = (Button) findViewById(R.id.okButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
countryCodeButton = (Button) findViewById(R.id.countryCodeButton);
phoneNumberEditText = (EditText) findViewById(R.id.phoneNumberEditText);
Log.v("areaCode", countryCodeButton.getText().toString());
Log.v("phoneNumber", phoneNumberEditText.getText().toString());
Intent k = new Intent(CheckNumberActivity.this, CheckUsernameActivity.class);
startActivity(k);
}
});
}
}
Try This way. I think it will help you.
public class CheckNumberActivity extends AppCompatActivity {
EditText phoneNumberEditText;
Button countryCodeButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_number);
Button button = (Button) findViewById(R.id.okButton);
countryCodeButton = (Button) findViewById(R.id.countryCodeButton);
phoneNumberEditText = (EditText) findViewById(R.id.phoneNumberEditText);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v("areaCode", countryCodeButton.getText().toString());
Log.v("phoneNumber", phoneNumberEditText.getText().toString());
Intent k = new Intent(CheckNumberActivity.this, CheckUsernameActivity.class);
startActivity(k);
}
});
}
}
I didn't have my new activity defined in my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dimsumdev.runk" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".activity.CheckNumberActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.CheckUsernameActivity" >
<!--Default Intent Filter-->
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".activity.HomeActivity" >
</activity>
</application>
</manifest>
I want get the install referrer value in my MainActivity. For that i am using two class
1) MainActivity
2) ReferrerReceiver
I got received install referrer value successfully in ReferrerReceiver class, i tested this using Toast control.
But i can not able to pass this value to MainActivity from ReferrerReceiver.
Bellow is i tried code. please any one help me.
Thanks for advance.
1) MainActivity.java
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv1 = (TextView) findViewById(R.id.tv1);
Intent in1= getIntent();
String ldString = in1.getStringExtra("number");
tv1.setText(ldString);
}
}
2) ReferrerReceiver.java
public class ReferrerReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
return;
}
Bundle bundle = intent.getExtras();
String phoneNumber = bundle.getString("referrer");
Intent i = new Intent(context, MainActivity.class);
i.putExtra("number", phoneNumber);
context.startActivity(i);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myreferrer.in"
android:versionCode="7"
android:versionName="1.0.6" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<receiver android:name="com.myreferrer.in.ReferrerReceiver"
android:enabled="true">
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This was i implemented in my project. its working for me. Use this code
(1) MainActivity.java
public class MainActivity extends Activity {
TextView tv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
}
public static void log(Context context, String string) {
if(string!=null) {
Toast.makeText(conte, "Referrer value is."+string, Toast.LENGTH_LONG).show();
tv1.setText(string);
}
}
(2) ReferrerReceiver.java
public class ReferrerReceiver extends BroadcastReceiver {
String referrer,rawReferrer;
public static String getReferrer(Context context) {
// Return any persisted referrer value or null if we don't have a referrer.
return context.getSharedPreferences("referrer", Context.MODE_PRIVATE).getString("referrer", null);
}
#Override
public void onReceive(Context context, Intent intent) {
try {
// Make sure this is the intent we expect - it always should be.
if ((null != intent) && (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))) {
// This intent should have a referrer string attached to it.
rawReferrer = intent.getStringExtra("referrer");
if (null != rawReferrer) {
// The string is usually URL Encoded, so we need to decode it.
referrer = URLDecoder.decode(rawReferrer, "UTF-8");
Toast.makeText(context, "ReferrerReceiver." + referrer, Toast.LENGTH_LONG).show();
MainActivity.log(context,"\nRaw referrer: " + rawReferrer +"\nReferrer: " + referrer);
MainActivity.log(context,referrer);
// Persist the referrer string.
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", referrer).commit();
} else {
Toast.makeText(context, "ReferrerReceiver." + referrer, Toast.LENGTH_LONG).show();
MainActivity.log(context,referrer);
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", referrer).commit();
}
} else {
Toast.makeText(context, "ReferrerReceiver intent value is null.", Toast.LENGTH_LONG).show();
MainActivity.log(context,referrer);
MainActivity.log(context,"intent value is nulll");
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", "intent value is nulll").commit();
}
}
catch (Exception e) {
//Toast.makeText(context, "ReferrerReceiver catch"+e, Toast.LENGTH_LONG).show();
MainActivity.log(context, e.toString());
}
}
}
(3) AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myreferrer.in"
android:versionCode="7"
android:versionName="1.0.6" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<receiver android:name="com.myreferrer.ReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(4) sample link:
https://play.google.com/store/apps/details?id=your_package_name&referrer=Welcome
You are using
Intent in1 = new Intent();
String ldString = in1.getStringExtra("KEY");
you are declaring new intent which is wrong, and also key you put is also wrong, which should be number
Replace it With,
Intent intent= getIntent();
String ldString = intent.getStringExtra("number");
you have declared your activity as"single Task" in Manifest;so if an instance of your
activity is already launched the system will create (NewIntent) to re_lunch your
activity.try to put this code before onCreate():
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// NOW getIntent() should always return the recent
setIntent(intent);
}
to get all the time the newest intent with the new extras.