实施Adwhirl的问题

时间:2011-01-09 19:43:35

标签: android adwhirl

好的,所以我放入了adwhirl jar和权限以及所有这些,我将布局添加到我的主xml并添加了java的东西,我没有错误或警告所以我对我做错了很困惑。这是我的源代码,布局,清单和日志cat

JAVA来源代码

public class ListA extends Activity implements OnClickListener, AdWhirlInterface {
    //**Sets the EditText view to txtNumber
    EditText txtNumber = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);

        if (layout == null) {
          Log.e("AdWhirl", "Layout is null!");
          return;
        }

        // These are density-independent pixel units, as defined in
        // http://developer.android.com/guide/practices/screens_support.html
        int width = 320;
        int height = 52;

        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        float density = displayMetrics.density;

        width = (int) (width * density);
        height = (int) (height * density);

        AdWhirlTargeting.setAge(23);
        AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);
        String keywords[] = { "online", "games", "gaming" };
        AdWhirlTargeting
            .setKeywordSet(new HashSet<String>(Arrays.asList(keywords)));
        AdWhirlTargeting.setPostalCode("94123");
        AdWhirlTargeting.setTestMode(false);

        AdWhirlAdapter.setGoogleAdSenseAppName("AdWhirl Test App");
        AdWhirlAdapter.setGoogleAdSenseCompanyName("AdWhirl");

        // Optional, will fetch new config if necessary after five minutes.
        AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

        // References AdWhirlLayout defined in the layout XML.
        AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.adwhirl_layout);
        adWhirlLayout.setAdWhirlInterface(this);
        adWhirlLayout.setMaxWidth(width);
        adWhirlLayout.setMaxHeight(height);

        // Instantiates AdWhirlLayout from code.
        // Note: Showing two ads on the same screen is for illustrative purposes
        // only.
        // You should check with ad networks on their specific policies.
        AdWhirlLayout adWhirlLayout2 = new AdWhirlLayout(this,
            "46a9e26bb1f5499ab7b00c9807ae034b");
        adWhirlLayout2.setAdWhirlInterface(this);
        adWhirlLayout2.setMaxWidth(width);
        adWhirlLayout2.setMaxHeight(height);
        RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        adWhirlLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        layout.setGravity(Gravity.CENTER_HORIZONTAL);
        layout.addView(adWhirlLayout2, adWhirlLayoutParams);

        TextView textView = new TextView(this);
        textView.setText("Below AdWhirlLayout from code");
        layout.addView(textView, adWhirlLayoutParams);
        layout.setGravity(Gravity.CENTER_HORIZONTAL);
        layout.invalidate();
      }

      public void adWhirlGeneric() {
        Log.e(AdWhirlUtil.ADWHIRL, "In adWhirlGeneric()");

        //**This makes it so that the EditText view can be called
        //**into the dialer
        txtNumber =  (EditText)(this.findViewById(R.id.txtNumber));

        //**Handles what the button dialer is going to do
        final Button btndialer = (Button) findViewById(R.id.dialer);
        btndialer.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {

            Intent dialIntent=
            new Intent(Intent.ACTION_CALL,Uri.parse("tel:*"+(txtNumber.getText()).toString()));
            startActivity(dialIntent);
            finish();

            Toast.makeText(ListA.this, R.string.Dial_notification,
                    Toast.LENGTH_LONG).show();

               }
              });

      //**Handles what the button redialer is going to do
        Button btnredialer = (Button) findViewById(R.id.redialer);
        btnredialer.setOnClickListener(new OnClickListener() { 

            public void onClick(View v) {

            Intent dialIntent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:*"));
            startActivity(dialIntent);

            Toast.makeText(ListA.this, R.string.Dial_notification,
                    Toast.LENGTH_LONG).show();

               }
              });
    }

    //**This calls the contacts view using the button.
    //**Make sure to use import android.provider.Contact.contacts;
    //**Do not use import android.provider.contacts; (this is for an older version)
    private static final int CONTACT_PICKER_RESULT = 1001;  

    public void doLaunchContactPicker(View view) {  
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,  
                Contacts.CONTENT_URI);  
        startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  
    }
    public void onClick(View view) {

}
    //**Grabs the results for the contact picker and calls it back into the activity.
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

        if (resultCode == RESULT_OK) {  
            switch (requestCode) {  
            case CONTACT_PICKER_RESULT:  
                Cursor cursor = null;  
                String Number = "";  
                try {  
                    Uri result = data.getData();  
                    Log.v(NOTIFICATION_SERVICE, "Got a contact result: "  
                            + result.toString());  

                    // get the contact id from the Uri  
                    String id = result.getLastPathSegment();  

                    // query for everything email  
                    cursor = getContentResolver().query(Phone.CONTENT_URI,  
                            null, Phone.CONTACT_ID + "=?", new String[] { id },  
                            null);  

                    int emailIdx = cursor.getColumnIndex(Phone.DATA);  

                    // let's just get the first email  
                    if (cursor.moveToFirst()) {  
                        Number = cursor.getString(emailIdx);  
                        Log.v(NOTIFICATION_SERVICE, "Got email: " + Number);  
                    } else {  
                        Log.w(NOTIFICATION_SERVICE, "No results");  
                    }  
                } catch (Exception e) {  
                    Log.e(NOTIFICATION_SERVICE, "Failed to get email data", e);  
                } finally {  
                    if (cursor != null) {  
                        cursor.close();  
                    }  
                    EditText emailEntry = (EditText) findViewById(R.id.txtNumber);  
                    emailEntry.setText(Number);  
                    if (Number.length() == 0) {  
                        Toast.makeText(this, "No email found for contact.",  
                                Toast.LENGTH_LONG).show();  
                    }  

                }  

                break;  
            }  

        } else {  
            Log.w(NOTIFICATION_SERVICE, "Warning: activity result not ok");  
        }  


}
    public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu, menu);
          return true;              

      }
          public boolean onOptionsItemSelected(MenuItem item) {
              // Handle item selection
              switch (item.getItemId()) {
              case R.id.item1:
                  Intent i = new Intent(ListA.this, straightapp.class);
                  startActivity(i); 
                    finish();
                  return true;

              default:
                  return super.onOptionsItemSelected(item);
              }
          }

}

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"
     android:orientation="vertical"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:focusable="true"
    android:id="@+id/layout_main">
<Button android:id="@+id/Button01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:onClick="doLaunchContactPicker" android:text="@string/GetContacts">
</Button>
<EditText 
    android:hint="@string/hint" 
    android:id="@+id/txtNumber" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:inputType="phone">
</EditText>
<Button 
    android:text="@string/dialer" 
    android:id="@+id/dialer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:onClick="OnClick">
</Button>
<Button 
    android:text="@string/redialer" 
    android:id="@+id/redialer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:onClick="OnClick2">
</Button>
 <com.adwhirl.AdWhirlLayout
        android:id="@+id/adwhirl_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.app"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ListA"
                  android:label="@string/app_name">
            <intent-filter>

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter>   
<meta-data android:value="bef8fbbc34c64ceaa67d1c230e864150"
        android:name="ADWHIRL_KEY"/>   
</activity>
<activity android:name="straightapp"></activity>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

</manifest> 

登录CAT

01-09 12:33:29.586: DEBUG/AndroidRuntime(663): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<

01-09 12:33:29.586: DEBUG/AndroidRuntime(663): CheckJNI is ON

01-09 12:33:29.786: DEBUG/AndroidRuntime(663): --- registering native functions ---

01-09 12:33:30.546: DEBUG/AndroidRuntime(663): Shutting down VM

01-09 12:33:30.556: DEBUG/dalvikvm(663): Debugger has detached; object registry had 1 entries

01-09 12:33:30.576: INFO/AndroidRuntime(663): NOTE: attach of thread 'Binder Thread #3' failed

01-09 12:33:31.116: DEBUG/AndroidRuntime(671): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<

01-09 12:33:31.116: DEBUG/AndroidRuntime(671): CheckJNI is ON

01-09 12:33:31.316: DEBUG/AndroidRuntime(671): --- registering native functions ---

01-09 12:33:32.077: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.adapter/.ListA }

01-09 12:33:32.117: INFO/ActivityManager(59): Start proc com.adapter for activity com.adapter/.ListA: pid=677 uid=10037 gids={3003, 1015}

01-09 12:33:32.157: DEBUG/AndroidRuntime(671): Shutting down VM

01-09 12:33:32.187: DEBUG/dalvikvm(671): Debugger has detached; object registry had 1 entries

01-09 12:33:32.207: INFO/AndroidRuntime(671): NOTE: attach of thread 'Binder Thread #3' failed

01-09 12:33:32.927: DEBUG/AndroidRuntime(677): Shutting down VM

01-09 12:33:32.977: WARN/dalvikvm(677): threadid=1: thread exiting with uncaught exception (group=0x4001d800)

01-09 12:33:33.017: ERROR/AndroidRuntime(677): FATAL EXCEPTION: main

01-09 12:33:33.017: ERROR/AndroidRuntime(677): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.adapter/com.adapter.ListA}: java.lang.ClassNotFoundException: com.adapter.ListA in loader dalvik.system.PathClassLoader[/data/app/com.adapter-2.apk]

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.os.Handler.dispatchMessage(Handler.java:99)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.os.Looper.loop(Looper.java:123)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread.main(ActivityThread.java:4627)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at java.lang.reflect.Method.invokeNative(Native Method)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at java.lang.reflect.Method.invoke(Method.java:521)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at dalvik.system.NativeStart.main(Native Method)

01-09 12:33:33.017: ERROR/AndroidRuntime(677): Caused by: java.lang.ClassNotFoundException: com.adapter.ListA in loader dalvik.system.PathClassLoader[/data/app/com.adapter-2.apk]

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)

01-09 12:33:33.017: ERROR/AndroidRuntime(677):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-09 12:33:33.017: ERROR/AndroidRuntime(677):     ... 11 more

01-09 12:33:33.037: WARN/ActivityManager(59):   Force finishing activity com.adapter/.ListA

01-09 12:33:33.567: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{4403a418 com.adapter/.ListA}

01-09 12:33:35.176: INFO/Process(677): Sending signal. PID: 677 SIG: 9

01-09 12:33:35.196: INFO/ActivityManager(59): Process com.adapter (pid 677) has died.

01-09 12:33:35.216: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43efbb88

01-09 12:33:43.859: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{4403a418 com.adapter/.ListA}

1 个答案:

答案 0 :(得分:0)

想出来。它与我经历的adwhirl无关,并将我的应用程序归结为基本的,它仍然强制关闭,所以这一切都在我的主项目中。它现在想通了。