当前位置: 编程技术>移动开发
本页文章导读:
▪自定义PreferenceActivity——修改Preference样式、加顶部布局 自定义PreferenceActivity——批改Preference样式、加顶部布局
自定义PreferenceActivity——修改Preference样式、加顶部布局首先在res/xml文件夹下建立preferences.xml<?xml version="1.0" encoding="utf-8"?><Pre.........
▪ 电话状态变更 电话状态变化
电话拨出,随后挂断04-27 18:28:38.600: I/System.out(15039): action = android.intent.action.NEW_OUTGOING_CALL
04-27 18:28:38.600: I/System.out(15039): 拨电话,状态:null
04-27 18:28:38.725: I/System.out(15039): action .........
▪ 新浪微博登录redirect_uri_mismatch异常解决办法 (转) 新浪微博登录redirect_uri_mismatch错误解决方法 (转)
1、在open.weibo.com创建应用,得到AppKey,设置“授权设置”中的“应用回调页”地址为"http://host/callback.php",其中host为网站域名。
2、下载Demo,.........
[1]自定义PreferenceActivity——修改Preference样式、加顶部布局
来源: 互联网 发布时间: 2014-02-18
自定义PreferenceActivity——批改Preference样式、加顶部布局
自定义PreferenceActivity——修改Preference样式、加顶部布局
首先在res/xml文件夹下建立preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="inline_preferences" >
<CheckBoxPreference
android:key="checkbox_preference"
android:summary="summary_toggle_preference"
android:title="title_toggle_preference" />
</PreferenceCategory>
<PreferenceCategory android:title="dialog_based_preferences" >
<EditTextPreference
android:dialogTitle="dialog_title_edittext_preference"
android:key="edittext_preference"
android:summary="summary_edittext_preference"
android:title="title_edittext_preference" />
<ListPreference
android:dialogTitle="dialog_title_list_preference"
android:entries="@array/entries_list_preference"
android:entryValues="@array/entryvalues_list_preference"
android:key="list_preference"
android:summary="summary_list_preference"
android:title="title_list_preference" />
</PreferenceCategory>
<PreferenceCategory android:title="launch_preferences" >
<PreferenceScreen
android:key="screen_preference"
android:summary="summary_screen_preference"
android:title="title_screen_preference" >
<CheckBoxPreference
android:key="next_screen_checkbox_preference"
android:summary="summary_next_screen_toggle_preference"
android:title="title_next_screen_toggle_preference" />
</PreferenceScreen>
<PreferenceScreen
android:summary="summary_intent_preference"
android:title="title_intent_preference" >
<intent
android:action="/blog_article/android.intent.action.VIEW"
android:data="http://www.android.com" />
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="preference_attributes" >
<CheckBoxPreference
android:key="parent_checkbox_preference"
android:summary="summary_parent_preference"
android:title="title_parent_preference" />
<CheckBoxPreference
android:dependency="parent_checkbox_preference"
android:key="child_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:summary="summary_child_preference"
android:title="title_child_preference" />
</PreferenceCategory>
</PreferenceScreen>
然后在代码中加载preferences.xml
public class MyPreferenceActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
这样就创建了从xml加载preferences的默认的PreferenceActivity。
在加载了preferences.xml的PreferenceActivity中, a top-level preference是一个PreferenceScreen,可用getPreferenceScreen()获取。PreferenceScreen和PreferenceCategory继承自PreferenceGroup,它们可以包含一个或多个PreferenceScreen,PreferenceCategory或者是具体的preference(如EditTextPreference、CheckBoxPreference)。由于PreferenceScreen,PreferenceCategory,EditTextPreference等都是继承自Preference,因此可以通过setLayoutResource()方法设置自己的布局样式。下面将遍历所有Preference,并设置自己的样式,代码如下:
private void setLayoutResource(Preference preference) {
if (preference instanceof PreferenceScreen) {
PreferenceScreen ps = (PreferenceScreen) preference;
ps.setLayoutResource(R.layout.preference_screen);
int cnt = ps.getPreferenceCount();
for (int i = 0; i < cnt; ++i) {
Preference p = ps.getPreference(i);
setLayoutResource(p);
}
} else if (preference instanceof PreferenceCategory) {
PreferenceCategory pc = (PreferenceCategory) preference;
pc.setLayoutResource(R.layout.preference_category);
int cnt = pc.getPreferenceCount();
for (int i = 0; i < cnt; ++i) {
Preference p = pc.getPreference(i);
setLayoutResource(p);
}
} else {
preference.setLayoutResource(R.layout.preference);
}
}
preference_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="/blog_article/@drawable/ic_launcher/index.html"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFFF1234"
/>
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FF888888" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
preference_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF123456"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="/blog_article/@drawable/ic_launcher/index.html" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFFF0000" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FF00FF00" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="#FF00FFFF" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FFFFFF00" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
下面介绍加顶部布局,其实也是添加加一个preference,通过preferenceScreen的addPreference添加。首先自定义一个PreferenceHead,布局中有一个返回按钮。
package com.preference.main;
import android.content.Context;
import android.preference.Preference;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class PreferenceHead extends Preference {
private OnClickListener onBackButtonClickListener;
public PreferenceHead(Context context) {
super(context);
setLayoutResource(R.layout.preference_head);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
Button btBack = (Button) view.findViewById(R.id.back);
btBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onBackButtonClickListener != null) {
onBackButtonClickListener.onClick(v);
}
}
});
}
public void setOnBackButtonClickListener(OnClickListener onClickListener) {
this.onBackButtonClickListener = onClickListener;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60.0dip"
android:background="#8000FF00"
android:gravity="center_vertical" >
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10.0dip"
android:text="返回" />
</LinearLayout>
然后在代码中实现
PreferenceHead ph = new PreferenceHead(this);
ph.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ph.setOrder(0);
preferenceScreen.addPreference(ph);
这样就完成了一个具有返回按钮的顶部布局的 PreferenceActivity,效果图如下
自定义PreferenceActivity——修改Preference样式、加顶部布局
首先在res/xml文件夹下建立preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="inline_preferences" >
<CheckBoxPreference
android:key="checkbox_preference"
android:summary="summary_toggle_preference"
android:title="title_toggle_preference" />
</PreferenceCategory>
<PreferenceCategory android:title="dialog_based_preferences" >
<EditTextPreference
android:dialogTitle="dialog_title_edittext_preference"
android:key="edittext_preference"
android:summary="summary_edittext_preference"
android:title="title_edittext_preference" />
<ListPreference
android:dialogTitle="dialog_title_list_preference"
android:entries="@array/entries_list_preference"
android:entryValues="@array/entryvalues_list_preference"
android:key="list_preference"
android:summary="summary_list_preference"
android:title="title_list_preference" />
</PreferenceCategory>
<PreferenceCategory android:title="launch_preferences" >
<PreferenceScreen
android:key="screen_preference"
android:summary="summary_screen_preference"
android:title="title_screen_preference" >
<CheckBoxPreference
android:key="next_screen_checkbox_preference"
android:summary="summary_next_screen_toggle_preference"
android:title="title_next_screen_toggle_preference" />
</PreferenceScreen>
<PreferenceScreen
android:summary="summary_intent_preference"
android:title="title_intent_preference" >
<intent
android:action="/blog_article/android.intent.action.VIEW"
android:data="http://www.android.com" />
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="preference_attributes" >
<CheckBoxPreference
android:key="parent_checkbox_preference"
android:summary="summary_parent_preference"
android:title="title_parent_preference" />
<CheckBoxPreference
android:dependency="parent_checkbox_preference"
android:key="child_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:summary="summary_child_preference"
android:title="title_child_preference" />
</PreferenceCategory>
</PreferenceScreen>
然后在代码中加载preferences.xml
public class MyPreferenceActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
这样就创建了从xml加载preferences的默认的PreferenceActivity。
在加载了preferences.xml的PreferenceActivity中, a top-level preference是一个PreferenceScreen,可用getPreferenceScreen()获取。PreferenceScreen和PreferenceCategory继承自PreferenceGroup,它们可以包含一个或多个PreferenceScreen,PreferenceCategory或者是具体的preference(如EditTextPreference、CheckBoxPreference)。由于PreferenceScreen,PreferenceCategory,EditTextPreference等都是继承自Preference,因此可以通过setLayoutResource()方法设置自己的布局样式。下面将遍历所有Preference,并设置自己的样式,代码如下:
private void setLayoutResource(Preference preference) {
if (preference instanceof PreferenceScreen) {
PreferenceScreen ps = (PreferenceScreen) preference;
ps.setLayoutResource(R.layout.preference_screen);
int cnt = ps.getPreferenceCount();
for (int i = 0; i < cnt; ++i) {
Preference p = ps.getPreference(i);
setLayoutResource(p);
}
} else if (preference instanceof PreferenceCategory) {
PreferenceCategory pc = (PreferenceCategory) preference;
pc.setLayoutResource(R.layout.preference_category);
int cnt = pc.getPreferenceCount();
for (int i = 0; i < cnt; ++i) {
Preference p = pc.getPreference(i);
setLayoutResource(p);
}
} else {
preference.setLayoutResource(R.layout.preference);
}
}
preference_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="/blog_article/@drawable/ic_launcher/index.html"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFFF1234"
/>
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FF888888" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
preference_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF123456"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="/blog_article/@drawable/ic_launcher/index.html" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFFF0000" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FF00FF00" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="#FF00FFFF" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="#FFFFFF00" />
</RelativeLayout>
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
下面介绍加顶部布局,其实也是添加加一个preference,通过preferenceScreen的addPreference添加。首先自定义一个PreferenceHead,布局中有一个返回按钮。
package com.preference.main;
import android.content.Context;
import android.preference.Preference;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class PreferenceHead extends Preference {
private OnClickListener onBackButtonClickListener;
public PreferenceHead(Context context) {
super(context);
setLayoutResource(R.layout.preference_head);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
Button btBack = (Button) view.findViewById(R.id.back);
btBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onBackButtonClickListener != null) {
onBackButtonClickListener.onClick(v);
}
}
});
}
public void setOnBackButtonClickListener(OnClickListener onClickListener) {
this.onBackButtonClickListener = onClickListener;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60.0dip"
android:background="#8000FF00"
android:gravity="center_vertical" >
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10.0dip"
android:text="返回" />
</LinearLayout>
然后在代码中实现
PreferenceHead ph = new PreferenceHead(this);
ph.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ph.setOrder(0);
preferenceScreen.addPreference(ph);
这样就完成了一个具有返回按钮的顶部布局的 PreferenceActivity,效果图如下
[2] 电话状态变更
来源: 互联网 发布时间: 2014-02-18
电话状态变化
电话拨出,随后挂断
来电,接通,挂断
来电,没接挂断
后记:您的文章当中包含了敏感关键词'电话兼听',属于有关部门规定的有害信息,为了保护您和ITeye网站的安全,我们建议您不要发表这篇文章,有关部门一旦认为你的文章是有害信息,会要求我们提供你的IP地址无处不在的监控。
电话拨出,随后挂断
04-27 18:28:38.600: I/System.out(15039): action = android.intent.action.NEW_OUTGOING_CALL 04-27 18:28:38.600: I/System.out(15039): 拨电话,状态:null 04-27 18:28:38.725: I/System.out(15039): action = android.intent.action.PHONE_STATE 04-27 18:28:38.725: I/System.out(15039): 接受电话,状态:OFFHOOK 04-27 18:29:05.610: I/System.out(15039): action = android.intent.action.PHONE_STATE 04-27 18:29:05.610: I/System.out(15039): 接受电话,状态:IDLE
来电,接通,挂断
04-27 18:26:53.129: I/System.out(19370): action = android.intent.action.PHONE_STATE 04-27 18:26:53.129: I/System.out(19370): 接受电话,状态:RINGING 04-27 18:26:56.319: I/System.out(19370): action = android.intent.action.PHONE_STATE 04-27 18:26:56.319: I/System.out(19370): 接受电话,状态:OFFHOOK 04-27 18:27:08.659: I/System.out(19370): action = android.intent.action.PHONE_STATE 04-27 18:27:08.659: I/System.out(19370): 接受电话,状态:IDLE
来电,没接挂断
04-27 18:24:27.159: I/System.out(19370): action = android.intent.action.PHONE_STATE 04-27 18:24:27.159: I/System.out(19370): 接受电话,状态:RINGING 04-27 18:24:39.089: I/System.out(19370): action = android.intent.action.PHONE_STATE 04-27 18:24:39.089: I/System.out(19370): 接受电话,状态:IDLE
电话状态对应: RINGING ----对应来电时响起铃声 OFFHOOK ----如果是来电,则是来电接通到挂断之前,如果是拨出,则是点击拨打电话那一刻(还未接通),直到挂断 IDLE ----对应挂断电话,即没有任何的电话事件了 特别说明:如果你在打电话过程中(状态为 OFFHOOK),此时如果有人再给你打电话,就会想起铃声,这时候的状态会变化为 RINGING,如果你挂断该来电,继续之前的电话,状态又变为 OFFHOOK
后记:您的文章当中包含了敏感关键词'电话兼听',属于有关部门规定的有害信息,为了保护您和ITeye网站的安全,我们建议您不要发表这篇文章,有关部门一旦认为你的文章是有害信息,会要求我们提供你的IP地址无处不在的监控。
[3] 新浪微博登录redirect_uri_mismatch异常解决办法 (转)
来源: 互联网 发布时间: 2014-02-18
新浪微博登录redirect_uri_mismatch错误解决方法 (转)
1、在open.weibo.com创建应用,得到AppKey,设置“授权设置”中的“应用回调页”地址为"http://host/callback.php",其中host为网站域名。
2、下载Demo,然后解压,修改config.php中的WB_AKEY为App Key,WB_SKEY为App Secret,WB_CALLBACK_URL为刚才填入的回调页地址。
3、上传到PHP空间即可
呵呵,我按着上述的方法设置了。当网站运行后,遇到这个问题:“
(error:redirect_uri_mismatch)”。
其实出现(error:redirect_uri_mismatch)错误的提示,其实是您没有对http://host/callback.php页面进行授权设置绑定。在申请“我的应用”时,那里填了很多信息。
在应用地址填了:http://yourhost ,刷新页面(error:redirect_uri_mismatch)错误提示依旧在。
误区一:错误的认为“应用地址”是授权设置
误区二:对新浪微博API设置不熟,不知道如何设置授权
正确授权方法:
步骤1:在open.weibo.com里面控制台的导航菜单,鼠标单击“应用信息”-“高级信息”
步骤2:鼠标点击 OAuth2.0授权设置右边的“编辑”按钮
步骤3:在授权回调页输入url地址,url必须是指向callback.php地址的绝对路径,如果输入出错,(error:redirect_uri_mismatch)错误提示不会消失,同时检查下config.php里的参数是否绑定授权地址。
刷新页面,(error:redirect_uri_mismatch)错误提示消失,新浪微博受权完成,可以开发自己想要的功能。
经验总结:认真看说明文档,少走弯路。
总要是在高级里设置的url跟代码的回调url要一样,少一个/都不行。
最新技术文章: